summaryrefslogtreecommitdiff
path: root/build_glob.py
diff options
context:
space:
mode:
authorDaniel Veillard <veillard@src.gnome.org>2003-05-15 22:11:36 +0000
committerDaniel Veillard <veillard@src.gnome.org>2003-05-15 22:11:36 +0000
commit781ac8b19bfc10635a8bb83158f874116fd7559e (patch)
treed4d835a320b96fd08c5dea232346e63cd20e9fb7 /build_glob.py
parent6f7e24bb7d94e2163ef26fdad860a3cd06116549 (diff)
downloadlibxml2-781ac8b19bfc10635a8bb83158f874116fd7559e.tar.gz
patch from Stéphane Bidoul for setting up threads global defaults. this
* build_glob.py global.data globals.c parser.c include/libxml/globals.h: patch from Sté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 Daniel
Diffstat (limited to 'build_glob.py')
-rwxr-xr-xbuild_glob.py39
1 files changed, 27 insertions, 12 deletions
diff --git a/build_glob.py b/build_glob.py
index dc42c245..8855ec79 100755
--- a/build_glob.py
+++ b/build_glob.py
@@ -16,10 +16,15 @@ class globvar:
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(os.linesep)
+ file.write("\n")
if __name__ == "__main__":
globals={}
@@ -34,8 +39,7 @@ if __name__ == "__main__":
# Automatically generated string
#
for line in global_hdr:
- if line[-len(os.linesep):] == os.linesep:
- line = line[:-len(os.linesep)]
+ line = striplinesep(line)
if line == " * Automatically generated by build_glob.py.":
break
writeline(global_functions_hdr, line)
@@ -46,8 +50,7 @@ if __name__ == "__main__":
writeline(global_functions_hdr)
for line in global_code:
- if line[-len(os.linesep):] == os.linesep:
- line = line[:-len(os.linesep)]
+ line = striplinesep(line)
if line == " * Automatically generated by build_glob.py.":
break
writeline(global_functions_impl, line)
@@ -61,36 +64,38 @@ if __name__ == "__main__":
for line in global_data:
if line[0]=='#':
continue
- if line[-len(os.linesep):] == os.linesep:
- line = line[:-len(os.linesep)]
+ line = striplinesep(line)
fields = string.split(line, ",")
# Update the header file
writeline(global_functions_hdr)
global_functions_hdr.write("extern "+fields[0]+" *")
- if len(fields) == 3:
+ if fields[2]:
global_functions_hdr.write("(*")
global_functions_hdr.write("__"+fields[1]+"(void)")
- if len(fields) == 3:
+ 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 len(fields) == 3:
+ 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 len(fields) == 3:
+ if fields[2]:
global_functions_impl.write("(*")
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, " if (IS_MAIN_THREAD)")
@@ -98,6 +103,16 @@ if __name__ == "__main__":
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")