--- parser3/src/main/pa_globals.C 2003/03/07 14:56:59 1.152.2.19 +++ parser3/src/main/pa_globals.C 2003/04/21 11:08:19 1.152.2.19.2.16 @@ -5,11 +5,12 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_GLOBALS_C="$Date: 2003/03/07 14:56:59 $"; +static const char* IDENT_GLOBALS_C="$Date: 2003/04/21 11:08:19 $"; #include "pa_config_includes.h" #ifdef XML +#include "libxml/xmlversion.h" #include "libxslt/extensions.h" #include "libxslt/xsltutils.h" extern "C" { @@ -22,6 +23,13 @@ extern "C" { #include "pa_sapi.h" #include "pa_threads.h" + +// defines + +#define PA_DEBUG_XML_GC_MEMORY + +// globals + short hex_value[0x100]; #ifdef XML @@ -71,9 +79,9 @@ public: thread_id=0; buf[used=0]=0; } - CharPtr get_and_reset() { - CharPtr result(new char[used+1]); - memcpy(result.get(), buf, used+1); + const char* getnd_reset() { + char* result=new(PointerFreeGC) char[used+1]; + memcpy(result, buf, used+1); reset(); return result; } @@ -123,16 +131,16 @@ bool xmlHaveGenericErrors() { return xml_generic_error_info(thread_id)!=0; } -CharPtr xmlGenericErrors() { +const char* xmlGenericErrors() { pa_thread_t thread_id=pa_get_thread_id(); SYNCHRONIZED; // find+free blocked XML_Generic_error_info *p=xml_generic_error_info(thread_id); if(!p) // no errors for our thread_id registered - return CharPtr(0); + return 0; - return p->get_and_reset(); + return p->getnd_reset(); } /** @@ -220,8 +228,57 @@ void pa_globals_destroy(void *) { } -/// @test hint on one should call this for each thread xmlSubstituteEntitiesDefault(1); +#ifdef XML +static char *pa_GC_strdup(const char *s) { + if(!s) + return 0; + + size_t size=strlen(s)+1; + char *result=(char *)GC_malloc_atomic(size); + memcpy(result, s, size); + return result; +} +#endif + +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 +#if LIBXML_VERSION >= 20506 + xmlGcMemSetup( + /*xmlFreeFunc */pa_gc_free, + /*xmlMallocFunc */pa_gc_malloc, + /*xmlMallocFunc */pa_gc_malloc_atomic, + /*xmlReallocFunc */pa_gc_realloc, + /*xmlStrdupFunc */pa_GC_strdup); +#else + xmlMemSetup( + /*xmlFreeFunc */pa_gc_free, + /*xmlMallocFunc */pa_gc_malloc, + /*xmlReallocFunc */pa_gc_realloc, + /*xmlStrdupFunc */pa_GC_strdup); +#endif + +#endif + + CORD_oom_fn=pa_CORD_oom_fn; +} + +/** + @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(); @@ -229,19 +286,19 @@ void pa_globals_init() { #ifdef XML // initializing xml libs - /* First I get a DOMImplementation reference */ + /* First get a DOMImplementation reference */ domimpl = gdome_di_mkref (); - /* - * Register the EXSLT extensions and the test module - */ - exsltRegisterAll(); - xsltRegisterTestModule(); - xmlDefaultSAXHandlerInit(); - /* - * disable CDATA from being built in the document tree - */ - // never added yet xmlDefaultSAXHandler.cdataBlock = NULL; - + /* + * Register the EXSLT extensions and the test module + */ + exsltRegisterAll(); + xsltRegisterTestModule(); + xmlDefaultSAXHandlerInit(); + /* + * disable CDATA from being built in the document tree + */ + // never added yet xmlDefaultSAXHandler.cdataBlock = NULL; + /* * Initialization function for the XML parser. * This is not reentrant. Call once before processing in case of @@ -262,7 +319,7 @@ void pa_globals_init() { xmlLoadExtDtdDefaultValue |= XML_DETECT_IDS; // Bit in the loadsubset context field to tell to do complete the elements attributes lists // with the ones defaulted from the DTDs - xmlLoadExtDtdDefaultValue |= XML_COMPLETE_ATTRS; + xmlLoadExtDtdDefaultValue |= XML_COMPLETE_ATTRS; // validate each document after load/create (?) //xmlDoValidityCheckingDefaultValue = 1; @@ -282,18 +339,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/libxml2_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