--- parser3/src/main/pa_globals.C 2003/03/31 08:35:45 1.152.2.19.2.9 +++ parser3/src/main/pa_globals.C 2003/04/02 10:59:19 1.152.2.19.2.14 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_GLOBALS_C="$Date: 2003/03/31 08:35:45 $"; +static const char* IDENT_GLOBALS_C="$Date: 2003/04/02 10:59:19 $"; #include "pa_config_includes.h" @@ -78,7 +78,7 @@ public: thread_id=0; buf[used=0]=0; } - const char* get_and_reset() { + const char* getnd_reset() { char* result=new(PointerFreeGC) char[used+1]; memcpy(result, buf, used+1); reset(); @@ -139,7 +139,7 @@ const char* xmlGenericErrors() { if(!p) // no errors for our thread_id registered return 0; - return p->get_and_reset(); + return p->getnd_reset(); } /** @@ -237,100 +237,44 @@ static char *pa_GC_strdup(const char *s) memcpy(result, s, size); return result; } +#endif -#ifdef PA_DEBUG_XML_GC_MEMORY - -static char * -pa_xmlStrndup(const char *cur, int len) { - char*ret; - - if ((cur == NULL) || (len < 0)) return(NULL); - ret = (char *) xmlMalloc((len + 1) * sizeof(char)); - if (ret == NULL) { - xmlGenericError(xmlGenericErrorContext, - "malloc of %ld byte failed\n", - (len + 1) * (long)sizeof(char)); - return(NULL); - } - memcpy(ret, cur, len * sizeof(char)); - ret[len] = 0; - return(ret); -} - -static char * -pa_debug_xmlStrdup(const char *cur) { - const char *p = cur; - - if (cur == NULL) return(NULL); - while (*p != 0) p++; /* non input consuming */ - return(pa_xmlStrndup(cur, p - cur)); -} - -static Hash valid_ptrs; -static void* add_valid_ptr(void* ptr) { - valid_ptrs.put((int)ptr, true); - return ptr; -} -static void* check_ptr(void* ptr) { - if(!valid_ptrs.get((int)ptr)) - _asm int 3; - return ptr; -} - -static int pa_debug_xml=1; -static void* pa_debug_GC_malloc(size_t size) { - if(pa_debug_xml) - return add_valid_ptr(GC_malloc(size)); - else - return GC_malloc(size); -} - -static void *pa_debug_GC_realloc(void *ptr, size_t size) { - //printf("realloc: 0x%p -> %u\n", ptr, size); - if(pa_debug_xml) - return add_valid_ptr(GC_realloc(check_ptr(ptr), size)); - else - return GC_realloc(ptr, size); -} - -static void pa_debug_GC_free(void*) { - // ignore free +void pa_CORD_oom_fn(void) { + SAPI::abort("out of memory (while expanding string)"); } +/** + @todo gc: pcre: substitute pcre_malloc &co + @todo gc: libltdl: substitute lt_dlmalloc & co + @todo gc: figure out how to substitute glib memory allocator +*/ +static void gc_substitute_memory_management_functions() { + // in libxml & libxslt +#ifdef XML + // asking to use GC memory + xmlMemSetup( + /*xmlFreeFunc */pa_gc_free, + /*xmlMallocFunc */pa_gc_malloc, + /*xmlReallocFunc */pa_gc_realloc, + /*xmlStrdupFunc */pa_GC_strdup); #endif + CORD_oom_fn=pa_CORD_oom_fn; +} -#endif - -/// @test hint on one should call this for each thread xmlSubstituteEntitiesDefault(1); +/** + @test hint on one should call this for each thread xmlSubstituteEntitiesDefault(1); +*/ void pa_globals_init() { + // in various libraries + gc_substitute_memory_management_functions(); // hex value setup_hex_value(); #ifdef XML - // initializing xml libs -#ifndef PA_DEBUG_DISABLE_GC - - // asking to use GC memory -#ifndef PA_DEBUG_XML_GC_MEMORY - xmlMemSetup( - /*xmlFreeFunc */GC_free, - /*xmlMallocFunc */GC_malloc, - /*xmlReallocFunc */GC_realloc, - /*xmlStrdupFunc */pa_GC_strdup); -#else - xmlMemSetup( - /*xmlFreeFunc */pa_debug_GC_free, - /*xmlMallocFunc */pa_debug_GC_malloc, - /*xmlReallocFunc */pa_debug_GC_realloc, - /*xmlStrdupFunc */pa_debug_xmlStrdup); -#endif - -#endif - /* First get a DOMImplementation reference */ domimpl = gdome_di_mkref (); /* @@ -384,18 +328,72 @@ void pa_globals_init() { #endif } -#if defined(XML) && defined(_MSC_VER) +#ifdef _MSC_VER + +#ifndef PA_DEBUG_DISABLE_GC +# define GC_LIB "/parser3project/win32/gc" +# ifdef _DEBUG +# pragma comment(lib, GC_LIB "/Debug/gc.lib") +# else +# pragma comment(lib, GC_LIB "/Release/gc.lib") +# endif + +#endif + +#ifdef XML # define GNOME_LIBS "/parser3project/win32xml/win32/gnome" # pragma comment(lib, GNOME_LIBS "/glib/lib/libglib-1.3-11.lib") # ifdef _DEBUG -# pragma comment(lib, GNOME_LIBS "/libxml2-x.x.x/win32/dsp/libxml2_so_debug/libxml2.lib") -# pragma comment(lib, GNOME_LIBS "/libxslt-x.x.x/win32/dsp/libexslt_so_debug/libexslt.lib") -# pragma comment(lib, GNOME_LIBS "/libxslt-x.x.x/win32/dsp/libxslt_so_debug/libxslt.lib") -# pragma comment(lib, GNOME_LIBS "/gdome2-x.x.x/win32/dsp/Debug/libgdome.lib") -# else -# pragma comment(lib, GNOME_LIBS "/libxml2-x.x.x/win32/dsp/libxml2_so_release/libxml2.lib") -# pragma comment(lib, GNOME_LIBS "/libxslt-x.x.x/win32/dsp/libexslt_so_release/libexslt.lib") -# pragma comment(lib, GNOME_LIBS "/libxslt-x.x.x/win32/dsp/libxslt_so_release/libxslt.lib") -# pragma comment(lib, GNOME_LIBS "/gdome2-x.x.x/win32/dsp/Release/libgdome.lib") + +# ifdef LIBXML_STATIC +# pragma comment(lib, GNOME_LIBS "/gnome-xml/win32/dsp/libxml2_DebugStatic/libxml2.lib") +# else +# pragma comment(lib, GNOME_LIBS "/gnome-xml/win32/dsp/libxml2_DebugDynamic/libxml2.lib") +# endif + +# ifdef LIBXSLT_STATIC +# pragma comment(lib, GNOME_LIBS "/libxslt-x.x.x/win32/dsp/libxslt_DebugStatic/libxslt.lib") +# else +# pragma comment(lib, GNOME_LIBS "/libxslt-x.x.x/win32/dsp/libxslt_DebugDynamic/libxslt.lib") +# endif +# ifdef LIBEXSLT_STATIC +# pragma comment(lib, GNOME_LIBS "/libxslt-x.x.x/win32/dsp/libexslt_DebugStatic/libexslt.lib") +# else +# pragma comment(lib, GNOME_LIBS "/libxslt-x.x.x/win32/dsp/libexslt_DebugDynamic/libexslt.lib") +# endif + +# ifdef LIBGDOME_STATIC +# pragma comment(lib, GNOME_LIBS "/gdome2-x.x.x/win32/dsp/libgdome_DebugStatic/libgdome.lib") +# else +# pragma comment(lib, GNOME_LIBS "/gdome2-x.x.x/win32/dsp/libgdome_DebugDynamic/libgdome.lib") +# endif + +#else + +# ifdef LIBXML_STATIC +# pragma comment(lib, GNOME_LIBS "/gnome-xml/win32/dsp/libxml2_ReleaseStatic/libxml2.lib") +# else +# pragma comment(lib, GNOME_LIBS "/gnome-xml/win32/dsp/lixml2_ReleaseDynamic/libxml2.lib") +# endif + +# ifdef LIBXSLT_STATIC +# pragma comment(lib, GNOME_LIBS "/libxslt-x.x.x/win32/dsp/libxslt_ReleaseStatic/libxslt.lib") +# else +# pragma comment(lib, GNOME_LIBS "/libxslt-x.x.x/win32/dsp/libxslt_ReleaseDynamic/libxslt.lib") +# endif +# ifdef LIBEXSLT_STATIC +# pragma comment(lib, GNOME_LIBS "/libxslt-x.x.x/win32/dsp/libexslt_ReleaseStatic/libexslt.lib") +# else +# pragma comment(lib, GNOME_LIBS "/libxslt-x.x.x/win32/dsp/libexslt_ReleaseDynamic/libexslt.lib") +# endif + +# ifdef LIBGDOME_STATIC +# pragma comment(lib, GNOME_LIBS "/gdome2-x.x.x/win32/dsp/libgdome_ReleaseStatic/libgdome.lib") +# else +# pragma comment(lib, GNOME_LIBS "/gdome2-x.x.x/win32/dsp/libgdome_ReleaseDynamic/libgdome.lib") +# endif + # endif #endif + +#endif