mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-19 03:07:59 +00:00
core: Remove ABI effects of MALLOC_DEBUG.
This allows asterisk to be compiled with MALLOC_DEBUG to load modules built without MALLOC_DEBUG. Now pre-compiled third-party modules will still work regardless of MALLOC_DEBUG being enabled or not. Change-Id: Ic07ad80b2c2df894db984cf27b16a69383ce0e10
This commit is contained in:
@@ -617,8 +617,8 @@ int ast_regex_string_to_regex_pattern(const char *regex_string, struct ast_str *
|
||||
* \note The result of this function is dynamically allocated memory, and must
|
||||
* be free()'d after it is no longer needed.
|
||||
*/
|
||||
#ifdef __AST_DEBUG_MALLOC
|
||||
#define ast_str_create(a) _ast_str_create(a,__FILE__,__LINE__,__PRETTY_FUNCTION__)
|
||||
#define ast_str_create(init_len) \
|
||||
_ast_str_create(init_len, __FILE__, __LINE__, __PRETTY_FUNCTION__)
|
||||
AST_INLINE_API(
|
||||
struct ast_str * attribute_malloc _ast_str_create(size_t init_len,
|
||||
const char *file, int lineno, const char *func),
|
||||
@@ -636,24 +636,6 @@ struct ast_str * attribute_malloc _ast_str_create(size_t init_len,
|
||||
return buf;
|
||||
}
|
||||
)
|
||||
#else
|
||||
AST_INLINE_API(
|
||||
struct ast_str * attribute_malloc ast_str_create(size_t init_len),
|
||||
{
|
||||
struct ast_str *buf;
|
||||
|
||||
buf = (struct ast_str *)ast_calloc(1, sizeof(*buf) + init_len);
|
||||
if (buf == NULL)
|
||||
return NULL;
|
||||
|
||||
buf->__AST_STR_LEN = init_len;
|
||||
buf->__AST_STR_USED = 0;
|
||||
buf->__AST_STR_TS = DS_MALLOC;
|
||||
|
||||
return buf;
|
||||
}
|
||||
)
|
||||
#endif
|
||||
|
||||
/*! \brief Reset the content of a dynamic string.
|
||||
* Useful before a series of ast_str_append.
|
||||
@@ -772,7 +754,6 @@ char *ast_str_truncate(struct ast_str *buf, ssize_t len),
|
||||
/*!
|
||||
* Make space in a new string (e.g. to read in data from a file)
|
||||
*/
|
||||
#ifdef __AST_DEBUG_MALLOC
|
||||
AST_INLINE_API(
|
||||
int _ast_str_make_space(struct ast_str **buf, size_t new_len, const char *file, int lineno, const char *function),
|
||||
{
|
||||
@@ -796,32 +777,8 @@ int _ast_str_make_space(struct ast_str **buf, size_t new_len, const char *file,
|
||||
return 0;
|
||||
}
|
||||
)
|
||||
#define ast_str_make_space(a,b) _ast_str_make_space(a,b,__FILE__,__LINE__,__PRETTY_FUNCTION__)
|
||||
#else
|
||||
AST_INLINE_API(
|
||||
int ast_str_make_space(struct ast_str **buf, size_t new_len),
|
||||
{
|
||||
struct ast_str *old_buf = *buf;
|
||||
|
||||
if (new_len <= (*buf)->__AST_STR_LEN)
|
||||
return 0; /* success */
|
||||
if ((*buf)->__AST_STR_TS == DS_ALLOCA || (*buf)->__AST_STR_TS == DS_STATIC)
|
||||
return -1; /* cannot extend */
|
||||
*buf = (struct ast_str *)ast_realloc(*buf, new_len + sizeof(struct ast_str));
|
||||
if (*buf == NULL) {
|
||||
*buf = old_buf;
|
||||
return -1;
|
||||
}
|
||||
if ((*buf)->__AST_STR_TS != DS_MALLOC) {
|
||||
pthread_setspecific((*buf)->__AST_STR_TS->key, *buf);
|
||||
_DB1(__ast_threadstorage_object_replace(old_buf, *buf, new_len + sizeof(struct ast_str));)
|
||||
}
|
||||
|
||||
(*buf)->__AST_STR_LEN = new_len;
|
||||
return 0;
|
||||
}
|
||||
)
|
||||
#endif
|
||||
#define ast_str_make_space(buf, new_len) \
|
||||
_ast_str_make_space(buf, new_len, __FILE__, __LINE__, __PRETTY_FUNCTION__)
|
||||
|
||||
AST_INLINE_API(
|
||||
int ast_str_copy_string(struct ast_str **dst, struct ast_str *src),
|
||||
@@ -965,14 +922,12 @@ enum {
|
||||
* through calling one of the other functions or macros defined in this
|
||||
* file.
|
||||
*/
|
||||
#ifdef __AST_DEBUG_MALLOC
|
||||
int __attribute__((format(printf, 4, 0))) __ast_debug_str_helper(struct ast_str **buf, ssize_t max_len,
|
||||
int append, const char *fmt, va_list ap, const char *file, int lineno, const char *func);
|
||||
#define __ast_str_helper(a,b,c,d,e) __ast_debug_str_helper(a,b,c,d,e,__FILE__,__LINE__,__PRETTY_FUNCTION__)
|
||||
#else
|
||||
int __attribute__((format(printf, 4, 0))) __ast_str_helper(struct ast_str **buf, ssize_t max_len,
|
||||
int append, const char *fmt, va_list ap);
|
||||
#endif
|
||||
int __attribute__((format(printf, 4, 0))) __ast_str_helper(struct ast_str **buf,
|
||||
ssize_t max_len, int append, const char *fmt, va_list ap,
|
||||
const char *file, int lineno, const char *func);
|
||||
#define _ast_str_helper(buf, max_len, append, fmt, ap) \
|
||||
__ast_str_helper(buf, max_len, append, fmt, ap, __FILE__, __LINE__, __PRETTY_FUNCTION__)
|
||||
|
||||
char *__ast_str_helper2(struct ast_str **buf, ssize_t max_len,
|
||||
const char *src, size_t maxsrc, int append, int escapecommas);
|
||||
|
||||
@@ -1022,7 +977,7 @@ char *__ast_str_helper2(struct ast_str **buf, ssize_t max_len,
|
||||
*/
|
||||
AST_INLINE_API(int __attribute__((format(printf, 3, 0))) ast_str_set_va(struct ast_str **buf, ssize_t max_len, const char *fmt, va_list ap),
|
||||
{
|
||||
return __ast_str_helper(buf, max_len, 0, fmt, ap);
|
||||
return _ast_str_helper(buf, max_len, 0, fmt, ap);
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1040,7 +995,7 @@ AST_INLINE_API(int __attribute__((format(printf, 3, 0))) ast_str_set_va(struct a
|
||||
*/
|
||||
AST_INLINE_API(int __attribute__((format(printf, 3, 0))) ast_str_append_va(struct ast_str **buf, ssize_t max_len, const char *fmt, va_list ap),
|
||||
{
|
||||
return __ast_str_helper(buf, max_len, 1, fmt, ap);
|
||||
return _ast_str_helper(buf, max_len, 1, fmt, ap);
|
||||
}
|
||||
)
|
||||
|
||||
|
Reference in New Issue
Block a user