Browse code

Add --malloc-prefix to apply a prefix to malloc, free etc

This makes it easy to use a replacement allocator instead of the
system default one.

Originally committed as revision 21509 to svn://svn.ffmpeg.org/ffmpeg/trunk

Måns Rullgård authored on 2010/01/28 22:06:31
Showing 2 changed files
... ...
@@ -231,6 +231,7 @@ Advanced options (experts only):
231 231
   --disable-vis            disable VIS optimizations
232 232
   --disable-yasm           disable use of yasm assembler
233 233
   --enable-pic             build position-independent code
234
+  --malloc-prefix=PFX      prefix malloc and related names with PFX
234 235
 
235 236
 Developer options (useful when working on FFmpeg itself):
236 237
   --disable-debug          disable debugging symbols
... ...
@@ -1108,6 +1109,7 @@ CMDLINE_SET="
1108 1108
     host_os
1109 1109
     ld
1110 1110
     logfile
1111
+    malloc_prefix
1111 1112
     nm
1112 1113
     source_path
1113 1114
     sysinclude
... ...
@@ -2438,9 +2440,9 @@ check_func  gethrtime
2438 2438
 check_func  getrusage
2439 2439
 check_func  inet_aton $network_extralibs
2440 2440
 check_func  isatty
2441
-check_func  memalign
2441
+check_func  ${malloc_prefix}memalign            && enable memalign
2442 2442
 check_func  mkstemp
2443
-check_func  posix_memalign
2443
+check_func  ${malloc_prefix}posix_memalign      && enable posix_memalign
2444 2444
 check_func_headers io.h setmode
2445 2445
 check_func_headers lzo/lzo1x.h lzo1x_999_compress
2446 2446
 check_func_headers windows.h GetProcessTimes
... ...
@@ -2978,6 +2980,9 @@ cat > $TMPH <<EOF
2978 2978
 #define EXTERN_ASM ${extern_prefix}
2979 2979
 EOF
2980 2980
 
2981
+test -n "$malloc_prefix" &&
2982
+    echo "#define MALLOC_PREFIX $malloc_prefix" >>$TMPH
2983
+
2981 2984
 if enabled small || disabled optimizations; then
2982 2985
     echo "#define av_always_inline"  >> $TMPH
2983 2986
 fi
... ...
@@ -33,6 +33,7 @@
33 33
 #include <malloc.h>
34 34
 #endif
35 35
 
36
+#include "avutil.h"
36 37
 #include "mem.h"
37 38
 
38 39
 /* here we can use OS-dependent allocation functions */
... ...
@@ -40,6 +41,22 @@
40 40
 #undef malloc
41 41
 #undef realloc
42 42
 
43
+#ifdef MALLOC_PREFIX
44
+
45
+#define malloc         AV_JOIN(MALLOC_PREFIX, malloc)
46
+#define memalign       AV_JOIN(MALLOC_PREFIX, memalign)
47
+#define posix_memalign AV_JOIN(MALLOC_PREFIX, posix_memalign)
48
+#define realloc        AV_JOIN(MALLOC_PREFIX, realloc)
49
+#define free           AV_JOIN(MALLOC_PREFIX, free)
50
+
51
+void *malloc(size_t size);
52
+void *memalign(size_t align, size_t size);
53
+int   posix_memalign(void **ptr, size_t align, size_t size);
54
+void *realloc(void *ptr, size_t size);
55
+void  free(void *ptr);
56
+
57
+#endif /* MALLOC_PREFIX */
58
+
43 59
 /* You can redefine av_malloc and av_free in your project to use your
44 60
    memory allocator. You do not need to suppress this file because the
45 61
    linker will do it automatically. */