Explorar o código

Redefining memory management functions: Add #undef lines and a comment

Civetweb.c defines several memory management functions (mg_malloc, mg_calloc, mg_realloc, mg_free),
that should be used instead of the C-library function (malloc, calloc, realloc, free) in civetweb.c
and all *.inl files.
To ensure all programmers remember this, the original functions are redefined as "DO NOT USE".

This commit adds a corresponding comment and some #undef line to the existing redefinitions.
This is related to issue #23. Still it is intended to include civetweb.h (not civetweb.c), and it
is not recommended to redefine global symbols used in civetweb.c from outside civetweb.
bel %!s(int64=11) %!d(string=hai) anos
pai
achega
1d72ad0e85
Modificáronse 1 ficheiros con 14 adicións e 0 borrados
  1. 14 0
      src/civetweb.c

+ 14 - 0
src/civetweb.c

@@ -502,11 +502,25 @@ static __inline void * mg_realloc(void * a, size_t b)  {return realloc(a, b);}
 static __inline void   mg_free(void * a)               {free(a);}
 #endif
 
+/* This following lines are just meant as a reminder to use the mg-functions for memory management */
+#ifdef malloc
+    #undef malloc 
+#endif
+#ifdef calloc
+    #undef calloc 
+#endif
+#ifdef realloc
+    #undef realloc 
+#endif
+#ifdef free
+    #undef free 
+#endif
 #define malloc  DO_NOT_USE_THIS_FUNCTION__USE_mg_malloc
 #define calloc  DO_NOT_USE_THIS_FUNCTION__USE_mg_calloc
 #define realloc DO_NOT_USE_THIS_FUNCTION__USE_mg_realloc
 #define free    DO_NOT_USE_THIS_FUNCTION__USE_mg_free
 
+
 #define MD5_STATIC static
 #include "md5.inl"