summaryrefslogtreecommitdiff
path: root/include/asterisk/utils.h
diff options
context:
space:
mode:
authorCorey Farrell <git@cfware.com>2016-08-19 15:09:45 -0400
committerCorey Farrell <git@cfware.com>2016-08-19 20:16:36 -0400
commit8061d9f66f636ada714f719be9809ea58cd5c871 (patch)
tree09bb8e63ebce00f7023ef54008a75af1caa50b61 /include/asterisk/utils.h
parentc6ed91a9c89de71b44045a53cfc73e1b12744cf8 (diff)
Fix naming mismatch of allocator functions.
Allocator functions that take file/line/func parameters are prefixed with single-underscore when MALLOC_DEBUG is not defined, double-underscore when it is defined. This change updates all allocators that accept file/line/func to have the same prototype in either ABI mode. The parameter order of __ast_vasprintf and __ast_asprintf in utils.h have been changed to match that of astmm.h. End-use allocator macro's have been removed from astmm.h and moved to an unconditional part of utils.h. Change-Id: I823bb6ce2b5675b3a4735948f10a3b420e9a023a
Diffstat (limited to 'include/asterisk/utils.h')
-rw-r--r--include/asterisk/utils.h200
1 files changed, 100 insertions, 100 deletions
diff --git a/include/asterisk/utils.h b/include/asterisk/utils.h
index c3df4779f..9789d34ee 100644
--- a/include/asterisk/utils.h
+++ b/include/asterisk/utils.h
@@ -533,19 +533,8 @@ long int ast_random(void);
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;
@@ -559,19 +548,8 @@ void * attribute_malloc _ast_malloc(size_t len, const char *file, int lineno, co
}
)
-/*!
- * \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;
@@ -585,6 +563,98 @@ void * attribute_malloc _ast_calloc(size_t num, size_t len, const char *file, in
}
)
+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
*
@@ -596,7 +666,7 @@ void * attribute_malloc _ast_calloc(size_t num, size_t len, const char *file, in
* 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()
@@ -607,22 +677,7 @@ void * attribute_malloc _ast_calloc(size_t num, size_t len, const char *file, in
* 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()
@@ -637,24 +692,7 @@ void * attribute_malloc _ast_realloc(void *p, size_t len, const char *file, int
* 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()
@@ -669,24 +707,7 @@ char * attribute_malloc _ast_strdup(const char *str, const char *file, int linen
* 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()
@@ -697,10 +718,7 @@ char * attribute_malloc _ast_strndup(const char *str, size_t len, const char *fi
* 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()
@@ -711,25 +729,7 @@ int __attribute__((format(printf, 5, 6)))
* 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