[xml] per thread globals initialization patch
- From: Stéphane Bidoul <stephane bidoul softwareag com>
- To: Daniel Veillard <veillard redhat com>
- Cc: xml gnome org
- Subject: [xml] per thread globals initialization patch
- Date: Thu, 15 May 2003 21:13:19 +0200
Daniel,
Here is my improved patch for per-thread globals initializers.
As you suggested, it now uses names like xmlThrDefTheVariable.
I also made one method that returns the previous value instead
of a pair of set/get (you gain 3 more characters per function name
and 12 public functions that would not have been used so often
anyway).
Have a look...
-sbi
Index: build_glob.py
===================================================================
RCS file: /cvs/gnome/gnome-xml/build_glob.py,v
retrieving revision 1.3
diff -c -b -r1.3 build_glob.py
*** build_glob.py 10 Feb 2002 13:20:36 -0000 1.3
--- build_glob.py 15 May 2003 19:00:11 -0000
***************
*** 16,25 ****
self.type=type
self.name=name
def writeline(file, line=None):
if line:
file.write(line)
! file.write(os.linesep)
if __name__ == "__main__":
globals={}
--- 16,30 ----
self.type=type
self.name=name
+ def striplinesep(line):
+ while line and line[-1] in ('\r','\n'):
+ line = line[:-1]
+ return line
+
def writeline(file, line=None):
if line:
file.write(line)
! file.write("\n")
if __name__ == "__main__":
globals={}
***************
*** 34,41 ****
# Automatically generated string
#
for line in global_hdr:
! if line[-len(os.linesep):] == os.linesep:
! line = line[:-len(os.linesep)]
if line == " * Automatically generated by build_glob.py.":
break
writeline(global_functions_hdr, line)
--- 39,45 ----
# Automatically generated string
#
for line in global_hdr:
! line = striplinesep(line)
if line == " * Automatically generated by build_glob.py.":
break
writeline(global_functions_hdr, line)
***************
*** 46,53 ****
writeline(global_functions_hdr)
for line in global_code:
! if line[-len(os.linesep):] == os.linesep:
! line = line[:-len(os.linesep)]
if line == " * Automatically generated by build_glob.py.":
break
writeline(global_functions_impl, line)
--- 50,56 ----
writeline(global_functions_hdr)
for line in global_code:
! line = striplinesep(line)
if line == " * Automatically generated by build_glob.py.":
break
writeline(global_functions_impl, line)
***************
*** 61,96 ****
for line in global_data:
if line[0]=='#':
continue
! if line[-len(os.linesep):] == os.linesep:
! line = line[:-len(os.linesep)]
fields = string.split(line, ",")
# Update the header file
writeline(global_functions_hdr)
global_functions_hdr.write("extern "+fields[0]+" *")
! if len(fields) == 3:
global_functions_hdr.write("(*")
global_functions_hdr.write("__"+fields[1]+"(void)")
! if len(fields) == 3:
global_functions_hdr.write(")"+fields[2])
writeline(global_functions_hdr,";")
writeline(global_functions_hdr, "#ifdef LIBXML_THREAD_ENABLED")
writeline(global_functions_hdr,"#define "+fields[1]+" \\")
writeline(global_functions_hdr,"(*(__"+fields[1]+"()))")
writeline(global_functions_hdr,"#else")
! if len(fields) == 3:
writeline(global_functions_hdr,"LIBXML_DLL_IMPORT extern "+fields[0]+"
"+fields[1]+fields[2]+";")
else:
writeline(global_functions_hdr,"LIBXML_DLL_IMPORT extern "+fields[0]+" "+fields[1]+";")
writeline(global_functions_hdr,"#endif")
# Update the implementation file
writeline(global_functions_impl)
# writeline(global_functions_impl, "extern "+fields[0]+" "+fields[1]+";")
writeline(global_functions_impl, "#undef\t"+fields[1])
writeline(global_functions_impl, fields[0]+" *")
! if len(fields) == 3:
global_functions_impl.write("(*")
global_functions_impl.write("__"+fields[1]+"(void)")
! if len(fields) == 3:
writeline(global_functions_impl, ")[]")
writeline(global_functions_impl, " {")
writeline(global_functions_impl, " if (IS_MAIN_THREAD)")
--- 64,101 ----
for line in global_data:
if line[0]=='#':
continue
! line = striplinesep(line)
fields = string.split(line, ",")
# Update the header file
writeline(global_functions_hdr)
global_functions_hdr.write("extern "+fields[0]+" *")
! if fields[2]:
global_functions_hdr.write("(*")
global_functions_hdr.write("__"+fields[1]+"(void)")
! if fields[2]:
global_functions_hdr.write(")"+fields[2])
writeline(global_functions_hdr,";")
writeline(global_functions_hdr, "#ifdef LIBXML_THREAD_ENABLED")
writeline(global_functions_hdr,"#define "+fields[1]+" \\")
writeline(global_functions_hdr,"(*(__"+fields[1]+"()))")
writeline(global_functions_hdr,"#else")
! if fields[2]:
writeline(global_functions_hdr,"LIBXML_DLL_IMPORT extern "+fields[0]+"
"+fields[1]+fields[2]+";")
else:
writeline(global_functions_hdr,"LIBXML_DLL_IMPORT extern "+fields[0]+" "+fields[1]+";")
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
writeline(global_functions_impl)
# writeline(global_functions_impl, "extern "+fields[0]+" "+fields[1]+";")
writeline(global_functions_impl, "#undef\t"+fields[1])
writeline(global_functions_impl, fields[0]+" *")
! if fields[2]:
global_functions_impl.write("(*")
global_functions_impl.write("__"+fields[1]+"(void)")
! if fields[2]:
writeline(global_functions_impl, ")[]")
writeline(global_functions_impl, " {")
writeline(global_functions_impl, " if (IS_MAIN_THREAD)")
***************
*** 98,103 ****
--- 103,118 ----
writeline(global_functions_impl, " else")
writeline(global_functions_impl, "\treturn (&xmlGetGlobalState()->"+fields[1]+");")
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
writeline(global_functions_hdr)
writeline(global_functions_hdr, "#ifdef __cplusplus")
Index: global.data
===================================================================
RCS file: /cvs/gnome/gnome-xml/global.data,v
retrieving revision 1.5
diff -c -b -r1.5 global.data
*** global.data 1 Jan 2003 20:59:37 -0000 1.5
--- global.data 15 May 2003 19:00:11 -0000
***************
*** 1,24 ****
! int,oldXMLWDcompatibility
! xmlBufferAllocationScheme,xmlBufferAllocScheme
! int,xmlDefaultBufferSize
! xmlSAXHandler,xmlDefaultSAXHandler
! xmlSAXLocator,xmlDefaultSAXLocator
! int,xmlDoValidityCheckingDefaultValue
! xmlGenericErrorFunc,xmlGenericError
! void *,xmlGenericErrorContext
! int,xmlGetWarningsDefaultValue
! int,xmlIndentTreeOutput
! const char *,xmlTreeIndentString
! int,xmlKeepBlanksDefaultValue
! int,xmlLineNumbersDefaultValue
! int,xmlLoadExtDtdDefaultValue
! int,xmlParserDebugEntities
! const char *,xmlParserVersion
! int,xmlPedanticParserDefaultValue
! int,xmlSaveNoEmptyTags
! #const xmlChar,xmlStringComment,[]
! #const xmlChar,xmlStringText,[]
! #const xmlChar,xmlStringTextNoenc,[]
! int,xmlSubstituteEntitiesDefaultValue
! xmlRegisterNodeFunc,xmlRegisterNodeDefaultValue
! xmlDeregisterNodeFunc,xmlDeregisterNodeDefaultValue
--- 1,25 ----
! #type,name,array?,threadGlobalDefault accessor?
! int,oldXMLWDcompatibility,,
! xmlBufferAllocationScheme,xmlBufferAllocScheme,,1
! int,xmlDefaultBufferSize,,1
! xmlSAXHandler,xmlDefaultSAXHandler,,
! xmlSAXLocator,xmlDefaultSAXLocator,,
! int,xmlDoValidityCheckingDefaultValue,,1
! xmlGenericErrorFunc,xmlGenericError,,
! void *,xmlGenericErrorContext,,
! int,xmlGetWarningsDefaultValue,,1
! int,xmlIndentTreeOutput,,1
! const char *,xmlTreeIndentString,,1
! int,xmlKeepBlanksDefaultValue,,1
! int,xmlLineNumbersDefaultValue,,1
! int,xmlLoadExtDtdDefaultValue,,1
! int,xmlParserDebugEntities,,1
! const char *,xmlParserVersion,,
! int,xmlPedanticParserDefaultValue,,1
! int,xmlSaveNoEmptyTags,,1
! #const xmlChar,xmlStringComment,[],1
! #const xmlChar,xmlStringText,[],1
! #const xmlChar,xmlStringTextNoenc,[],1
! int,xmlSubstituteEntitiesDefaultValue,,1
! xmlRegisterNodeFunc,xmlRegisterNodeDefaultValue,,
! xmlDeregisterNodeFunc,xmlDeregisterNodeDefaultValue,,
Index: parser.c
===================================================================
RCS file: /cvs/gnome/gnome-xml/parser.c,v
retrieving revision 1.267
diff -c -b -r1.267 parser.c
*** parser.c 9 May 2003 22:26:28 -0000 1.267
--- parser.c 15 May 2003 19:00:15 -0000
***************
*** 11140,11145 ****
--- 11140,11146 ----
if ((xmlGenericError == xmlGenericErrorDefaultFunc) ||
(xmlGenericError == NULL))
initGenericErrorDefaultFunc(NULL);
+ xmlInitGlobals();
xmlInitThreads();
xmlInitMemory();
xmlInitCharEncodingHandlers();
***************
*** 11176,11180 ****
--- 11177,11182 ----
xmlCatalogCleanup();
#endif
xmlCleanupThreads();
+ xmlCleanupGlobals();
xmlParserInitialized = 0;
}
Index: include/libxml/globals.h
===================================================================
RCS file: /cvs/gnome/gnome-xml/include/libxml/globals.h,v
retrieving revision 1.11
diff -c -b -r1.11 globals.h
*** include/libxml/globals.h 19 Apr 2003 00:07:51 -0000 1.11
--- include/libxml/globals.h 15 May 2003 19:00:16 -0000
***************
*** 22,27 ****
--- 22,30 ----
extern "C" {
#endif
+ void xmlInitGlobals();
+ void xmlCleanupGlobals();
+
/*
* Externally global symbols which need to be protected for backwards
* compatibility support.
***************
*** 112,119 ****
--- 115,126 ----
void xmlInitializeGlobalState(xmlGlobalStatePtr gs);
+ void xmlThrDefSetGenericErrorFunc(void *ctx, xmlGenericErrorFunc handler);
+
xmlRegisterNodeFunc xmlRegisterNodeDefault(xmlRegisterNodeFunc func);
+ xmlRegisterNodeFunc xmlThrDefRegisterNodeDefault(xmlRegisterNodeFunc func);
xmlDeregisterNodeFunc xmlDeregisterNodeDefault(xmlDeregisterNodeFunc func);
+ xmlDeregisterNodeFunc xmlThrDefDeregisterNodeDefault(xmlDeregisterNodeFunc func);
/*
* In general the memory allocation entry points are not kept
***************
*** 217,222 ****
--- 224,230 ----
#else
LIBXML_DLL_IMPORT extern xmlBufferAllocationScheme xmlBufferAllocScheme;
#endif
+ xmlBufferAllocationScheme xmlThrDefBufferAllocScheme(xmlBufferAllocationScheme v);
extern int *__xmlDefaultBufferSize(void);
#ifdef LIBXML_THREAD_ENABLED
***************
*** 225,230 ****
--- 233,239 ----
#else
LIBXML_DLL_IMPORT extern int xmlDefaultBufferSize;
#endif
+ int xmlThrDefDefaultBufferSize(int v);
extern xmlSAXHandler *__xmlDefaultSAXHandler(void);
#ifdef LIBXML_THREAD_ENABLED
***************
*** 249,254 ****
--- 258,264 ----
#else
LIBXML_DLL_IMPORT extern int xmlDoValidityCheckingDefaultValue;
#endif
+ int xmlThrDefDoValidityCheckingDefaultValue(int v);
extern xmlGenericErrorFunc *__xmlGenericError(void);
#ifdef LIBXML_THREAD_ENABLED
***************
*** 273,278 ****
--- 283,289 ----
#else
LIBXML_DLL_IMPORT extern int xmlGetWarningsDefaultValue;
#endif
+ int xmlThrDefGetWarningsDefaultValue(int v);
extern int *__xmlIndentTreeOutput(void);
#ifdef LIBXML_THREAD_ENABLED
***************
*** 281,286 ****
--- 292,298 ----
#else
LIBXML_DLL_IMPORT extern int xmlIndentTreeOutput;
#endif
+ int xmlThrDefIndentTreeOutput(int v);
extern const char * *__xmlTreeIndentString(void);
#ifdef LIBXML_THREAD_ENABLED
***************
*** 289,294 ****
--- 301,307 ----
#else
LIBXML_DLL_IMPORT extern const char * xmlTreeIndentString;
#endif
+ const char * xmlThrDefTreeIndentString(const char * v);
extern int *__xmlKeepBlanksDefaultValue(void);
#ifdef LIBXML_THREAD_ENABLED
***************
*** 297,302 ****
--- 310,316 ----
#else
LIBXML_DLL_IMPORT extern int xmlKeepBlanksDefaultValue;
#endif
+ int xmlThrDefKeepBlanksDefaultValue(int v);
extern int *__xmlLineNumbersDefaultValue(void);
#ifdef LIBXML_THREAD_ENABLED
***************
*** 305,310 ****
--- 319,325 ----
#else
LIBXML_DLL_IMPORT extern int xmlLineNumbersDefaultValue;
#endif
+ int xmlThrDefLineNumbersDefaultValue(int v);
extern int *__xmlLoadExtDtdDefaultValue(void);
#ifdef LIBXML_THREAD_ENABLED
***************
*** 313,318 ****
--- 328,334 ----
#else
LIBXML_DLL_IMPORT extern int xmlLoadExtDtdDefaultValue;
#endif
+ int xmlThrDefLoadExtDtdDefaultValue(int v);
extern int *__xmlParserDebugEntities(void);
#ifdef LIBXML_THREAD_ENABLED
***************
*** 321,326 ****
--- 337,343 ----
#else
LIBXML_DLL_IMPORT extern int xmlParserDebugEntities;
#endif
+ int xmlThrDefParserDebugEntities(int v);
extern const char * *__xmlParserVersion(void);
#ifdef LIBXML_THREAD_ENABLED
***************
*** 337,342 ****
--- 354,360 ----
#else
LIBXML_DLL_IMPORT extern int xmlPedanticParserDefaultValue;
#endif
+ int xmlThrDefPedanticParserDefaultValue(int v);
extern int *__xmlSaveNoEmptyTags(void);
#ifdef LIBXML_THREAD_ENABLED
***************
*** 345,350 ****
--- 363,369 ----
#else
LIBXML_DLL_IMPORT extern int xmlSaveNoEmptyTags;
#endif
+ int xmlThrDefSaveNoEmptyTags(int v);
extern int *__xmlSubstituteEntitiesDefaultValue(void);
#ifdef LIBXML_THREAD_ENABLED
***************
*** 353,358 ****
--- 372,378 ----
#else
LIBXML_DLL_IMPORT extern int xmlSubstituteEntitiesDefaultValue;
#endif
+ int xmlThrDefSubstituteEntitiesDefaultValue(int v);
extern xmlRegisterNodeFunc *__xmlRegisterNodeDefaultValue(void);
#ifdef LIBXML_THREAD_ENABLED
Index: python/libxml.c
===================================================================
RCS file: /cvs/gnome/gnome-xml/python/libxml.c,v
retrieving revision 1.42
diff -c -b -r1.42 libxml.c
*** python/libxml.c 23 Apr 2003 07:36:50 -0000 1.42
--- python/libxml.c 15 May 2003 19:00:16 -0000
***************
*** 1267,1272 ****
--- 1267,1273 ----
printf("libxml_xmlErrorInitialize() called\n");
#endif
xmlSetGenericErrorFunc(NULL, libxml_xmlErrorFuncHandler);
+ xmlThrDefSetGenericErrorFunc(NULL, libxml_xmlErrorFuncHandler);
}
PyObject *
***************
*** 1767,1773 ****
printf("libxml_xpathCallbacksInitialized called\n");
#endif
! for (i = 0; i < 10; i++) {
libxml_xpathCallbacks[i].ctx = NULL;
libxml_xpathCallbacks[i].name = NULL;
libxml_xpathCallbacks[i].ns_uri = NULL;
--- 1768,1774 ----
printf("libxml_xpathCallbacksInitialized called\n");
#endif
! for (i = 0; i < libxml_xpathCallbacksMax; i++) {
libxml_xpathCallbacks[i].ctx = NULL;
libxml_xpathCallbacks[i].name = NULL;
libxml_xpathCallbacks[i].ns_uri = NULL;
***************
*** 2620,2625 ****
--- 2621,2628 ----
if (initialized != 0)
return;
+ /* XXX xmlInitParser does much more than this */
+ xmlInitGlobals();
xmlRegisterDefaultOutputCallbacks();
xmlRegisterDefaultInputCallbacks();
m = Py_InitModule((char *) "libxml2mod", libxmlMethods);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]