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 | |
parent | 161beba6cdb0d91b15ad19fa8b3e51d986203915 (diff) |
Add support for custom allocators
New example: examples/cxx/hybrid/allocator.
Diffstat (limited to 'libxsde/xsde/c')
-rw-r--r-- | libxsde/xsde/c/expat/xmlparse.c | 15 | ||||
-rw-r--r-- | libxsde/xsde/c/genx/genx.c | 18 |
2 files changed, 33 insertions, 0 deletions
diff --git a/libxsde/xsde/c/expat/xmlparse.c b/libxsde/xsde/c/expat/xmlparse.c index 6eac810..19fa39a 100644 --- a/libxsde/xsde/c/expat/xmlparse.c +++ b/libxsde/xsde/c/expat/xmlparse.c @@ -12,6 +12,10 @@ #include "expat.h" +#ifdef XSDE_CUSTOM_ALLOCATOR +# include <xsde/allocator.h> +#endif + #ifdef XML_UNICODE #define XML_ENCODE_MAX XML_UTF16_ENCODE_MAX #define XmlConvert XmlUtf16Convert @@ -702,6 +706,16 @@ parserCreate(const XML_Char *encodingName, } else { XML_Memory_Handling_Suite *mtemp; + +#ifdef XSDE_CUSTOM_ALLOCATOR + parser = (XML_Parser)xsde_alloc(sizeof(struct XML_ParserStruct)); + if (parser != NULL) { + mtemp = (XML_Memory_Handling_Suite *)&(parser->m_mem); + mtemp->malloc_fcn = xsde_alloc; + mtemp->realloc_fcn = xsde_realloc; + mtemp->free_fcn = xsde_free; + } +#else parser = (XML_Parser)malloc(sizeof(struct XML_ParserStruct)); if (parser != NULL) { mtemp = (XML_Memory_Handling_Suite *)&(parser->m_mem); @@ -709,6 +723,7 @@ parserCreate(const XML_Char *encodingName, mtemp->realloc_fcn = realloc; mtemp->free_fcn = free; } +#endif } if (!parser) 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; |