#endif
-/* Provide our own definitions */
-
-#define ast_calloc(a,b) \
- __ast_calloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
-
-#define ast_calloc_cache(a,b) \
- __ast_calloc_cache(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
-
-#define ast_malloc(a) \
- __ast_malloc(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
+/* Provide our own definition for ast_free */
#define ast_free(a) \
__ast_free(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
-#define ast_realloc(a,b) \
- __ast_realloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
-
-#define ast_strdup(a) \
- __ast_strdup(a,__FILE__, __LINE__, __PRETTY_FUNCTION__)
-
-#define ast_strndup(a,b) \
- __ast_strndup(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__)
-
-#define ast_asprintf(a, b, c...) \
- __ast_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, b, c)
-
-#define ast_vasprintf(a,b,c) \
- __ast_vasprintf(a,b,c,__FILE__, __LINE__, __PRETTY_FUNCTION__)
-
#endif /* !STANDALONE */
#else
ast_log(LOG_ERROR, "Memory Allocation Failure in function %s at line %d of %s\n", func, lineno, file)
#endif
-/*!
- * \brief A wrapper for malloc()
- *
- * ast_malloc() is a wrapper for malloc() that will generate an Asterisk log
- * message in the case that the allocation fails.
- *
- * The argument and return value are the same as malloc()
- */
-#define ast_malloc(len) \
- _ast_malloc((len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
-
AST_INLINE_API(
-void * attribute_malloc _ast_malloc(size_t len, const char *file, int lineno, const char *func),
+void * attribute_malloc __ast_malloc(size_t len, const char *file, int lineno, const char *func),
{
void *p;
}
)
-/*!
- * \brief A wrapper for calloc()
- *
- * ast_calloc() is a wrapper for calloc() that will generate an Asterisk log
- * message in the case that the allocation fails.
- *
- * The arguments and return value are the same as calloc()
- */
-#define ast_calloc(num, len) \
- _ast_calloc((num), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
-
AST_INLINE_API(
-void * attribute_malloc _ast_calloc(size_t num, size_t len, const char *file, int lineno, const char *func),
+void * attribute_malloc __ast_calloc(size_t num, size_t len, const char *file, int lineno, const char *func),
{
void *p;
}
)
+AST_INLINE_API(
+void * attribute_malloc __ast_realloc(void *p, size_t len, const char *file, int lineno, const char *func),
+{
+ void *newp;
+
+ DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);
+
+ if (!(newp = realloc(p, len))) {
+ MALLOC_FAILURE_MSG;
+ }
+
+ return newp;
+}
+)
+
+AST_INLINE_API(
+char * attribute_malloc __ast_strdup(const char *str, const char *file, int lineno, const char *func),
+{
+ char *newstr = NULL;
+
+ DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);
+
+ if (str) {
+ if (!(newstr = strdup(str))) {
+ MALLOC_FAILURE_MSG;
+ }
+ }
+
+ return newstr;
+}
+)
+
+AST_INLINE_API(
+char * attribute_malloc __ast_strndup(const char *str, size_t len, const char *file, int lineno, const char *func),
+{
+ char *newstr = NULL;
+
+ DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);
+
+ if (str) {
+ if (!(newstr = strndup(str, len))) {
+ MALLOC_FAILURE_MSG;
+ }
+ }
+
+ return newstr;
+}
+)
+
+int __attribute__((format(printf, 5, 6)))
+ __ast_asprintf(const char *file, int lineno, const char *func, char **ret, const char *fmt, ...);
+
+AST_INLINE_API(
+__attribute__((format(printf, 2, 0)))
+int __ast_vasprintf(char **ret, const char *fmt, va_list ap, const char *file, int lineno, const char *func),
+{
+ int res;
+
+ DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, -1);
+
+ if ((res = vasprintf(ret, fmt, ap)) == -1) {
+ MALLOC_FAILURE_MSG;
+ }
+
+ return res;
+}
+)
+
+#endif /* AST_DEBUG_MALLOC */
+
+/*!
+ * \brief A wrapper for malloc()
+ *
+ * ast_malloc() is a wrapper for malloc() that will generate an Asterisk log
+ * message in the case that the allocation fails.
+ *
+ * The argument and return value are the same as malloc()
+ */
+#define ast_malloc(len) \
+ __ast_malloc((len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
+
+/*!
+ * \brief A wrapper for calloc()
+ *
+ * ast_calloc() is a wrapper for calloc() that will generate an Asterisk log
+ * message in the case that the allocation fails.
+ *
+ * The arguments and return value are the same as calloc()
+ */
+#define ast_calloc(num, len) \
+ __ast_calloc((num), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
+
/*!
* \brief A wrapper for calloc() for use in cache pools
*
* The arguments and return value are the same as calloc()
*/
#define ast_calloc_cache(num, len) \
- _ast_calloc((num), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
+ __ast_calloc((num), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
/*!
* \brief A wrapper for realloc()
* The arguments and return value are the same as realloc()
*/
#define ast_realloc(p, len) \
- _ast_realloc((p), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
-
-AST_INLINE_API(
-void * attribute_malloc _ast_realloc(void *p, size_t len, const char *file, int lineno, const char *func),
-{
- void *newp;
-
- DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);
-
- if (!(newp = realloc(p, len))) {
- MALLOC_FAILURE_MSG;
- }
-
- return newp;
-}
-)
+ __ast_realloc((p), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
/*!
* \brief A wrapper for strdup()
* The argument and return value are the same as strdup()
*/
#define ast_strdup(str) \
- _ast_strdup((str), __FILE__, __LINE__, __PRETTY_FUNCTION__)
-
-AST_INLINE_API(
-char * attribute_malloc _ast_strdup(const char *str, const char *file, int lineno, const char *func),
-{
- char *newstr = NULL;
-
- DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);
-
- if (str) {
- if (!(newstr = strdup(str))) {
- MALLOC_FAILURE_MSG;
- }
- }
-
- return newstr;
-}
-)
+ __ast_strdup((str), __FILE__, __LINE__, __PRETTY_FUNCTION__)
/*!
* \brief A wrapper for strndup()
* The arguments and return value are the same as strndup()
*/
#define ast_strndup(str, len) \
- _ast_strndup((str), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
-
-AST_INLINE_API(
-char * attribute_malloc _ast_strndup(const char *str, size_t len, const char *file, int lineno, const char *func),
-{
- char *newstr = NULL;
-
- DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL);
-
- if (str) {
- if (!(newstr = strndup(str, len))) {
- MALLOC_FAILURE_MSG;
- }
- }
-
- return newstr;
-}
-)
+ __ast_strndup((str), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
/*!
* \brief A wrapper for asprintf()
* The arguments and return value are the same as asprintf()
*/
#define ast_asprintf(ret, fmt, ...) \
- _ast_asprintf((ret), __FILE__, __LINE__, __PRETTY_FUNCTION__, fmt, __VA_ARGS__)
-
-int __attribute__((format(printf, 5, 6)))
- _ast_asprintf(char **ret, const char *file, int lineno, const char *func, const char *fmt, ...);
+ __ast_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, (ret), (fmt), __VA_ARGS__)
/*!
* \brief A wrapper for vasprintf()
* The arguments and return value are the same as vasprintf()
*/
#define ast_vasprintf(ret, fmt, ap) \
- _ast_vasprintf((ret), __FILE__, __LINE__, __PRETTY_FUNCTION__, (fmt), (ap))
-
-AST_INLINE_API(
-__attribute__((format(printf, 5, 0)))
-int _ast_vasprintf(char **ret, const char *file, int lineno, const char *func, const char *fmt, va_list ap),
-{
- int res;
-
- DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, -1);
-
- if ((res = vasprintf(ret, fmt, ap)) == -1) {
- MALLOC_FAILURE_MSG;
- }
-
- return res;
-}
-)
-
-#endif /* AST_DEBUG_MALLOC */
+ __ast_vasprintf((ret), (fmt), (ap), __FILE__, __LINE__, __PRETTY_FUNCTION__)
/*!
\brief call __builtin_alloca to ensure we get gcc builtin semantics
switch (options & AO2_ALLOC_OPT_LOCK_MASK) {
case AO2_ALLOC_OPT_LOCK_MUTEX:
-#if defined(__AST_DEBUG_MALLOC)
obj_mutex = __ast_calloc(1, sizeof(*obj_mutex) + data_size, file, line, func);
-#else
- obj_mutex = ast_calloc(1, sizeof(*obj_mutex) + data_size);
-#endif
if (obj_mutex == NULL) {
return NULL;
}
obj = (struct astobj2 *) &obj_mutex->priv_data;
break;
case AO2_ALLOC_OPT_LOCK_RWLOCK:
-#if defined(__AST_DEBUG_MALLOC)
obj_rwlock = __ast_calloc(1, sizeof(*obj_rwlock) + data_size, file, line, func);
-#else
- obj_rwlock = ast_calloc(1, sizeof(*obj_rwlock) + data_size);
-#endif
if (obj_rwlock == NULL) {
return NULL;
}
obj = (struct astobj2 *) &obj_rwlock->priv_data;
break;
case AO2_ALLOC_OPT_LOCK_NOLOCK:
-#if defined(__AST_DEBUG_MALLOC)
obj = __ast_calloc(1, sizeof(*obj) + data_size, file, line, func);
-#else
- obj = ast_calloc(1, sizeof(*obj) + data_size);
-#endif
if (obj == NULL) {
return NULL;
}
struct ast_cc_config_params *__ast_cc_config_params_init(const char *file, int line, const char *function)
{
-#if defined(__AST_DEBUG_MALLOC)
struct ast_cc_config_params *params = __ast_malloc(sizeof(*params), file, line, function);
-#else
- struct ast_cc_config_params *params = ast_malloc(sizeof(*params));
-#endif
if (!params) {
return NULL;
return NULL;
}
-#if defined(__AST_DEBUG_MALLOC)
if (!(datastore = __ast_calloc(1, sizeof(*datastore), file, line, function))) {
return NULL;
}
-#else
- if (!(datastore = ast_calloc(1, sizeof(*datastore)))) {
- return NULL;
- }
-#endif
datastore->info = info;
static void *calloc_wrapper(unsigned int num_structs, size_t struct_size,
const char *file, int lineno, const char *func)
{
-#if defined(__AST_DEBUG_MALLOC)
return __ast_calloc(num_structs, struct_size, file, lineno, func);
-#else
- return ast_calloc(num_structs, struct_size);
-#endif
}
/*! \brief add a new block to the pool.
}
#ifndef __AST_DEBUG_MALLOC
-int _ast_asprintf(char **ret, const char *file, int lineno, const char *func, const char *fmt, ...)
+int __ast_asprintf(const char *file, int lineno, const char *func, char **ret, const char *fmt, ...)
{
int res;
va_list ap;
#define MALLOC_FAILURE_MSG \
ast_log(LOG_ERROR, "Memory Allocation Failure in function %s at line %d of %s\n", func, lineno, file);
-void * attribute_malloc _ast_calloc(size_t num, size_t len, const char *file, int lineno, const char *func);
+void * attribute_malloc __ast_calloc(size_t num, size_t len, const char *file, int lineno, const char *func);
-void * attribute_malloc _ast_calloc(size_t num, size_t len, const char *file, int lineno, const char *func)
+void * attribute_malloc __ast_calloc(size_t num, size_t len, const char *file, int lineno, const char *func)
{
void *p;
#define ast_free free
#define ast_free_ptr free
-#define MALLOC_FAILURE_MSG \
- ast_log(LOG_ERROR, "Memory Allocation Failure in function %s at line %d of %s\n", func, lineno, file);
-
-/*!
- * \brief A wrapper for malloc()
- *
- * ast_malloc() is a wrapper for malloc() that will generate an Asterisk log
- * message in the case that the allocation fails.
- *
- * The argument and return value are the same as malloc()
- */
-#define ast_malloc(len) \
- _ast_malloc((len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
-
-#define ast_calloc(num, len) \
- _ast_calloc((num), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
-
-#define ast_calloc_cache(num, len) \
- _ast_calloc((num), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
-
-#define ast_realloc(p, len) \
- _ast_realloc((p), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
-
-#define ast_strdup(str) \
- _ast_strdup((str), __FILE__, __LINE__, __PRETTY_FUNCTION__)
-
-#define ast_strndup(str, len) \
- _ast_strndup((str), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
-
-#define ast_asprintf(ret, fmt, ...) \
- _ast_asprintf((ret), __FILE__, __LINE__, __PRETTY_FUNCTION__, fmt, __VA_ARGS__)
-
-#define ast_vasprintf(ret, fmt, ap) \
- _ast_vasprintf((ret), __FILE__, __LINE__, __PRETTY_FUNCTION__, (fmt), (ap))
-
struct ast_flags { /* stolen from utils.h */
unsigned int flags;
};
#define MALLOC_FAILURE_MSG \
ast_log(LOG_ERROR, "Memory Allocation Failure in function %s at line %d of %s\n", func, lineno, file);
+
/*!
* \brief A wrapper for malloc()
*
* The argument and return value are the same as malloc()
*/
#define ast_malloc(len) \
- _ast_malloc((len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
+ __ast_malloc((len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
AST_INLINE_API(
-void * attribute_malloc _ast_malloc(size_t len, const char *file, int lineno, const char *func),
+void * attribute_malloc __ast_malloc(size_t len, const char *file, int lineno, const char *func),
{
void *p;
* The arguments and return value are the same as calloc()
*/
#define ast_calloc(num, len) \
- _ast_calloc((num), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
+ __ast_calloc((num), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
AST_INLINE_API(
-void * attribute_malloc _ast_calloc(size_t num, size_t len, const char *file, int lineno, const char *func),
+void * attribute_malloc __ast_calloc(size_t num, size_t len, const char *file, int lineno, const char *func),
{
void *p;
* The arguments and return value are the same as calloc()
*/
#define ast_calloc_cache(num, len) \
- _ast_calloc((num), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
+ __ast_calloc((num), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
/*!
* \brief A wrapper for realloc()
* The arguments and return value are the same as realloc()
*/
#define ast_realloc(p, len) \
- _ast_realloc((p), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
+ __ast_realloc((p), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
AST_INLINE_API(
-void * attribute_malloc _ast_realloc(void *p, size_t len, const char *file, int lineno, const char *func),
+void * attribute_malloc __ast_realloc(void *p, size_t len, const char *file, int lineno, const char *func),
{
void *newp;
* The argument and return value are the same as strdup()
*/
#define ast_strdup(str) \
- _ast_strdup((str), __FILE__, __LINE__, __PRETTY_FUNCTION__)
+ __ast_strdup((str), __FILE__, __LINE__, __PRETTY_FUNCTION__)
AST_INLINE_API(
-char * attribute_malloc _ast_strdup(const char *str, const char *file, int lineno, const char *func),
+char * attribute_malloc __ast_strdup(const char *str, const char *file, int lineno, const char *func),
{
char *newstr = NULL;
* The arguments and return value are the same as strndup()
*/
#define ast_strndup(str, len) \
- _ast_strndup((str), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
+ __ast_strndup((str), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
AST_INLINE_API(
-char * attribute_malloc _ast_strndup(const char *str, size_t len, const char *file, int lineno, const char *func),
+char * attribute_malloc __ast_strndup(const char *str, size_t len, const char *file, int lineno, const char *func),
{
char *newstr = NULL;
* The arguments and return value are the same as asprintf()
*/
#define ast_asprintf(ret, fmt, ...) \
- _ast_asprintf((ret), __FILE__, __LINE__, __PRETTY_FUNCTION__, fmt, __VA_ARGS__)
+ __ast_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, (ret), (fmt), __VA_ARGS__)
AST_INLINE_API(
__attribute__((format(printf, 5, 6)))
-int _ast_asprintf(char **ret, const char *file, int lineno, const char *func, const char *fmt, ...),
+int __ast_asprintf(const char *file, int lineno, const char *func, char **ret, const char *fmt, ...),
{
int res;
va_list ap;
* The arguments and return value are the same as vasprintf()
*/
#define ast_vasprintf(ret, fmt, ap) \
- _ast_vasprintf((ret), __FILE__, __LINE__, __PRETTY_FUNCTION__, (fmt), (ap))
+ __ast_vasprintf((ret), (fmt), (ap), __FILE__, __LINE__, __PRETTY_FUNCTION__)
AST_INLINE_API(
-__attribute__((format(printf, 5, 0)))
-int _ast_vasprintf(char **ret, const char *file, int lineno, const char *func, const char *fmt, va_list ap),
+__attribute__((format(printf, 2, 0)))
+int __ast_vasprintf(char **ret, const char *fmt, va_list ap, const char *file, int lineno, const char *func),
{
int res;