diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2010-05-11 12:20:11 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2010-05-11 12:20:11 +0200 |
commit | 2e501c68a8641a2b3c430b55f13491a9c1c5d0f5 (patch) | |
tree | 49c2748443fe3c1f01108756b647440e0647a11b /libxsde/xsde/c/genx/genx.c | |
parent | 161beba6cdb0d91b15ad19fa8b3e51d986203915 (diff) |
Add support for custom allocators
New example: examples/cxx/hybrid/allocator.
Diffstat (limited to 'libxsde/xsde/c/genx/genx.c')
-rw-r--r-- | libxsde/xsde/c/genx/genx.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/libxsde/xsde/c/genx/genx.c b/libxsde/xsde/c/genx/genx.c index 0c0ed17..6596f81 100644 --- a/libxsde/xsde/c/genx/genx.c +++ b/libxsde/xsde/c/genx/genx.c @@ -10,8 +10,14 @@ #include <stdlib.h> #include <string.h> +#include <xsde/config.h> + #include "genx.h" +#ifdef XSDE_CUSTOM_ALLOCATOR +# include <xsde/allocator.h> +#endif + #define Boolean int #define True 1 #define False 0 @@ -156,7 +162,11 @@ static void * allocate(genxWriter w, int bytes) if (w->alloc) return (void *) (*w->alloc)(w->userData, bytes); else +#ifdef XSDE_CUSTOM_ALLOCATOR + return (void *) xsde_alloc(bytes); +#else return (void *) malloc(bytes); +#endif } static void deallocate(genxWriter w, void * data) @@ -164,7 +174,11 @@ static void deallocate(genxWriter w, void * data) if (w->dealloc) (*w->dealloc)(w->userData, data); else if (w->alloc == NULL) +#ifdef XSDE_CUSTOM_ALLOCATOR + xsde_free(data); +#else free(data); +#endif } static utf8 copy(genxWriter w, constUtf8 from) @@ -527,7 +541,11 @@ genxWriter genxNew(void * (* alloc)(void * userData, int bytes), if (alloc) w = (genxWriter) (*alloc)(userData, sizeof(struct genxWriter_rec)); else +#ifdef XSDE_CUSTOM_ALLOCATOR + w = (genxWriter) xsde_alloc(sizeof(struct genxWriter_rec)); +#else w = (genxWriter) malloc(sizeof(struct genxWriter_rec)); +#endif if (w == NULL) return NULL; |