summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Veillard <veillard@src.gnome.org>2002-02-22 22:58:47 +0000
committerDaniel Veillard <veillard@src.gnome.org>2002-02-22 22:58:47 +0000
commitbd90990db204676575730e94e032305d1d07d4c3 (patch)
tree339f50f552db3fc96c6e283ef716a133e4250a83
parentac7602771834007af95df5c19775dbd9ad458824 (diff)
downloadlibxslt-bd90990db204676575730e94e032305d1d07d4c3.tar.gz
libxslt-bd90990db204676575730e94e032305d1d07d4c3.tar.bz2
libxslt-bd90990db204676575730e94e032305d1d07d4c3.zip
changes for the 'usual' setup.py to allow building a libxml2-python module
* python/generator.py python/libxslt.c: changes for the 'usual' setup.py to allow building a libxml2-python module based on the same code. The initialization is however different the 2 .so files fo libxml2 and libxslt are identical and they entry point initialize both libraries. this is done to avoid some possible nasty problem since the Python don't merge the maps of all shared modules. * python/libxsl.py: attempt to cope with the shared library loading problem when both modules are not merged. Daniel
-rw-r--r--ChangeLog12
-rwxr-xr-xpython/generator.py657
-rw-r--r--python/libxsl.py48
-rw-r--r--python/libxslt.c14
4 files changed, 418 insertions, 313 deletions
diff --git a/ChangeLog b/ChangeLog
index be59384f..336794d8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+Fri Feb 22 23:44:57 CET 2002 Daniel Veillard <daniel@veillard.com>
+
+ * python/generator.py python/libxslt.c: changes for the 'usual'
+ setup.py to allow building a libxml2-python
+ module based on the same code. The initialization is however
+ different the 2 .so files fo libxml2 and libxslt are identical and
+ they entry point initialize both libraries. this is done to avoid
+ some possible nasty problem since the Python don't merge the maps
+ of all shared modules.
+ * python/libxsl.py: attempt to cope with the shared library loading
+ problem when both modules are not merged.
+
Thu Feb 21 12:59:59 CET 2002 Daniel Veillard <daniel@veillard.com>
* doc/site.xml doc/xslt.html doc/python.html doc/*.html: added
diff --git a/python/generator.py b/python/generator.py
index f6abc76a..6a6abe4a 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -413,63 +413,76 @@ def print_function_wrapper(name, output, export, include):
output.write("}\n\n")
return 1
-try:
- f = open("../doc/libxslt-api.xml")
- data = f.read()
- (parser, target) = getparser()
- parser.feed(data)
- parser.close()
-except IOError, msg:
- print file, ":", msg
-
-n = len(functions.keys())
-print "Found %d functions in libxslt-api.xml" % (n)
-
-py_types['pythonObject'] = ('O', "pythonObject", "pythonObject", "pythonObject", "libxml_")
-try:
- f = open("libxslt-python-api.xml")
- data = f.read()
- (parser, target) = getparser()
- parser.feed(data)
- parser.close()
-except IOError, msg:
- print file, ":", msg
-
-
-print "Found %d functions in libxslt-python-api.xml" % (
- len(functions.keys()) - n)
-nb_wrap = 0
-failed = 0
-skipped = 0
-
-include = open("libxslt-py.h", "w")
-include.write("/* Generated */\n\n")
-export = open("libxslt-export.c", "w")
-export.write("/* Generated */\n\n")
-wrapper = open("libxslt-py.c", "w")
-wrapper.write("/* Generated */\n\n")
-wrapper.write("#include \"libxslt_wrap.h\"\n")
-wrapper.write("#include \"libxslt-py.h\"\n\n")
-for function in functions.keys():
- ret = print_function_wrapper(function, wrapper, export, include)
- if ret < 0:
- failed = failed + 1
- del functions[function]
- if ret == 0:
- skipped = skipped + 1
- del functions[function]
- if ret == 1:
- nb_wrap = nb_wrap + 1
-include.close()
-export.close()
-wrapper.close()
-
-print "Generated %d wrapper functions, %d failed, %d skipped\n" % (nb_wrap,
- failed, skipped);
-print "Missing type converters:"
-for type in unknown_types.keys():
- print "%s:%d " % (type, len(unknown_types[type])),
-print
+def buildStubs():
+ global py_types
+ global py_return_types
+ global unknown_types
+
+ try:
+ f = open("libxslt-api.xml")
+ data = f.read()
+ (parser, target) = getparser()
+ parser.feed(data)
+ parser.close()
+ except IOError, msg:
+ try:
+ f = open("../doc/libxslt-api.xml")
+ data = f.read()
+ (parser, target) = getparser()
+ parser.feed(data)
+ parser.close()
+ except IOError, msg:
+ print "../doc/libxslt-api.xml", ":", msg
+
+ n = len(functions.keys())
+ print "Found %d functions in libxslt-api.xml" % (n)
+
+ py_types['pythonObject'] = ('O', "pythonObject", "pythonObject",
+ "pythonObject", "libxml_")
+ try:
+ f = open("libxslt-python-api.xml")
+ data = f.read()
+ (parser, target) = getparser()
+ parser.feed(data)
+ parser.close()
+ except IOError, msg:
+ print "libxslt-python-api.xml", ":", msg
+
+
+ print "Found %d functions in libxslt-python-api.xml" % (
+ len(functions.keys()) - n)
+ nb_wrap = 0
+ failed = 0
+ skipped = 0
+
+ include = open("libxslt-py.h", "w")
+ include.write("/* Generated */\n\n")
+ export = open("libxslt-export.c", "w")
+ export.write("/* Generated */\n\n")
+ wrapper = open("libxslt-py.c", "w")
+ wrapper.write("/* Generated */\n\n")
+ wrapper.write("#include \"libxslt_wrap.h\"\n")
+ wrapper.write("#include \"libxslt-py.h\"\n\n")
+ for function in functions.keys():
+ ret = print_function_wrapper(function, wrapper, export, include)
+ if ret < 0:
+ failed = failed + 1
+ del functions[function]
+ if ret == 0:
+ skipped = skipped + 1
+ del functions[function]
+ if ret == 1:
+ nb_wrap = nb_wrap + 1
+ include.close()
+ export.close()
+ wrapper.close()
+
+ print "Generated %d wrapper functions, %d failed, %d skipped\n" % (nb_wrap,
+ failed, skipped);
+ print "Missing type converters:"
+ for type in unknown_types.keys():
+ print "%s:%d " % (type, len(unknown_types[type])),
+ print
#######################################################################
#
@@ -532,38 +545,11 @@ classes_destructors = {
}
function_classes = {}
-
-function_classes["None"] = []
-for type in classes_type.keys():
- function_classes[classes_type[type][2]] = []
-
-#
-# Build the list of C types to look for ordered to start with primary classes
-#
ctypes = []
classes_list = []
-ctypes_processed = {}
-classes_processed = {}
-for classe in primary_classes:
- classes_list.append(classe)
- classes_processed[classe] = ()
- for type in classes_type.keys():
- tinfo = classes_type[type]
- if tinfo[2] == classe:
- ctypes.append(type)
- ctypes_processed[type] = ()
-for type in classes_type.keys():
- if ctypes_processed.has_key(type):
- continue
- tinfo = classes_type[type]
- if not classes_processed.has_key(tinfo[2]):
- classes_list.append(tinfo[2])
- classes_processed[tinfo[2]] = ()
-
- ctypes.append(type)
- ctypes_processed[type] = ()
-
-def nameFixup(function, classe, type, file):
+
+
+def nameFixup(name, classe, type, file):
listname = classe + "List"
ll = len(listname)
l = len(classe)
@@ -634,45 +620,6 @@ def nameFixup(function, classe, type, file):
func = "UTF8" + func[4:]
return func
-for name in functions.keys():
- found = 0;
- (desc, ret, args, file) = functions[name]
- for type in ctypes:
- classe = classes_type[type][2]
-
- if name[0:4] == "xslt" and len(args) >= 1 and args[0][1] == type:
- found = 1
- func = nameFixup(name, classe, type, file)
- info = (0, func, name, ret, args, file)
- function_classes[classe].append(info)
- elif name[0:4] == "xslt" and len(args) >= 2 and args[1][1] == type:
- found = 1
- func = nameFixup(name, classe, type, file)
- info = (1, func, name, ret, args, file)
- function_classes[classe].append(info)
- elif name[0:4] == "xslt" and len(args) >= 3 and args[2][1] == type:
- found = 1
- func = nameFixup(name, classe, type, file)
- info = (2, func, name, ret, args, file)
- function_classes[classe].append(info)
- if found == 1:
- break
- if found == 1:
- continue
- if name[0:8] == "xmlXPath":
- continue
- if name[0:6] == "xmlStr":
- continue
- if name[0:10] == "xmlCharStr":
- continue
- func = nameFixup(name, "None", file, file)
- info = (0, func, name, ret, args, file)
- function_classes['None'].append(info)
-
-classes = open("libxsltclass.py", "w")
-txt = open("libxsltclass.txt", "w")
-txt.write(" Generated Classes for libxslt-python\n\n")
-
def functionCompare(info1, info2):
(index1, func1, name1, ret1, args1, file1) = info1
(index2, func2, name2, ret2, args2, file2) = info2
@@ -711,187 +658,277 @@ def writeDoc(name, args, indent, output):
output.write(val);
output.write('"""\n')
-txt.write("#\n# Global functions of the module\n#\n\n")
-if function_classes.has_key("None"):
- flist = function_classes["None"]
- flist.sort(functionCompare)
- oldfile = ""
- for info in flist:
- (index, func, name, ret, args, file) = info
- if file != oldfile:
- classes.write("#\n# Functions from module %s\n#\n\n" % file)
- txt.write("\n# functions from module %s\n" % file)
- oldfile = file
- classes.write("def %s(" % func)
- txt.write("%s()\n" % func);
- n = 0
- for arg in args:
- if n != 0:
- classes.write(", ")
- classes.write("%s" % arg[0])
- n = n + 1
- classes.write("):\n")
- writeDoc(name, args, ' ', classes);
-
- for arg in args:
- if classes_type.has_key(arg[1]):
- classes.write(" if %s == None: %s__o = None\n" %
- (arg[0], arg[0]))
- classes.write(" else: %s__o = %s%s\n" %
- (arg[0], arg[0], classes_type[arg[1]][0]))
- elif libxml2_classes_type.has_key(arg[1]):
- classes.write(" if %s == None: %s__o = None\n" %
- (arg[0], arg[0]))
- classes.write(" else: %s__o = %s%s\n" %
- (arg[0], arg[0], libxml2_classes_type[arg[1]][0]))
- if ret[0] != "void":
- classes.write(" ret = ");
- else:
- classes.write(" ");
- classes.write("libxsltmod.%s(" % name)
- n = 0
- for arg in args:
- if n != 0:
- classes.write(", ");
- classes.write("%s" % arg[0])
- if classes_type.has_key(arg[1]):
- classes.write("__o");
- if libxml2_classes_type.has_key(arg[1]):
- classes.write("__o");
- n = n + 1
- classes.write(")\n");
- if ret[0] != "void":
- if classes_type.has_key(ret[0]):
- classes.write(" if ret == None: return None\n");
- classes.write(" return ");
- classes.write(classes_type[ret[0]][1] % ("ret"));
- classes.write("\n");
- elif libxml2_classes_type.has_key(ret[0]):
- classes.write(" if ret == None: return None\n");
- classes.write(" return libxml2.");
- classes.write(libxml2_classes_type[ret[0]][1] % ("ret"));
- classes.write("\n");
- else:
- classes.write(" return ret\n");
- classes.write("\n");
-
-txt.write("\n\n#\n# Set of classes of the module\n#\n\n")
-for classname in classes_list:
- if classname == "None":
- pass
- else:
- if classes_ancestor.has_key(classname):
- txt.write("\n\nClass %s(%s)\n" % (classname,
- classes_ancestor[classname]))
- classes.write("class %s(%s):\n" % (classname,
- classes_ancestor[classname]))
- classes.write(" def __init__(self, _obj=None):\n")
- classes.write(" self._o = None\n")
- classes.write(" %s.__init__(self, _obj=_obj)\n\n" % (
- classes_ancestor[classname]))
- if classes_ancestor[classname] == "xmlCore" or \
- classes_ancestor[classname] == "xmlNode":
- classes.write(" def __repr__(self):\n")
- format = "%s:%%s" % (classname)
- classes.write(" return \"%s\" %% (self.name)\n\n" % (
- format))
- else:
- txt.write("Class %s()\n" % (classname))
- classes.write("class %s:\n" % (classname))
- classes.write(" def __init__(self, _obj=None):\n")
- classes.write(" if _obj != None:self._o = _obj;return\n")
- classes.write(" self._o = None\n\n");
- if classes_destructors.has_key(classname):
- classes.write(" def __del__(self):\n")
- if classes_destructors[classname] == "pass":
- classes.write(" pass\n")
- else:
- classes.write(" if self._o != None:\n")
- classes.write(" libxsltmod.%s(self._o)\n" %
- classes_destructors[classname]);
- classes.write(" self._o = None\n\n");
- flist = function_classes[classname]
- flist.sort(functionCompare)
- oldfile = ""
- for info in flist:
- (index, func, name, ret, args, file) = info
- if file != oldfile:
- if file == "python_accessor":
- classes.write(" # accessors for %s\n" % (classname))
- txt.write(" # accessors\n")
- else:
- classes.write(" #\n")
- classes.write(" # %s functions from module %s\n" % (
- classname, file))
- txt.write("\n # functions from module %s\n" % file)
- classes.write(" #\n\n")
- oldfile = file
- classes.write(" def %s(self" % func)
- txt.write(" %s()\n" % func);
- n = 0
- for arg in args:
- if n != index:
- classes.write(", %s" % arg[0])
- n = n + 1
- classes.write("):\n")
- writeDoc(name, args, ' ', classes);
- n = 0
- for arg in args:
- if classes_type.has_key(arg[1]):
- if n != index:
- classes.write(" if %s == None: %s__o = None\n" %
- (arg[0], arg[0]))
- classes.write(" else: %s__o = %s%s\n" %
- (arg[0], arg[0], classes_type[arg[1]][0]))
- elif libxml2_classes_type.has_key(arg[1]):
- classes.write(" if %s == None: %s__o = None\n" %
- (arg[0], arg[0]))
- classes.write(" else: %s__o = %s%s\n" %
- (arg[0], arg[0],
- libxml2_classes_type[arg[1]][0]))
- n = n + 1
- if ret[0] != "void":
- classes.write(" ret = ");
- else:
- classes.write(" ");
- classes.write("libxsltmod.%s(" % name)
- n = 0
- for arg in args:
- if n != 0:
- classes.write(", ");
- if n != index:
- classes.write("%s" % arg[0])
- if classes_type.has_key(arg[1]):
- classes.write("__o");
- elif libxml2_classes_type.has_key(arg[1]):
- classes.write("__o");
- else:
- classes.write("self");
- if classes_type.has_key(arg[1]):
- classes.write(classes_type[arg[1]][0])
- elif libxml2_classes_type.has_key(arg[1]):
- classes.write(libxml2_classes_type[arg[1]][0])
- n = n + 1
- classes.write(")\n");
- if ret[0] != "void":
- if classes_type.has_key(ret[0]):
- classes.write(" if ret == None: return None\n");
- classes.write(" return ");
- classes.write(classes_type[ret[0]][1] % ("ret"));
- classes.write("\n");
- elif libxml2_classes_type.has_key(ret[0]):
- classes.write(" if ret == None: return None\n");
- classes.write(" return libxml2.");
- classes.write(libxml2_classes_type[ret[0]][1] % ("ret"));
- classes.write("\n");
- elif converter_type.has_key(ret[0]):
- classes.write(" if ret == None: return None\n");
- classes.write(" return ");
- classes.write(converter_type[ret[0]] % ("ret"));
- classes.write("\n");
- else:
- classes.write(" return ret\n");
- classes.write("\n");
-
-txt.close()
-classes.close()
+def buildWrappers():
+ global ctypes
+ global py_types
+ global py_return_types
+ global unknown_types
+ global functions
+ global function_classes
+ global libxml2_classes_type
+ global classes_type
+ global classes_list
+ global converter_type
+ global primary_classes
+ global converter_type
+ global classes_ancestor
+ global converter_type
+ global primary_classes
+ global classes_ancestor
+ global classes_destructors
+
+ function_classes["None"] = []
+ for type in classes_type.keys():
+ function_classes[classes_type[type][2]] = []
+
+ #
+ # Build the list of C types to look for ordered to start with
+ # primary classes
+ #
+ ctypes_processed = {}
+ classes_processed = {}
+ for classe in primary_classes:
+ classes_list.append(classe)
+ classes_processed[classe] = ()
+ for type in classes_type.keys():
+ tinfo = classes_type[type]
+ if tinfo[2] == classe:
+ ctypes.append(type)
+ ctypes_processed[type] = ()
+ for type in classes_type.keys():
+ if ctypes_processed.has_key(type):
+ continue
+ tinfo = classes_type[type]
+ if not classes_processed.has_key(tinfo[2]):
+ classes_list.append(tinfo[2])
+ classes_processed[tinfo[2]] = ()
+
+ ctypes.append(type)
+ ctypes_processed[type] = ()
+
+ for name in functions.keys():
+ found = 0;
+ (desc, ret, args, file) = functions[name]
+ for type in ctypes:
+ classe = classes_type[type][2]
+
+ if name[0:4] == "xslt" and len(args) >= 1 and args[0][1] == type:
+ found = 1
+ func = nameFixup(name, classe, type, file)
+ info = (0, func, name, ret, args, file)
+ function_classes[classe].append(info)
+ elif name[0:4] == "xslt" and len(args) >= 2 and args[1][1] == type:
+ found = 1
+ func = nameFixup(name, classe, type, file)
+ info = (1, func, name, ret, args, file)
+ function_classes[classe].append(info)
+ elif name[0:4] == "xslt" and len(args) >= 3 and args[2][1] == type:
+ found = 1
+ func = nameFixup(name, classe, type, file)
+ info = (2, func, name, ret, args, file)
+ function_classes[classe].append(info)
+ if found == 1:
+ break
+ if found == 1:
+ continue
+ if name[0:8] == "xmlXPath":
+ continue
+ if name[0:6] == "xmlStr":
+ continue
+ if name[0:10] == "xmlCharStr":
+ continue
+ func = nameFixup(name, "None", file, file)
+ info = (0, func, name, ret, args, file)
+ function_classes['None'].append(info)
+
+ classes = open("libxsltclass.py", "w")
+ txt = open("libxsltclass.txt", "w")
+ txt.write(" Generated Classes for libxslt-python\n\n")
+
+ txt.write("#\n# Global functions of the module\n#\n\n")
+ if function_classes.has_key("None"):
+ flist = function_classes["None"]
+ flist.sort(functionCompare)
+ oldfile = ""
+ for info in flist:
+ (index, func, name, ret, args, file) = info
+ if file != oldfile:
+ classes.write("#\n# Functions from module %s\n#\n\n" % file)
+ txt.write("\n# functions from module %s\n" % file)
+ oldfile = file
+ classes.write("def %s(" % func)
+ txt.write("%s()\n" % func);
+ n = 0
+ for arg in args:
+ if n != 0:
+ classes.write(", ")
+ classes.write("%s" % arg[0])
+ n = n + 1
+ classes.write("):\n")
+ writeDoc(name, args, ' ', classes);
+
+ for arg in args:
+ if classes_type.has_key(arg[1]):
+ classes.write(" if %s == None: %s__o = None\n" %
+ (arg[0], arg[0]))
+ classes.write(" else: %s__o = %s%s\n" %
+ (arg[0], arg[0], classes_type[arg[1]][0]))
+ elif libxml2_classes_type.has_key(arg[1]):
+ classes.write(" if %s == None: %s__o = None\n" %
+ (arg[0], arg[0]))
+ classes.write(" else: %s__o = %s%s\n" %
+ (arg[0], arg[0], libxml2_classes_type[arg[1]][0]))
+ if ret[0] != "void":
+ classes.write(" ret = ");
+ else:
+ classes.write(" ");
+ classes.write("libxsltmod.%s(" % name)
+ n = 0
+ for arg in args:
+ if n != 0:
+ classes.write(", ");
+ classes.write("%s" % arg[0])
+ if classes_type.has_key(arg[1]):
+ classes.write("__o");
+ if libxml2_classes_type.has_key(arg[1]):
+ classes.write("__o");
+ n = n + 1
+ classes.write(")\n");
+ if ret[0] != "void":
+ if classes_type.has_key(ret[0]):
+ classes.write(" if ret == None: return None\n");
+ classes.write(" return ");
+ classes.write(classes_type[ret[0]][1] % ("ret"));
+ classes.write("\n");
+ elif libxml2_classes_type.has_key(ret[0]):
+ classes.write(" if ret == None: return None\n");
+ classes.write(" return libxml2.");
+ classes.write(libxml2_classes_type[ret[0]][1] % ("ret"));
+ classes.write("\n");
+ else:
+ classes.write(" return ret\n");
+ classes.write("\n");
+
+ txt.write("\n\n#\n# Set of classes of the module\n#\n\n")
+ for classname in classes_list:
+ if classname == "None":
+ pass
+ else:
+ if classes_ancestor.has_key(classname):
+ txt.write("\n\nClass %s(%s)\n" % (classname,
+ classes_ancestor[classname]))
+ classes.write("class %s(%s):\n" % (classname,
+ classes_ancestor[classname]))
+ classes.write(" def __init__(self, _obj=None):\n")
+ classes.write(" self._o = None\n")
+ classes.write(" %s.__init__(self, _obj=_obj)\n\n" % (
+ classes_ancestor[classname]))
+ if classes_ancestor[classname] == "xmlCore" or \
+ classes_ancestor[classname] == "xmlNode":
+ classes.write(" def __repr__(self):\n")
+ format = "%s:%%s" % (classname)
+ classes.write(" return \"%s\" %% (self.name)\n\n" % (
+ format))
+ else:
+ txt.write("Class %s()\n" % (classname))
+ classes.write("class %s:\n" % (classname))
+ classes.write(" def __init__(self, _obj=None):\n")
+ classes.write(" if _obj != None:self._o = _obj;return\n")
+ classes.write(" self._o = None\n\n");
+ if classes_destructors.has_key(classname):
+ classes.write(" def __del__(self):\n")
+ if classes_destructors[classname] == "pass":
+ classes.write(" pass\n")
+ else:
+ classes.write(" if self._o != None:\n")
+ classes.write(" libxsltmod.%s(self._o)\n" %
+ classes_destructors[classname]);
+ classes.write(" self._o = None\n\n");
+ flist = function_classes[classname]
+ flist.sort(functionCompare)
+ oldfile = ""
+ for info in flist:
+ (index, func, name, ret, args, file) = info
+ if file != oldfile:
+ if file == "python_accessor":
+ classes.write(" # accessors for %s\n" % (classname))
+ txt.write(" # accessors\n")
+ else:
+ classes.write(" #\n")
+ classes.write(" # %s functions from module %s\n" % (
+ classname, file))
+ txt.write("\n # functions from module %s\n" % file)
+ classes.write(" #\n\n")
+ oldfile = file
+ classes.write(" def %s(self" % func)
+ txt.write(" %s()\n" % func);
+ n = 0
+ for arg in args:
+ if n != index:
+ classes.write(", %s" % arg[0])
+ n = n + 1
+ classes.write("):\n")
+ writeDoc(name, args, ' ', classes);
+ n = 0
+ for arg in args:
+ if classes_type.has_key(arg[1]):
+ if n != index:
+ classes.write(" if %s == None: %s__o = None\n" %
+ (arg[0], arg[0]))
+ classes.write(" else: %s__o = %s%s\n" %
+ (arg[0], arg[0], classes_type[arg[1]][0]))
+ elif libxml2_classes_type.has_key(arg[1]):
+ classes.write(" if %s == None: %s__o = None\n" %
+ (arg[0], arg[0]))
+ classes.write(" else: %s__o = %s%s\n" %
+ (arg[0], arg[0],
+ libxml2_classes_type[arg[1]][0]))
+ n = n + 1
+ if ret[0] != "void":
+ classes.write(" ret = ");
+ else:
+ classes.write(" ");
+ classes.write("libxsltmod.%s(" % name)
+ n = 0
+ for arg in args:
+ if n != 0:
+ classes.write(", ");
+ if n != index:
+ classes.write("%s" % arg[0])
+ if classes_type.has_key(arg[1]):
+ classes.write("__o");
+ elif libxml2_classes_type.has_key(arg[1]):
+ classes.write("__o");
+ else:
+ classes.write("self");
+ if classes_type.has_key(arg[1]):
+ classes.write(classes_type[arg[1]][0])
+ elif libxml2_classes_type.has_key(arg[1]):
+ classes.write(libxml2_classes_type[arg[1]][0])
+ n = n + 1
+ classes.write(")\n");
+ if ret[0] != "void":
+ if classes_type.has_key(ret[0]):
+ classes.write(" if ret == None: return None\n");
+ classes.write(" return ");
+ classes.write(classes_type[ret[0]][1] % ("ret"));
+ classes.write("\n");
+ elif libxml2_classes_type.has_key(ret[0]):
+ classes.write(" if ret == None: return None\n");
+ classes.write(" return libxml2.");
+ classes.write(libxml2_classes_type[ret[0]][1] % ("ret"));
+ classes.write("\n");
+ elif converter_type.has_key(ret[0]):
+ classes.write(" if ret == None: return None\n");
+ classes.write(" return ");
+ classes.write(converter_type[ret[0]] % ("ret"));
+ classes.write("\n");
+ else:
+ classes.write(" return ret\n");
+ classes.write("\n");
+
+ txt.close()
+ classes.close()
+
+buildStubs()
+buildWrappers()
diff --git a/python/libxsl.py b/python/libxsl.py
index d482af3f..125630b6 100644
--- a/python/libxsl.py
+++ b/python/libxsl.py
@@ -1,6 +1,48 @@
-import libxml2mod
-import libxsltmod
-import libxml2
+#
+# Both libxml2mod and libxsltmod have a dependancy on libxml2.so
+# and they should share the same module, try to convince the python
+# loader to work in that mode if feasible
+#
+import sys
+try:
+ from dl import RTLD_GLOBAL, RTLD_NOW
+except ImportError:
+ RTLD_GLOBAL = -1
+ RTLD_NOW = -1
+ try:
+ import os
+ osname = os.uname()[0]
+ if osname == 'Linux':
+ RTLD_GLOBAL = 0x00100
+ RTLD_NOW = 0x00002
+ #
+ # is there a better method ?
+ #
+ else:
+ print "libxslt could not guess RTLD_GLOBAL and RTLD_NOW " + \
+ "on this platform: %s" % (osname)
+ except:
+ print "libxslt could not guess RTLD_GLOBAL and RTLD_NOW " + \
+ "on this platform: %s" % (osname)
+
+if RTLD_GLOBAL != -1 and RTLD_NOW != -1:
+ try:
+ flags = sys.getdlopenflags()
+ sys.setdlopenflags(RTLD_GLOBAL | RTLD_NOW)
+ try:
+ import libxml2mod
+ import libxsltmod
+ import libxml2
+ finally:
+ sys.setdlopenflags(flags)
+ except:
+ import libxml2mod
+ import libxsltmod
+ import libxml2
+else:
+ import libxml2mod
+ import libxsltmod
+ import libxml2
#
# Everything below this point is automatically generated
diff --git a/python/libxslt.c b/python/libxslt.c
index 4ede77c0..4f75a934 100644
--- a/python/libxslt.c
+++ b/python/libxslt.c
@@ -4,6 +4,9 @@
* entry points where an automatically generated stub is either
* unpractical or would not match cleanly the Python model.
*
+ * If compiled with MERGED_MODULES, the entry point will be used to
+ * initialize both the libxml2 and the libxslt wrappers
+ *
* See Copyright for the status of this software.
*
* daniel@veillard.com
@@ -352,8 +355,17 @@ static PyMethodDef libxsltMethods[] = {
{ NULL }
};
+#ifdef MERGED_MODULES
+extern void initlibxml2mod(void);
+#endif
+
void initlibxsltmod(void) {
PyObject *m;
+
+#ifdef MERGED_MODULES
+ initlibxml2mod();
+#endif
+
m = Py_InitModule("libxsltmod", libxsltMethods);
/* libxslt_xmlErrorInitialize(); */
/*
@@ -365,5 +377,7 @@ void initlibxsltmod(void) {
xmlLoadExtDtdDefaultValue = XML_DETECT_IDS | XML_COMPLETE_ATTRS;
/* xmlDefaultSAXHandlerInit(); */
xmlDefaultSAXHandler.cdataBlock = NULL;
+
}
+