1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-08-07 06:43:02 +03:00

patch from Stphane Bidoul for setting up threads global defaults. this

* build_glob.py global.data globals.c parser.c
  include/libxml/globals.h: patch from Stphane Bidoul for setting
  up threads global defaults.
* doc/libxml2-api.xml: this extends the API with new functions
* python/tests/Makefile.am python/tests/reader2.py
  python/tests/thread2.py: integrated the associated testcase and
  fixed the error string used in reader2
Daniel
This commit is contained in:
Daniel Veillard
2003-05-15 22:11:36 +00:00
parent 6f7e24bb7d
commit 781ac8b19b
12 changed files with 511 additions and 57 deletions

View File

@@ -1,3 +1,13 @@
Thu May 15 18:06:18 EDT 2003 Daniel Veillard <daniel@veillard.com>
* build_glob.py global.data globals.c parser.c
include/libxml/globals.h: patch from St<53>phane Bidoul for setting
up threads global defaults.
* doc/libxml2-api.xml: this extends the API with new functions
* python/tests/Makefile.am python/tests/reader2.py
python/tests/thread2.py: integrated the associated testcase and
fixed the error string used in reader2
Wed May 14 14:56:46 EDT 2003 Daniel Veillard <daniel@veillard.com> Wed May 14 14:56:46 EDT 2003 Daniel Veillard <daniel@veillard.com>
* configure.in libxml.spec.in python/Makefile.am: trying * configure.in libxml.spec.in python/Makefile.am: trying

View File

@@ -16,10 +16,15 @@ class globvar:
self.type=type self.type=type
self.name=name self.name=name
def striplinesep(line):
while line and line[-1] in ('\r','\n'):
line = line[:-1]
return line
def writeline(file, line=None): def writeline(file, line=None):
if line: if line:
file.write(line) file.write(line)
file.write(os.linesep) file.write("\n")
if __name__ == "__main__": if __name__ == "__main__":
globals={} globals={}
@@ -34,8 +39,7 @@ if __name__ == "__main__":
# Automatically generated string # Automatically generated string
# #
for line in global_hdr: for line in global_hdr:
if line[-len(os.linesep):] == os.linesep: line = striplinesep(line)
line = line[:-len(os.linesep)]
if line == " * Automatically generated by build_glob.py.": if line == " * Automatically generated by build_glob.py.":
break break
writeline(global_functions_hdr, line) writeline(global_functions_hdr, line)
@@ -46,8 +50,7 @@ if __name__ == "__main__":
writeline(global_functions_hdr) writeline(global_functions_hdr)
for line in global_code: for line in global_code:
if line[-len(os.linesep):] == os.linesep: line = striplinesep(line)
line = line[:-len(os.linesep)]
if line == " * Automatically generated by build_glob.py.": if line == " * Automatically generated by build_glob.py.":
break break
writeline(global_functions_impl, line) writeline(global_functions_impl, line)
@@ -61,36 +64,38 @@ if __name__ == "__main__":
for line in global_data: for line in global_data:
if line[0]=='#': if line[0]=='#':
continue continue
if line[-len(os.linesep):] == os.linesep: line = striplinesep(line)
line = line[:-len(os.linesep)]
fields = string.split(line, ",") fields = string.split(line, ",")
# Update the header file # Update the header file
writeline(global_functions_hdr) writeline(global_functions_hdr)
global_functions_hdr.write("extern "+fields[0]+" *") global_functions_hdr.write("extern "+fields[0]+" *")
if len(fields) == 3: if fields[2]:
global_functions_hdr.write("(*") global_functions_hdr.write("(*")
global_functions_hdr.write("__"+fields[1]+"(void)") global_functions_hdr.write("__"+fields[1]+"(void)")
if len(fields) == 3: if fields[2]:
global_functions_hdr.write(")"+fields[2]) global_functions_hdr.write(")"+fields[2])
writeline(global_functions_hdr,";") writeline(global_functions_hdr,";")
writeline(global_functions_hdr, "#ifdef LIBXML_THREAD_ENABLED") writeline(global_functions_hdr, "#ifdef LIBXML_THREAD_ENABLED")
writeline(global_functions_hdr,"#define "+fields[1]+" \\") writeline(global_functions_hdr,"#define "+fields[1]+" \\")
writeline(global_functions_hdr,"(*(__"+fields[1]+"()))") writeline(global_functions_hdr,"(*(__"+fields[1]+"()))")
writeline(global_functions_hdr,"#else") writeline(global_functions_hdr,"#else")
if len(fields) == 3: if fields[2]:
writeline(global_functions_hdr,"LIBXML_DLL_IMPORT extern "+fields[0]+" "+fields[1]+fields[2]+";") writeline(global_functions_hdr,"LIBXML_DLL_IMPORT extern "+fields[0]+" "+fields[1]+fields[2]+";")
else: else:
writeline(global_functions_hdr,"LIBXML_DLL_IMPORT extern "+fields[0]+" "+fields[1]+";") writeline(global_functions_hdr,"LIBXML_DLL_IMPORT extern "+fields[0]+" "+fields[1]+";")
writeline(global_functions_hdr,"#endif") writeline(global_functions_hdr,"#endif")
# set/get for per-thread global defaults
if fields[3]:
writeline(global_functions_hdr,fields[0]+" "+fields[1][:3]+"ThrDef"+fields[1][3:]+"("+fields[0]+" v);")
# Update the implementation file # Update the implementation file
writeline(global_functions_impl) writeline(global_functions_impl)
# writeline(global_functions_impl, "extern "+fields[0]+" "+fields[1]+";") # writeline(global_functions_impl, "extern "+fields[0]+" "+fields[1]+";")
writeline(global_functions_impl, "#undef\t"+fields[1]) writeline(global_functions_impl, "#undef\t"+fields[1])
writeline(global_functions_impl, fields[0]+" *") writeline(global_functions_impl, fields[0]+" *")
if len(fields) == 3: if fields[2]:
global_functions_impl.write("(*") global_functions_impl.write("(*")
global_functions_impl.write("__"+fields[1]+"(void)") global_functions_impl.write("__"+fields[1]+"(void)")
if len(fields) == 3: if fields[2]:
writeline(global_functions_impl, ")[]") writeline(global_functions_impl, ")[]")
writeline(global_functions_impl, " {") writeline(global_functions_impl, " {")
writeline(global_functions_impl, " if (IS_MAIN_THREAD)") writeline(global_functions_impl, " if (IS_MAIN_THREAD)")
@@ -98,6 +103,16 @@ if __name__ == "__main__":
writeline(global_functions_impl, " else") writeline(global_functions_impl, " else")
writeline(global_functions_impl, "\treturn (&xmlGetGlobalState()->"+fields[1]+");") writeline(global_functions_impl, "\treturn (&xmlGetGlobalState()->"+fields[1]+");")
writeline(global_functions_impl, "}") writeline(global_functions_impl, "}")
# set/get for per-thread global defaults
if fields[3]:
writeline(global_functions_impl,fields[0]+" "+fields[1][:3]+"ThrDef"+fields[1][3:]+"("+fields[0]+" v) {")
writeline(global_functions_impl," "+fields[0]+" ret;");
writeline(global_functions_impl," xmlMutexLock(xmlThrDefMutex);")
writeline(global_functions_impl," ret = "+fields[1][:3]+fields[1][3:]+"ThrDef;")
writeline(global_functions_impl," "+fields[1][:3]+fields[1][3:]+"ThrDef = v;")
writeline(global_functions_impl," xmlMutexUnlock(xmlThrDefMutex);")
writeline(global_functions_impl," return ret;")
writeline(global_functions_impl,"}")
# Terminate the header file with appropriate boilerplate # Terminate the header file with appropriate boilerplate
writeline(global_functions_hdr) writeline(global_functions_hdr)
writeline(global_functions_hdr, "#ifdef __cplusplus") writeline(global_functions_hdr, "#ifdef __cplusplus")

View File

@@ -1514,6 +1514,7 @@
<exports symbol='oldXMLWDcompatibility'/> <exports symbol='oldXMLWDcompatibility'/>
<exports symbol='xmlBufferAllocScheme'/> <exports symbol='xmlBufferAllocScheme'/>
<exports symbol='xmlBufferAllocScheme'/> <exports symbol='xmlBufferAllocScheme'/>
<exports symbol='xmlCleanupGlobals'/>
<exports symbol='xmlDefaultBufferSize'/> <exports symbol='xmlDefaultBufferSize'/>
<exports symbol='xmlDefaultBufferSize'/> <exports symbol='xmlDefaultBufferSize'/>
<exports symbol='xmlDefaultSAXHandler'/> <exports symbol='xmlDefaultSAXHandler'/>
@@ -1538,6 +1539,7 @@
<exports symbol='xmlGlobalStatePtr'/> <exports symbol='xmlGlobalStatePtr'/>
<exports symbol='xmlIndentTreeOutput'/> <exports symbol='xmlIndentTreeOutput'/>
<exports symbol='xmlIndentTreeOutput'/> <exports symbol='xmlIndentTreeOutput'/>
<exports symbol='xmlInitGlobals'/>
<exports symbol='xmlInitializeGlobalState'/> <exports symbol='xmlInitializeGlobalState'/>
<exports symbol='xmlKeepBlanksDefaultValue'/> <exports symbol='xmlKeepBlanksDefaultValue'/>
<exports symbol='xmlKeepBlanksDefaultValue'/> <exports symbol='xmlKeepBlanksDefaultValue'/>
@@ -1567,6 +1569,22 @@
<exports symbol='xmlSaveNoEmptyTags'/> <exports symbol='xmlSaveNoEmptyTags'/>
<exports symbol='xmlSubstituteEntitiesDefaultValue'/> <exports symbol='xmlSubstituteEntitiesDefaultValue'/>
<exports symbol='xmlSubstituteEntitiesDefaultValue'/> <exports symbol='xmlSubstituteEntitiesDefaultValue'/>
<exports symbol='xmlThrDefBufferAllocScheme'/>
<exports symbol='xmlThrDefDefaultBufferSize'/>
<exports symbol='xmlThrDefDeregisterNodeDefault'/>
<exports symbol='xmlThrDefDoValidityCheckingDefaultValue'/>
<exports symbol='xmlThrDefGetWarningsDefaultValue'/>
<exports symbol='xmlThrDefIndentTreeOutput'/>
<exports symbol='xmlThrDefKeepBlanksDefaultValue'/>
<exports symbol='xmlThrDefLineNumbersDefaultValue'/>
<exports symbol='xmlThrDefLoadExtDtdDefaultValue'/>
<exports symbol='xmlThrDefParserDebugEntities'/>
<exports symbol='xmlThrDefPedanticParserDefaultValue'/>
<exports symbol='xmlThrDefRegisterNodeDefault'/>
<exports symbol='xmlThrDefSaveNoEmptyTags'/>
<exports symbol='xmlThrDefSetGenericErrorFunc'/>
<exports symbol='xmlThrDefSubstituteEntitiesDefaultValue'/>
<exports symbol='xmlThrDefTreeIndentString'/>
<exports symbol='xmlTreeIndentString'/> <exports symbol='xmlTreeIndentString'/>
<exports symbol='xmlTreeIndentString'/> <exports symbol='xmlTreeIndentString'/>
</file> </file>
@@ -5383,6 +5401,10 @@ actually an xmlCharEncoding'/>
<info>Unregisters all aliases</info> <info>Unregisters all aliases</info>
<return type='void'/> <return type='void'/>
</function> </function>
<function name='xmlCleanupGlobals' file='globals'>
<info></info>
<return type='void'/>
</function>
<function name='xmlCleanupInputCallbacks' file='xmlIO'> <function name='xmlCleanupInputCallbacks' file='xmlIO'>
<info>clears the entire input callback table. this includes the compiled-in I/O.</info> <info>clears the entire input callback table. this includes the compiled-in I/O.</info>
<return type='void'/> <return type='void'/>
@@ -6439,6 +6461,10 @@ actually an xmlCharEncoding'/>
<info>Initialize the char encoding support, it registers the default encoding supported. NOTE: while public, this function usually doesn&apos;t need to be called in normal processing.</info> <info>Initialize the char encoding support, it registers the default encoding supported. NOTE: while public, this function usually doesn&apos;t need to be called in normal processing.</info>
<return type='void'/> <return type='void'/>
</function> </function>
<function name='xmlInitGlobals' file='globals'>
<info></info>
<return type='void'/>
</function>
<function name='xmlInitMemory' file='xmlmemory'> <function name='xmlInitMemory' file='xmlmemory'>
<info>Initialize the memory layer.</info> <info>Initialize the memory layer.</info>
<return type='int' info='0 on success'/> <return type='int' info='0 on success'/>
@@ -9300,6 +9326,87 @@ actually an xmlCharEncoding'/>
<return type='xmlChar *' info='the xml:lang value or NULL if none exists.'/> <return type='xmlChar *' info='the xml:lang value or NULL if none exists.'/>
<arg name='reader' type='xmlTextReaderPtr' info='the xmlTextReaderPtr used'/> <arg name='reader' type='xmlTextReaderPtr' info='the xmlTextReaderPtr used'/>
</function> </function>
<function name='xmlThrDefBufferAllocScheme' file='globals'>
<info></info>
<return type='xmlBufferAllocationScheme' info=''/>
<arg name='v' type='xmlBufferAllocationScheme' info=''/>
</function>
<function name='xmlThrDefDefaultBufferSize' file='globals'>
<info></info>
<return type='int' info=''/>
<arg name='v' type='int' info=''/>
</function>
<function name='xmlThrDefDeregisterNodeDefault' file='globals'>
<info></info>
<return type='xmlDeregisterNodeFunc' info=''/>
<arg name='func' type='xmlDeregisterNodeFunc' info=''/>
</function>
<function name='xmlThrDefDoValidityCheckingDefaultValue' file='globals'>
<info></info>
<return type='int' info=''/>
<arg name='v' type='int' info=''/>
</function>
<function name='xmlThrDefGetWarningsDefaultValue' file='globals'>
<info></info>
<return type='int' info=''/>
<arg name='v' type='int' info=''/>
</function>
<function name='xmlThrDefIndentTreeOutput' file='globals'>
<info></info>
<return type='int' info=''/>
<arg name='v' type='int' info=''/>
</function>
<function name='xmlThrDefKeepBlanksDefaultValue' file='globals'>
<info></info>
<return type='int' info=''/>
<arg name='v' type='int' info=''/>
</function>
<function name='xmlThrDefLineNumbersDefaultValue' file='globals'>
<info></info>
<return type='int' info=''/>
<arg name='v' type='int' info=''/>
</function>
<function name='xmlThrDefLoadExtDtdDefaultValue' file='globals'>
<info></info>
<return type='int' info=''/>
<arg name='v' type='int' info=''/>
</function>
<function name='xmlThrDefParserDebugEntities' file='globals'>
<info></info>
<return type='int' info=''/>
<arg name='v' type='int' info=''/>
</function>
<function name='xmlThrDefPedanticParserDefaultValue' file='globals'>
<info></info>
<return type='int' info=''/>
<arg name='v' type='int' info=''/>
</function>
<function name='xmlThrDefRegisterNodeDefault' file='globals'>
<info></info>
<return type='xmlRegisterNodeFunc' info=''/>
<arg name='func' type='xmlRegisterNodeFunc' info=''/>
</function>
<function name='xmlThrDefSaveNoEmptyTags' file='globals'>
<info></info>
<return type='int' info=''/>
<arg name='v' type='int' info=''/>
</function>
<function name='xmlThrDefSetGenericErrorFunc' file='globals'>
<info></info>
<return type='void'/>
<arg name='ctx' type='void *' info=''/>
<arg name='handler' type='xmlGenericErrorFunc' info=''/>
</function>
<function name='xmlThrDefSubstituteEntitiesDefaultValue' file='globals'>
<info></info>
<return type='int' info=''/>
<arg name='v' type='int' info=''/>
</function>
<function name='xmlThrDefTreeIndentString' file='globals'>
<info></info>
<return type='const char *' info=''/>
<arg name='v' type='const char *' info=''/>
</function>
<function name='xmlUCSIsAlphabeticPresentationForms' file='xmlunicode'> <function name='xmlUCSIsAlphabeticPresentationForms' file='xmlunicode'>
<info>Check whether the character is part of AlphabeticPresentationForms UCS Block</info> <info>Check whether the character is part of AlphabeticPresentationForms UCS Block</info>
<return type='int' info='1 if true 0 otherwise'/> <return type='int' info='1 if true 0 otherwise'/>

View File

@@ -1,24 +1,25 @@
int,oldXMLWDcompatibility #type,name,array?,threadGlobalDefault accessor?
xmlBufferAllocationScheme,xmlBufferAllocScheme int,oldXMLWDcompatibility,,
int,xmlDefaultBufferSize xmlBufferAllocationScheme,xmlBufferAllocScheme,,1
xmlSAXHandler,xmlDefaultSAXHandler int,xmlDefaultBufferSize,,1
xmlSAXLocator,xmlDefaultSAXLocator xmlSAXHandler,xmlDefaultSAXHandler,,
int,xmlDoValidityCheckingDefaultValue xmlSAXLocator,xmlDefaultSAXLocator,,
xmlGenericErrorFunc,xmlGenericError int,xmlDoValidityCheckingDefaultValue,,1
void *,xmlGenericErrorContext xmlGenericErrorFunc,xmlGenericError,,
int,xmlGetWarningsDefaultValue void *,xmlGenericErrorContext,,
int,xmlIndentTreeOutput int,xmlGetWarningsDefaultValue,,1
const char *,xmlTreeIndentString int,xmlIndentTreeOutput,,1
int,xmlKeepBlanksDefaultValue const char *,xmlTreeIndentString,,1
int,xmlLineNumbersDefaultValue int,xmlKeepBlanksDefaultValue,,1
int,xmlLoadExtDtdDefaultValue int,xmlLineNumbersDefaultValue,,1
int,xmlParserDebugEntities int,xmlLoadExtDtdDefaultValue,,1
const char *,xmlParserVersion int,xmlParserDebugEntities,,1
int,xmlPedanticParserDefaultValue const char *,xmlParserVersion,,
int,xmlSaveNoEmptyTags int,xmlPedanticParserDefaultValue,,1
#const xmlChar,xmlStringComment,[] int,xmlSaveNoEmptyTags,,1
#const xmlChar,xmlStringText,[] #const xmlChar,xmlStringComment,[],1
#const xmlChar,xmlStringTextNoenc,[] #const xmlChar,xmlStringText,[],1
int,xmlSubstituteEntitiesDefaultValue #const xmlChar,xmlStringTextNoenc,[],1
xmlRegisterNodeFunc,xmlRegisterNodeDefaultValue int,xmlSubstituteEntitiesDefaultValue,,1
xmlDeregisterNodeFunc,xmlDeregisterNodeDefaultValue xmlRegisterNodeFunc,xmlRegisterNodeDefaultValue,,
xmlDeregisterNodeFunc,xmlDeregisterNodeDefaultValue,,

217
globals.c
View File

@@ -21,6 +21,7 @@
#include <libxml/globals.h> #include <libxml/globals.h>
#include <libxml/xmlmemory.h> #include <libxml/xmlmemory.h>
#include <libxml/threads.h>
/* #define DEBUG_GLOBALS */ /* #define DEBUG_GLOBALS */
@@ -33,6 +34,21 @@
#define IS_MAIN_THREAD 1 #define IS_MAIN_THREAD 1
#endif #endif
/*
* Mutex to protect "ForNewThreads" variables
*/
static xmlMutexPtr xmlThrDefMutex = NULL;
void xmlInitGlobals()
{
xmlThrDefMutex = xmlNewMutex();
}
void xmlCleanupGlobals()
{
xmlFreeMutex(xmlThrDefMutex);
}
/************************************************************************ /************************************************************************
* * * *
* All the user accessible global variables of the library * * All the user accessible global variables of the library *
@@ -150,12 +166,14 @@ const char *xmlParserVersion = LIBXML_VERSION_STRING;
* XML_BUFFER_ALLOC_EXACT * XML_BUFFER_ALLOC_EXACT
*/ */
xmlBufferAllocationScheme xmlBufferAllocScheme = XML_BUFFER_ALLOC_EXACT; xmlBufferAllocationScheme xmlBufferAllocScheme = XML_BUFFER_ALLOC_EXACT;
static xmlBufferAllocationScheme xmlBufferAllocSchemeThrDef = XML_BUFFER_ALLOC_EXACT;
/** /**
* xmlDefaultBufferSize: * xmlDefaultBufferSize:
* *
* Global setting, default buffer size. Default value is BASE_BUFFER_SIZE * Global setting, default buffer size. Default value is BASE_BUFFER_SIZE
*/ */
int xmlDefaultBufferSize = BASE_BUFFER_SIZE; int xmlDefaultBufferSize = BASE_BUFFER_SIZE;
static int xmlDefaultBufferSizeThrDef = BASE_BUFFER_SIZE;
/* /*
* Parser defaults * Parser defaults
@@ -175,6 +193,7 @@ int oldXMLWDcompatibility = 0; /* DEPRECATED */
* Disabled by default * Disabled by default
*/ */
int xmlParserDebugEntities = 0; int xmlParserDebugEntities = 0;
static int xmlParserDebugEntitiesThrDef = 0;
/** /**
* xmlDoValidityCheckingDefaultValue: * xmlDoValidityCheckingDefaultValue:
* *
@@ -182,6 +201,7 @@ int xmlParserDebugEntities = 0;
* Disabled by default. * Disabled by default.
*/ */
int xmlDoValidityCheckingDefaultValue = 0; int xmlDoValidityCheckingDefaultValue = 0;
static int xmlDoValidityCheckingDefaultValueThrDef = 0;
/** /**
* xmlGetWarningsDefaultValue: * xmlGetWarningsDefaultValue:
* *
@@ -189,6 +209,7 @@ int xmlDoValidityCheckingDefaultValue = 0;
* Activated by default. * Activated by default.
*/ */
int xmlGetWarningsDefaultValue = 1; int xmlGetWarningsDefaultValue = 1;
static int xmlGetWarningsDefaultValueThrDef = 1;
/** /**
* xmlLoadExtDtdDefaultValue: * xmlLoadExtDtdDefaultValue:
* *
@@ -197,6 +218,7 @@ int xmlGetWarningsDefaultValue = 1;
* Disabled by default. * Disabled by default.
*/ */
int xmlLoadExtDtdDefaultValue = 0; int xmlLoadExtDtdDefaultValue = 0;
static int xmlLoadExtDtdDefaultValueThrDef = 0;
/** /**
* xmlPedanticParserDefaultValue: * xmlPedanticParserDefaultValue:
* *
@@ -204,6 +226,7 @@ int xmlLoadExtDtdDefaultValue = 0;
* Disabled by default. * Disabled by default.
*/ */
int xmlPedanticParserDefaultValue = 0; int xmlPedanticParserDefaultValue = 0;
static int xmlPedanticParserDefaultValueThrDef = 0;
/** /**
* xmlLineNumbersDefaultValue: * xmlLineNumbersDefaultValue:
* *
@@ -213,6 +236,7 @@ int xmlPedanticParserDefaultValue = 0;
* applicaton. * applicaton.
*/ */
int xmlLineNumbersDefaultValue = 0; int xmlLineNumbersDefaultValue = 0;
static int xmlLineNumbersDefaultValueThrDef = 0;
/** /**
* xmlKeepBlanksDefaultValue: * xmlKeepBlanksDefaultValue:
* *
@@ -223,6 +247,7 @@ int xmlLineNumbersDefaultValue = 0;
* for some applications since this was libxml1 default behaviour. * for some applications since this was libxml1 default behaviour.
*/ */
int xmlKeepBlanksDefaultValue = 1; int xmlKeepBlanksDefaultValue = 1;
static int xmlKeepBlanksDefaultValueThrDef = 1;
/** /**
* xmlSubstituteEntitiesDefaultValue: * xmlSubstituteEntitiesDefaultValue:
* *
@@ -233,9 +258,12 @@ int xmlKeepBlanksDefaultValue = 1;
* engine does not handle entities references transparently. * engine does not handle entities references transparently.
*/ */
int xmlSubstituteEntitiesDefaultValue = 0; int xmlSubstituteEntitiesDefaultValue = 0;
static int xmlSubstituteEntitiesDefaultValueThrDef = 0;
xmlRegisterNodeFunc xmlRegisterNodeDefaultValue = NULL; xmlRegisterNodeFunc xmlRegisterNodeDefaultValue = NULL;
static xmlRegisterNodeFunc xmlRegisterNodeDefaultValueThrDef = NULL;
xmlDeregisterNodeFunc xmlDeregisterNodeDefaultValue = NULL; xmlDeregisterNodeFunc xmlDeregisterNodeDefaultValue = NULL;
static xmlDeregisterNodeFunc xmlDeregisterNodeDefaultValueThrDef = NULL;
/* /*
* Error handling * Error handling
@@ -252,12 +280,14 @@ void xmlGenericErrorDefaultFunc (void *ctx ATTRIBUTE_UNUSED,
* Global setting: function used for generic error callbacks * Global setting: function used for generic error callbacks
*/ */
xmlGenericErrorFunc xmlGenericError = xmlGenericErrorDefaultFunc; xmlGenericErrorFunc xmlGenericError = xmlGenericErrorDefaultFunc;
static xmlGenericErrorFunc xmlGenericErrorThrDef = xmlGenericErrorDefaultFunc;
/** /**
* xmlGenericErrorContext: * xmlGenericErrorContext:
* *
* Global setting passed to generic error callbacks * Global setting passed to generic error callbacks
*/ */
void *xmlGenericErrorContext = NULL; void *xmlGenericErrorContext = NULL;
static void *xmlGenericErrorContextThrDef = NULL;
/* /*
* output defaults * output defaults
@@ -269,6 +299,7 @@ void *xmlGenericErrorContext = NULL;
* Enabled by default * Enabled by default
*/ */
int xmlIndentTreeOutput = 1; int xmlIndentTreeOutput = 1;
static int xmlIndentTreeOutputThrDef = 1;
/** /**
* xmlTreeIndentString: * xmlTreeIndentString:
@@ -276,6 +307,7 @@ int xmlIndentTreeOutput = 1;
* The string used to do one-level indent. By default is equal to " " (two spaces) * The string used to do one-level indent. By default is equal to " " (two spaces)
*/ */
const char *xmlTreeIndentString = " "; const char *xmlTreeIndentString = " ";
static const char *xmlTreeIndentStringThrDef = " ";
/** /**
* xmlSaveNoEmptyTags: * xmlSaveNoEmptyTags:
@@ -286,6 +318,7 @@ const char *xmlTreeIndentString = " ";
* Disabled by default * Disabled by default
*/ */
int xmlSaveNoEmptyTags = 0; int xmlSaveNoEmptyTags = 0;
int xmlSaveNoEmptyTagsThrDef = 0;
/** /**
* xmlDefaultSAXHandler: * xmlDefaultSAXHandler:
@@ -427,6 +460,7 @@ xmlInitializeGlobalState(xmlGlobalStatePtr gs)
/* /*
* Perform initialization as required by libxml * Perform initialization as required by libxml
*/ */
xmlMutexLock(xmlThrDefMutex);
#ifdef LIBXML_DOCB_ENABLED #ifdef LIBXML_DOCB_ENABLED
initdocbDefaultSAXHandler(&gs->docbDefaultSAXHandler); initdocbDefaultSAXHandler(&gs->docbDefaultSAXHandler);
@@ -434,17 +468,17 @@ xmlInitializeGlobalState(xmlGlobalStatePtr gs)
#ifdef LIBXML_HTML_ENABLED #ifdef LIBXML_HTML_ENABLED
inithtmlDefaultSAXHandler(&gs->htmlDefaultSAXHandler); inithtmlDefaultSAXHandler(&gs->htmlDefaultSAXHandler);
#endif #endif
initGenericErrorDefaultFunc(&gs->xmlGenericError);
gs->oldXMLWDcompatibility = 0; gs->oldXMLWDcompatibility = 0;
gs->xmlBufferAllocScheme = XML_BUFFER_ALLOC_EXACT; gs->xmlBufferAllocScheme = xmlBufferAllocSchemeThrDef;
gs->xmlDefaultBufferSize = BASE_BUFFER_SIZE; gs->xmlDefaultBufferSize = xmlDefaultBufferSizeThrDef;
initxmlDefaultSAXHandler(&gs->xmlDefaultSAXHandler, 1); initxmlDefaultSAXHandler(&gs->xmlDefaultSAXHandler, 1);
gs->xmlDefaultSAXLocator.getPublicId = getPublicId; gs->xmlDefaultSAXLocator.getPublicId = getPublicId;
gs->xmlDefaultSAXLocator.getSystemId = getSystemId; gs->xmlDefaultSAXLocator.getSystemId = getSystemId;
gs->xmlDefaultSAXLocator.getLineNumber = getLineNumber; gs->xmlDefaultSAXLocator.getLineNumber = getLineNumber;
gs->xmlDefaultSAXLocator.getColumnNumber = getColumnNumber; gs->xmlDefaultSAXLocator.getColumnNumber = getColumnNumber;
gs->xmlDoValidityCheckingDefaultValue = 0; gs->xmlDoValidityCheckingDefaultValue =
xmlDoValidityCheckingDefaultValueThrDef;
#if defined(DEBUG_MEMORY_LOCATION) | defined(DEBUG_MEMORY) #if defined(DEBUG_MEMORY_LOCATION) | defined(DEBUG_MEMORY)
gs->xmlFree = (xmlFreeFunc) xmlMemFree; gs->xmlFree = (xmlFreeFunc) xmlMemFree;
gs->xmlMalloc = (xmlMallocFunc) xmlMemMalloc; gs->xmlMalloc = (xmlMallocFunc) xmlMemMalloc;
@@ -458,21 +492,36 @@ xmlInitializeGlobalState(xmlGlobalStatePtr gs)
gs->xmlRealloc = (xmlReallocFunc) realloc; gs->xmlRealloc = (xmlReallocFunc) realloc;
gs->xmlMemStrdup = (xmlStrdupFunc) xmlStrdup; gs->xmlMemStrdup = (xmlStrdupFunc) xmlStrdup;
#endif #endif
gs->xmlGenericErrorContext = NULL; gs->xmlGetWarningsDefaultValue = xmlGetWarningsDefaultValueThrDef;
gs->xmlGetWarningsDefaultValue = 1; gs->xmlIndentTreeOutput = xmlIndentTreeOutputThrDef;
gs->xmlIndentTreeOutput = 1; gs->xmlTreeIndentString = xmlTreeIndentStringThrDef;
gs->xmlTreeIndentString = " "; gs->xmlKeepBlanksDefaultValue = xmlKeepBlanksDefaultValueThrDef;
gs->xmlKeepBlanksDefaultValue = 1; gs->xmlLineNumbersDefaultValue = xmlLineNumbersDefaultValueThrDef;
gs->xmlLineNumbersDefaultValue = 0; gs->xmlLoadExtDtdDefaultValue = xmlLoadExtDtdDefaultValueThrDef;
gs->xmlLoadExtDtdDefaultValue = 0; gs->xmlParserDebugEntities = xmlParserDebugEntitiesThrDef;
gs->xmlParserDebugEntities = 0;
gs->xmlParserVersion = LIBXML_VERSION_STRING; gs->xmlParserVersion = LIBXML_VERSION_STRING;
gs->xmlPedanticParserDefaultValue = 0; gs->xmlPedanticParserDefaultValue = xmlPedanticParserDefaultValueThrDef;
gs->xmlSaveNoEmptyTags = 0; gs->xmlSaveNoEmptyTags = xmlSaveNoEmptyTagsThrDef;
gs->xmlSubstituteEntitiesDefaultValue = 0; gs->xmlSubstituteEntitiesDefaultValue =
xmlSubstituteEntitiesDefaultValueThrDef;
gs->xmlRegisterNodeDefaultValue = NULL; gs->xmlGenericError = xmlGenericErrorThrDef;
gs->xmlDeregisterNodeDefaultValue = NULL; gs->xmlGenericErrorContext = xmlGenericErrorContextThrDef;
gs->xmlRegisterNodeDefaultValue = xmlRegisterNodeDefaultValueThrDef;
gs->xmlDeregisterNodeDefaultValue = xmlDeregisterNodeDefaultValueThrDef;
xmlMutexUnlock(xmlThrDefMutex);
}
void
xmlThrDefSetGenericErrorFunc(void *ctx, xmlGenericErrorFunc handler) {
xmlMutexLock(xmlThrDefMutex);
xmlGenericErrorContextThrDef = ctx;
if (handler != NULL)
xmlGenericErrorThrDef = handler;
else
xmlGenericErrorThrDef = xmlGenericErrorDefaultFunc;
xmlMutexUnlock(xmlThrDefMutex);
} }
/** /**
@@ -493,6 +542,21 @@ xmlRegisterNodeDefault(xmlRegisterNodeFunc func)
return(old); return(old);
} }
xmlRegisterNodeFunc
xmlThrDefRegisterNodeDefault(xmlRegisterNodeFunc func)
{
xmlRegisterNodeFunc old;
xmlMutexLock(xmlThrDefMutex);
old = xmlRegisterNodeDefaultValueThrDef;
__xmlRegisterCallbacks = 1;
xmlRegisterNodeDefaultValueThrDef = func;
xmlMutexUnlock(xmlThrDefMutex);
return(old);
}
/** /**
* xmlDeregisterNodeDefault: * xmlDeregisterNodeDefault:
* @func: function pointer to the new DeregisterNodeFunc * @func: function pointer to the new DeregisterNodeFunc
@@ -511,6 +575,21 @@ xmlDeregisterNodeDefault(xmlDeregisterNodeFunc func)
return(old); return(old);
} }
xmlDeregisterNodeFunc
xmlThrDefDeregisterNodeDefault(xmlDeregisterNodeFunc func)
{
xmlDeregisterNodeFunc old;
xmlMutexLock(xmlThrDefMutex);
old = xmlDeregisterNodeDefaultValueThrDef;
__xmlRegisterCallbacks = 1;
xmlDeregisterNodeDefaultValueThrDef = func;
xmlMutexUnlock(xmlThrDefMutex);
return(old);
}
#ifdef LIBXML_DOCB_ENABLED #ifdef LIBXML_DOCB_ENABLED
#undef docbDefaultSAXHandler #undef docbDefaultSAXHandler
@@ -558,6 +637,14 @@ __xmlBufferAllocScheme(void) {
else else
return (&xmlGetGlobalState()->xmlBufferAllocScheme); return (&xmlGetGlobalState()->xmlBufferAllocScheme);
} }
xmlBufferAllocationScheme xmlThrDefBufferAllocScheme(xmlBufferAllocationScheme v) {
xmlBufferAllocationScheme ret;
xmlMutexLock(xmlThrDefMutex);
ret = xmlBufferAllocSchemeThrDef;
xmlBufferAllocSchemeThrDef = v;
xmlMutexUnlock(xmlThrDefMutex);
return ret;
}
#undef xmlDefaultBufferSize #undef xmlDefaultBufferSize
int * int *
@@ -567,6 +654,14 @@ __xmlDefaultBufferSize(void) {
else else
return (&xmlGetGlobalState()->xmlDefaultBufferSize); return (&xmlGetGlobalState()->xmlDefaultBufferSize);
} }
int xmlThrDefDefaultBufferSize(int v) {
int ret;
xmlMutexLock(xmlThrDefMutex);
ret = xmlDefaultBufferSizeThrDef;
xmlDefaultBufferSizeThrDef = v;
xmlMutexUnlock(xmlThrDefMutex);
return ret;
}
#undef xmlDefaultSAXHandler #undef xmlDefaultSAXHandler
xmlSAXHandler * xmlSAXHandler *
@@ -594,6 +689,14 @@ __xmlDoValidityCheckingDefaultValue(void) {
else else
return (&xmlGetGlobalState()->xmlDoValidityCheckingDefaultValue); return (&xmlGetGlobalState()->xmlDoValidityCheckingDefaultValue);
} }
int xmlThrDefDoValidityCheckingDefaultValue(int v) {
int ret;
xmlMutexLock(xmlThrDefMutex);
ret = xmlDoValidityCheckingDefaultValueThrDef;
xmlDoValidityCheckingDefaultValueThrDef = v;
xmlMutexUnlock(xmlThrDefMutex);
return ret;
}
#undef xmlGenericError #undef xmlGenericError
xmlGenericErrorFunc * xmlGenericErrorFunc *
@@ -621,6 +724,14 @@ __xmlGetWarningsDefaultValue(void) {
else else
return (&xmlGetGlobalState()->xmlGetWarningsDefaultValue); return (&xmlGetGlobalState()->xmlGetWarningsDefaultValue);
} }
int xmlThrDefGetWarningsDefaultValue(int v) {
int ret;
xmlMutexLock(xmlThrDefMutex);
ret = xmlGetWarningsDefaultValueThrDef;
xmlGetWarningsDefaultValueThrDef = v;
xmlMutexUnlock(xmlThrDefMutex);
return ret;
}
#undef xmlIndentTreeOutput #undef xmlIndentTreeOutput
int * int *
@@ -630,6 +741,14 @@ __xmlIndentTreeOutput(void) {
else else
return (&xmlGetGlobalState()->xmlIndentTreeOutput); return (&xmlGetGlobalState()->xmlIndentTreeOutput);
} }
int xmlThrDefIndentTreeOutput(int v) {
int ret;
xmlMutexLock(xmlThrDefMutex);
ret = xmlIndentTreeOutputThrDef;
xmlIndentTreeOutputThrDef = v;
xmlMutexUnlock(xmlThrDefMutex);
return ret;
}
#undef xmlTreeIndentString #undef xmlTreeIndentString
const char * * const char * *
@@ -639,6 +758,14 @@ __xmlTreeIndentString(void) {
else else
return (&xmlGetGlobalState()->xmlTreeIndentString); return (&xmlGetGlobalState()->xmlTreeIndentString);
} }
const char * xmlThrDefTreeIndentString(const char * v) {
const char * ret;
xmlMutexLock(xmlThrDefMutex);
ret = xmlTreeIndentStringThrDef;
xmlTreeIndentStringThrDef = v;
xmlMutexUnlock(xmlThrDefMutex);
return ret;
}
#undef xmlKeepBlanksDefaultValue #undef xmlKeepBlanksDefaultValue
int * int *
@@ -648,6 +775,14 @@ __xmlKeepBlanksDefaultValue(void) {
else else
return (&xmlGetGlobalState()->xmlKeepBlanksDefaultValue); return (&xmlGetGlobalState()->xmlKeepBlanksDefaultValue);
} }
int xmlThrDefKeepBlanksDefaultValue(int v) {
int ret;
xmlMutexLock(xmlThrDefMutex);
ret = xmlKeepBlanksDefaultValueThrDef;
xmlKeepBlanksDefaultValueThrDef = v;
xmlMutexUnlock(xmlThrDefMutex);
return ret;
}
#undef xmlLineNumbersDefaultValue #undef xmlLineNumbersDefaultValue
int * int *
@@ -657,6 +792,14 @@ __xmlLineNumbersDefaultValue(void) {
else else
return (&xmlGetGlobalState()->xmlLineNumbersDefaultValue); return (&xmlGetGlobalState()->xmlLineNumbersDefaultValue);
} }
int xmlThrDefLineNumbersDefaultValue(int v) {
int ret;
xmlMutexLock(xmlThrDefMutex);
ret = xmlLineNumbersDefaultValueThrDef;
xmlLineNumbersDefaultValueThrDef = v;
xmlMutexUnlock(xmlThrDefMutex);
return ret;
}
#undef xmlLoadExtDtdDefaultValue #undef xmlLoadExtDtdDefaultValue
int * int *
@@ -666,6 +809,14 @@ __xmlLoadExtDtdDefaultValue(void) {
else else
return (&xmlGetGlobalState()->xmlLoadExtDtdDefaultValue); return (&xmlGetGlobalState()->xmlLoadExtDtdDefaultValue);
} }
int xmlThrDefLoadExtDtdDefaultValue(int v) {
int ret;
xmlMutexLock(xmlThrDefMutex);
ret = xmlLoadExtDtdDefaultValueThrDef;
xmlLoadExtDtdDefaultValueThrDef = v;
xmlMutexUnlock(xmlThrDefMutex);
return ret;
}
#undef xmlParserDebugEntities #undef xmlParserDebugEntities
int * int *
@@ -675,6 +826,14 @@ __xmlParserDebugEntities(void) {
else else
return (&xmlGetGlobalState()->xmlParserDebugEntities); return (&xmlGetGlobalState()->xmlParserDebugEntities);
} }
int xmlThrDefParserDebugEntities(int v) {
int ret;
xmlMutexLock(xmlThrDefMutex);
ret = xmlParserDebugEntitiesThrDef;
xmlParserDebugEntitiesThrDef = v;
xmlMutexUnlock(xmlThrDefMutex);
return ret;
}
#undef xmlParserVersion #undef xmlParserVersion
const char * * const char * *
@@ -693,6 +852,14 @@ __xmlPedanticParserDefaultValue(void) {
else else
return (&xmlGetGlobalState()->xmlPedanticParserDefaultValue); return (&xmlGetGlobalState()->xmlPedanticParserDefaultValue);
} }
int xmlThrDefPedanticParserDefaultValue(int v) {
int ret;
xmlMutexLock(xmlThrDefMutex);
ret = xmlPedanticParserDefaultValueThrDef;
xmlPedanticParserDefaultValueThrDef = v;
xmlMutexUnlock(xmlThrDefMutex);
return ret;
}
#undef xmlSaveNoEmptyTags #undef xmlSaveNoEmptyTags
int * int *
@@ -702,6 +869,14 @@ __xmlSaveNoEmptyTags(void) {
else else
return (&xmlGetGlobalState()->xmlSaveNoEmptyTags); return (&xmlGetGlobalState()->xmlSaveNoEmptyTags);
} }
int xmlThrDefSaveNoEmptyTags(int v) {
int ret;
xmlMutexLock(xmlThrDefMutex);
ret = xmlSaveNoEmptyTagsThrDef;
xmlSaveNoEmptyTagsThrDef = v;
xmlMutexUnlock(xmlThrDefMutex);
return ret;
}
#undef xmlSubstituteEntitiesDefaultValue #undef xmlSubstituteEntitiesDefaultValue
int * int *
@@ -711,6 +886,14 @@ __xmlSubstituteEntitiesDefaultValue(void) {
else else
return (&xmlGetGlobalState()->xmlSubstituteEntitiesDefaultValue); return (&xmlGetGlobalState()->xmlSubstituteEntitiesDefaultValue);
} }
int xmlThrDefSubstituteEntitiesDefaultValue(int v) {
int ret;
xmlMutexLock(xmlThrDefMutex);
ret = xmlSubstituteEntitiesDefaultValueThrDef;
xmlSubstituteEntitiesDefaultValueThrDef = v;
xmlMutexUnlock(xmlThrDefMutex);
return ret;
}
#undef xmlRegisterNodeDefaultValue #undef xmlRegisterNodeDefaultValue
xmlRegisterNodeFunc * xmlRegisterNodeFunc *

View File

@@ -22,6 +22,9 @@
extern "C" { extern "C" {
#endif #endif
void xmlInitGlobals(void);
void xmlCleanupGlobals(void);
/* /*
* Externally global symbols which need to be protected for backwards * Externally global symbols which need to be protected for backwards
* compatibility support. * compatibility support.
@@ -112,8 +115,12 @@ extern "C" {
void xmlInitializeGlobalState(xmlGlobalStatePtr gs); void xmlInitializeGlobalState(xmlGlobalStatePtr gs);
void xmlThrDefSetGenericErrorFunc(void *ctx, xmlGenericErrorFunc handler);
xmlRegisterNodeFunc xmlRegisterNodeDefault(xmlRegisterNodeFunc func); xmlRegisterNodeFunc xmlRegisterNodeDefault(xmlRegisterNodeFunc func);
xmlRegisterNodeFunc xmlThrDefRegisterNodeDefault(xmlRegisterNodeFunc func);
xmlDeregisterNodeFunc xmlDeregisterNodeDefault(xmlDeregisterNodeFunc func); xmlDeregisterNodeFunc xmlDeregisterNodeDefault(xmlDeregisterNodeFunc func);
xmlDeregisterNodeFunc xmlThrDefDeregisterNodeDefault(xmlDeregisterNodeFunc func);
/* /*
* In general the memory allocation entry points are not kept * In general the memory allocation entry points are not kept
@@ -217,6 +224,7 @@ extern xmlBufferAllocationScheme *__xmlBufferAllocScheme(void);
#else #else
LIBXML_DLL_IMPORT extern xmlBufferAllocationScheme xmlBufferAllocScheme; LIBXML_DLL_IMPORT extern xmlBufferAllocationScheme xmlBufferAllocScheme;
#endif #endif
xmlBufferAllocationScheme xmlThrDefBufferAllocScheme(xmlBufferAllocationScheme v);
extern int *__xmlDefaultBufferSize(void); extern int *__xmlDefaultBufferSize(void);
#ifdef LIBXML_THREAD_ENABLED #ifdef LIBXML_THREAD_ENABLED
@@ -225,6 +233,7 @@ extern int *__xmlDefaultBufferSize(void);
#else #else
LIBXML_DLL_IMPORT extern int xmlDefaultBufferSize; LIBXML_DLL_IMPORT extern int xmlDefaultBufferSize;
#endif #endif
int xmlThrDefDefaultBufferSize(int v);
extern xmlSAXHandler *__xmlDefaultSAXHandler(void); extern xmlSAXHandler *__xmlDefaultSAXHandler(void);
#ifdef LIBXML_THREAD_ENABLED #ifdef LIBXML_THREAD_ENABLED
@@ -249,6 +258,7 @@ extern int *__xmlDoValidityCheckingDefaultValue(void);
#else #else
LIBXML_DLL_IMPORT extern int xmlDoValidityCheckingDefaultValue; LIBXML_DLL_IMPORT extern int xmlDoValidityCheckingDefaultValue;
#endif #endif
int xmlThrDefDoValidityCheckingDefaultValue(int v);
extern xmlGenericErrorFunc *__xmlGenericError(void); extern xmlGenericErrorFunc *__xmlGenericError(void);
#ifdef LIBXML_THREAD_ENABLED #ifdef LIBXML_THREAD_ENABLED
@@ -273,6 +283,7 @@ extern int *__xmlGetWarningsDefaultValue(void);
#else #else
LIBXML_DLL_IMPORT extern int xmlGetWarningsDefaultValue; LIBXML_DLL_IMPORT extern int xmlGetWarningsDefaultValue;
#endif #endif
int xmlThrDefGetWarningsDefaultValue(int v);
extern int *__xmlIndentTreeOutput(void); extern int *__xmlIndentTreeOutput(void);
#ifdef LIBXML_THREAD_ENABLED #ifdef LIBXML_THREAD_ENABLED
@@ -281,6 +292,7 @@ extern int *__xmlIndentTreeOutput(void);
#else #else
LIBXML_DLL_IMPORT extern int xmlIndentTreeOutput; LIBXML_DLL_IMPORT extern int xmlIndentTreeOutput;
#endif #endif
int xmlThrDefIndentTreeOutput(int v);
extern const char * *__xmlTreeIndentString(void); extern const char * *__xmlTreeIndentString(void);
#ifdef LIBXML_THREAD_ENABLED #ifdef LIBXML_THREAD_ENABLED
@@ -289,6 +301,7 @@ extern const char * *__xmlTreeIndentString(void);
#else #else
LIBXML_DLL_IMPORT extern const char * xmlTreeIndentString; LIBXML_DLL_IMPORT extern const char * xmlTreeIndentString;
#endif #endif
const char * xmlThrDefTreeIndentString(const char * v);
extern int *__xmlKeepBlanksDefaultValue(void); extern int *__xmlKeepBlanksDefaultValue(void);
#ifdef LIBXML_THREAD_ENABLED #ifdef LIBXML_THREAD_ENABLED
@@ -297,6 +310,7 @@ extern int *__xmlKeepBlanksDefaultValue(void);
#else #else
LIBXML_DLL_IMPORT extern int xmlKeepBlanksDefaultValue; LIBXML_DLL_IMPORT extern int xmlKeepBlanksDefaultValue;
#endif #endif
int xmlThrDefKeepBlanksDefaultValue(int v);
extern int *__xmlLineNumbersDefaultValue(void); extern int *__xmlLineNumbersDefaultValue(void);
#ifdef LIBXML_THREAD_ENABLED #ifdef LIBXML_THREAD_ENABLED
@@ -305,6 +319,7 @@ extern int *__xmlLineNumbersDefaultValue(void);
#else #else
LIBXML_DLL_IMPORT extern int xmlLineNumbersDefaultValue; LIBXML_DLL_IMPORT extern int xmlLineNumbersDefaultValue;
#endif #endif
int xmlThrDefLineNumbersDefaultValue(int v);
extern int *__xmlLoadExtDtdDefaultValue(void); extern int *__xmlLoadExtDtdDefaultValue(void);
#ifdef LIBXML_THREAD_ENABLED #ifdef LIBXML_THREAD_ENABLED
@@ -313,6 +328,7 @@ extern int *__xmlLoadExtDtdDefaultValue(void);
#else #else
LIBXML_DLL_IMPORT extern int xmlLoadExtDtdDefaultValue; LIBXML_DLL_IMPORT extern int xmlLoadExtDtdDefaultValue;
#endif #endif
int xmlThrDefLoadExtDtdDefaultValue(int v);
extern int *__xmlParserDebugEntities(void); extern int *__xmlParserDebugEntities(void);
#ifdef LIBXML_THREAD_ENABLED #ifdef LIBXML_THREAD_ENABLED
@@ -321,6 +337,7 @@ extern int *__xmlParserDebugEntities(void);
#else #else
LIBXML_DLL_IMPORT extern int xmlParserDebugEntities; LIBXML_DLL_IMPORT extern int xmlParserDebugEntities;
#endif #endif
int xmlThrDefParserDebugEntities(int v);
extern const char * *__xmlParserVersion(void); extern const char * *__xmlParserVersion(void);
#ifdef LIBXML_THREAD_ENABLED #ifdef LIBXML_THREAD_ENABLED
@@ -337,6 +354,7 @@ extern int *__xmlPedanticParserDefaultValue(void);
#else #else
LIBXML_DLL_IMPORT extern int xmlPedanticParserDefaultValue; LIBXML_DLL_IMPORT extern int xmlPedanticParserDefaultValue;
#endif #endif
int xmlThrDefPedanticParserDefaultValue(int v);
extern int *__xmlSaveNoEmptyTags(void); extern int *__xmlSaveNoEmptyTags(void);
#ifdef LIBXML_THREAD_ENABLED #ifdef LIBXML_THREAD_ENABLED
@@ -345,6 +363,7 @@ extern int *__xmlSaveNoEmptyTags(void);
#else #else
LIBXML_DLL_IMPORT extern int xmlSaveNoEmptyTags; LIBXML_DLL_IMPORT extern int xmlSaveNoEmptyTags;
#endif #endif
int xmlThrDefSaveNoEmptyTags(int v);
extern int *__xmlSubstituteEntitiesDefaultValue(void); extern int *__xmlSubstituteEntitiesDefaultValue(void);
#ifdef LIBXML_THREAD_ENABLED #ifdef LIBXML_THREAD_ENABLED
@@ -353,6 +372,7 @@ extern int *__xmlSubstituteEntitiesDefaultValue(void);
#else #else
LIBXML_DLL_IMPORT extern int xmlSubstituteEntitiesDefaultValue; LIBXML_DLL_IMPORT extern int xmlSubstituteEntitiesDefaultValue;
#endif #endif
int xmlThrDefSubstituteEntitiesDefaultValue(int v);
extern xmlRegisterNodeFunc *__xmlRegisterNodeDefaultValue(void); extern xmlRegisterNodeFunc *__xmlRegisterNodeDefaultValue(void);
#ifdef LIBXML_THREAD_ENABLED #ifdef LIBXML_THREAD_ENABLED

View File

@@ -11140,6 +11140,7 @@ xmlInitParser(void) {
if ((xmlGenericError == xmlGenericErrorDefaultFunc) || if ((xmlGenericError == xmlGenericErrorDefaultFunc) ||
(xmlGenericError == NULL)) (xmlGenericError == NULL))
initGenericErrorDefaultFunc(NULL); initGenericErrorDefaultFunc(NULL);
xmlInitGlobals();
xmlInitThreads(); xmlInitThreads();
xmlInitMemory(); xmlInitMemory();
xmlInitCharEncodingHandlers(); xmlInitCharEncodingHandlers();
@@ -11176,5 +11177,6 @@ xmlCleanupParser(void) {
xmlCatalogCleanup(); xmlCatalogCleanup();
#endif #endif
xmlCleanupThreads(); xmlCleanupThreads();
xmlCleanupGlobals();
xmlParserInitialized = 0; xmlParserInitialized = 0;
} }

View File

@@ -1267,6 +1267,7 @@ libxml_xmlErrorInitialize(void)
printf("libxml_xmlErrorInitialize() called\n"); printf("libxml_xmlErrorInitialize() called\n");
#endif #endif
xmlSetGenericErrorFunc(NULL, libxml_xmlErrorFuncHandler); xmlSetGenericErrorFunc(NULL, libxml_xmlErrorFuncHandler);
xmlThrDefSetGenericErrorFunc(NULL, libxml_xmlErrorFuncHandler);
} }
PyObject * PyObject *
@@ -1767,7 +1768,7 @@ libxml_xpathCallbacksInitialize(void)
printf("libxml_xpathCallbacksInitialized called\n"); printf("libxml_xpathCallbacksInitialized called\n");
#endif #endif
for (i = 0; i < 10; i++) { for (i = 0; i < libxml_xpathCallbacksMax; i++) {
libxml_xpathCallbacks[i].ctx = NULL; libxml_xpathCallbacks[i].ctx = NULL;
libxml_xpathCallbacks[i].name = NULL; libxml_xpathCallbacks[i].name = NULL;
libxml_xpathCallbacks[i].ns_uri = NULL; libxml_xpathCallbacks[i].ns_uri = NULL;
@@ -2620,6 +2621,8 @@ initlibxml2mod(void)
if (initialized != 0) if (initialized != 0)
return; return;
/* XXX xmlInitParser does much more than this */
xmlInitGlobals();
xmlRegisterDefaultOutputCallbacks(); xmlRegisterDefaultOutputCallbacks();
xmlRegisterDefaultInputCallbacks(); xmlRegisterDefaultInputCallbacks();
m = Py_InitModule((char *) "libxml2mod", libxmlMethods); m = Py_InitModule((char *) "libxml2mod", libxmlMethods);

View File

@@ -63,6 +63,22 @@ cleanupPredefinedEntities()
initializePredefinedEntities() initializePredefinedEntities()
predefinedEntity() predefinedEntity()
# functions from module globals
cleanupGlobals()
initGlobals()
thrDefDefaultBufferSize()
thrDefDoValidityCheckingDefaultValue()
thrDefGetWarningsDefaultValue()
thrDefIndentTreeOutput()
thrDefKeepBlanksDefaultValue()
thrDefLineNumbersDefaultValue()
thrDefLoadExtDtdDefaultValue()
thrDefParserDebugEntities()
thrDefPedanticParserDefaultValue()
thrDefSaveNoEmptyTags()
thrDefSubstituteEntitiesDefaultValue()
thrDefTreeIndentString()
# functions from module nanoftp # functions from module nanoftp
nanoFTPCleanup() nanoFTPCleanup()
nanoFTPInit() nanoFTPInit()

View File

@@ -28,7 +28,8 @@ PYTESTS= \
reader6.py \ reader6.py \
ctxterror.py\ ctxterror.py\
readererr.py\ readererr.py\
relaxng.py relaxng.py \
thread2.py
XMLS= \ XMLS= \
tst.xml \ tst.xml \

View File

@@ -14,10 +14,10 @@ libxml2.debugMemory(1)
err="" err=""
expect="""../../test/valid/rss.xml:172: validity error: Element rss does not carry attribute version expect="""../../test/valid/rss.xml:172: validity error: Element rss does not carry attribute version
</rss> </rss>
^ ^
../../test/valid/xlink.xml:450: validity error: ID dt-arc already defined ../../test/valid/xlink.xml:450: validity error: ID dt-arc already defined
<p><termdef id="dt-arc" term="Arc">An <ter <p><termdef id="dt-arc" term="Arc">An <ter
^ ^
../../test/valid/xlink.xml:530: validity error: attribute def line 199 references an unknown ID "dt-xlg" ../../test/valid/xlink.xml:530: validity error: attribute def line 199 references an unknown ID "dt-xlg"
^ ^

96
python/tests/thread2.py Executable file
View File

@@ -0,0 +1,96 @@
#!/usr/bin/python -u
import string, sys, time
import thread
from threading import Thread, Lock
import libxml2
THREADS_COUNT = 15
failed = 0
class ErrorHandler:
def __init__(self):
self.errors = []
self.lock = Lock()
def handler(self,ctx,str):
self.lock.acquire()
self.errors.append(str)
self.lock.release()
def getLineNumbersDefault():
old = libxml2.lineNumbersDefault(0)
libxml2.lineNumbersDefault(old)
return old
def test(expectedLineNumbersDefault):
time.sleep(1)
global failed
# check a per thread-global
if expectedLineNumbersDefault != getLineNumbersDefault():
failed = 1
print "FAILED to obtain correct value for " \
"lineNumbersDefault in thread %d" % thread.get_ident()
# check ther global error handler
# (which is NOT per-thread in the python bindings)
try:
doc = libxml2.parseFile("bad.xml")
except:
pass
else:
assert "failed"
# global error handler
eh = ErrorHandler()
libxml2.registerErrorHandler(eh.handler,"")
# set on the main thread only
libxml2.lineNumbersDefault(1)
test(1)
ec = len(eh.errors)
if ec == 0:
print "FAILED: should have obtained errors"
sys.exit(1)
ts = []
for i in range(THREADS_COUNT):
# expect 0 for lineNumbersDefault because
# the new value has been set on the main thread only
ts.append(Thread(target=test,args=(0,)))
for t in ts:
t.start()
for t in ts:
t.join()
if len(eh.errors) != ec+THREADS_COUNT*ec:
print "FAILED: did not obtain the correct number of errors"
sys.exit(1)
# set lineNumbersDefault for future new threads
libxml2.thrDefLineNumbersDefaultValue(1)
ts = []
for i in range(THREADS_COUNT):
# expect 1 for lineNumbersDefault
ts.append(Thread(target=test,args=(1,)))
for t in ts:
t.start()
for t in ts:
t.join()
if len(eh.errors) != ec+THREADS_COUNT*ec*2:
print "FAILED: did not obtain the correct number of errors"
sys.exit(1)
if failed:
print "FAILED"
sys.exit(1)
# Memory debug specific
libxml2.cleanupParser()
if libxml2.debugMemory(1) == 0:
print "OK"
else:
print "Memory leak %d bytes" % (libxml2.debugMemory(1))
libxml2.dumpMemory()