[Asterisk-code-review] Add support for NOWRAP LIBC MALLOC to astmm.h. (asterisk[master])

Corey Farrell asteriskteam at digium.com
Tue May 12 09:26:33 CDT 2015


Corey Farrell has uploaded a new change for review.

  https://gerrit.asterisk.org/442

Change subject: Add support for NOWRAP_LIBC_MALLOC to astmm.h.
......................................................................

Add support for NOWRAP_LIBC_MALLOC to astmm.h.

There are situations where replacing standard allocator and
other functions is a problem for library headers.  If they
provide static inline functions in the headers, those functions
can trip the checks for use of standard functions.  This adds
the ability to define NOWRAP_LIBC_MALLOC before including
asterisk.h.  This will prevent any redefinition of the standard
functions, fixing build errors that can happen with MALLOC_DEBUG.

Change-Id: I8afef4bc7f3b93914263ae27d3a5858b69663fc7
---
M include/asterisk/astmm.h
M res/res_fax_spandsp.c
M res/snmp/agent.c
3 files changed, 20 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/42/442/1

diff --git a/include/asterisk/astmm.h b/include/asterisk/astmm.h
index 1d778d4..2b82f4e 100644
--- a/include/asterisk/astmm.h
+++ b/include/asterisk/astmm.h
@@ -44,16 +44,6 @@
 #include <stdio.h>
 #include <stdarg.h>
 
-/* Undefine any macros */
-#undef malloc
-#undef calloc
-#undef realloc
-#undef strdup
-#undef strndup
-#undef asprintf
-#undef vasprintf
-#undef free
-
 void *ast_std_malloc(size_t size);
 void *ast_std_calloc(size_t nmemb, size_t size);
 void *ast_std_realloc(void *ptr, size_t size);
@@ -75,6 +65,17 @@
 void __ast_mm_init_phase_2(void);
 
 /* Redefine libc malloc to our own versions */
+
+#ifndef NOWRAP_LIBC_MALLOC
+/* Undefine any macros */
+#undef malloc
+#undef calloc
+#undef realloc
+#undef strdup
+#undef strndup
+#undef asprintf
+#undef vasprintf
+#undef free
 
 #ifdef WRAP_LIBC_MALLOC
 #define calloc(a,b) \
@@ -112,6 +113,7 @@
 	Do_not_use_vasprintf__use_ast_vasprintf->fail(a,b,c)
 #endif
 
+#endif
 /* Provide our own definitions */
 
 #define ast_calloc(a,b) \
diff --git a/res/res_fax_spandsp.c b/res/res_fax_spandsp.c
index 4249227..b1de0b8 100644
--- a/res/res_fax_spandsp.c
+++ b/res/res_fax_spandsp.c
@@ -48,12 +48,8 @@
 	<support_level>extended</support_level>
 ***/
 
-/* Include spandsp headers before asterisk.h so the inline functions can continue using
- * malloc and free, even with MALLOC_DEBUG enabled. */
-#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
-#include <spandsp.h>
-#include <spandsp/version.h>
-
+/* Needed for spandsp headers */
+#define NOWRAP_LIBC_MALLOC
 #include "asterisk.h"
 
 ASTERISK_REGISTER_FILE()
@@ -69,6 +65,10 @@
 #include "asterisk/channel.h"
 #include "asterisk/format_cache.h"
 
+#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
+#include <spandsp.h>
+#include <spandsp/version.h>
+
 #define SPANDSP_FAX_SAMPLES 160
 #define SPANDSP_FAX_TIMER_RATE 8000 / SPANDSP_FAX_SAMPLES	/* 50 ticks per second, 20ms, 160 samples per second */
 #define SPANDSP_ENGAGE_UDPTL_NAT_RETRY 3
diff --git a/res/snmp/agent.c b/res/snmp/agent.c
index bebcee1..fa7ad6c 100644
--- a/res/snmp/agent.c
+++ b/res/snmp/agent.c
@@ -18,6 +18,8 @@
 	<support_level>extended</support_level>
  ***/
 
+/* Needed for net-snmp headers */
+#define NOWRAP_LIBC_MALLOC
 #include "asterisk.h"
 
 ASTERISK_REGISTER_FILE()

-- 
To view, visit https://gerrit.asterisk.org/442
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8afef4bc7f3b93914263ae27d3a5858b69663fc7
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Corey Farrell <git at cfware.com>



More information about the asterisk-code-review mailing list