mirror of
https://github.com/GNOME/libxml2.git
synced 2025-03-31 19:10:28 +08:00
modified the generator to allow keeping class references when creating new
* python/generator.py: modified the generator to allow keeping class references when creating new classes, needed to fix a bug pointed by Stphane Bidoul where the input buffer of the xmlTextReader instance gets destroyed if the python wrapper for the input is not referenced anymore. Daniel
This commit is contained in:
parent
4d8db8a22c
commit
dc85f28f66
@ -1,3 +1,11 @@
|
||||
Tue Dec 31 12:15:37 CET 2002 Daniel Veillard <daniel@veillard.com>
|
||||
|
||||
* python/generator.py: modified the generator to allow keeping
|
||||
class references when creating new classes, needed to fix a bug
|
||||
pointed by Stéphane Bidoul where the input buffer of the
|
||||
xmlTextReader instance gets destroyed if the python wrapper for
|
||||
the input is not referenced anymore.
|
||||
|
||||
Mon Dec 30 19:39:36 CET 2002 Daniel Veillard <daniel@veillard.com>
|
||||
|
||||
* xmlreader.c python/tests/reader.py: fixed another pair of problem
|
||||
|
@ -634,6 +634,10 @@ functions_noexcept = {
|
||||
"xmlHasNsProp": 1,
|
||||
}
|
||||
|
||||
reference_keepers = {
|
||||
"xmlTextReader": [('inputBuffer', 'input')],
|
||||
}
|
||||
|
||||
function_classes = {}
|
||||
|
||||
function_classes["None"] = []
|
||||
@ -931,6 +935,10 @@ def buildWrappers():
|
||||
classes.write("class %s(%s):\n" % (classname,
|
||||
classes_ancestor[classname]))
|
||||
classes.write(" def __init__(self, _obj=None):\n")
|
||||
if reference_keepers.has_key(classname):
|
||||
rlist = reference_keepers[classname]
|
||||
for ref in rlist:
|
||||
classes.write(" self.%s = None\n" % ref[1])
|
||||
classes.write(" self._o = None\n")
|
||||
classes.write(" %s.__init__(self, _obj=_obj)\n\n" % (
|
||||
classes_ancestor[classname]))
|
||||
@ -944,6 +952,10 @@ def buildWrappers():
|
||||
txt.write("Class %s()\n" % (classname))
|
||||
classes.write("class %s:\n" % (classname))
|
||||
classes.write(" def __init__(self, _obj=None):\n")
|
||||
if reference_keepers.has_key(classname):
|
||||
list = reference_keepers[classname]
|
||||
for ref in list:
|
||||
classes.write(" self.%s = None\n" % ref[1])
|
||||
classes.write(" if _obj != None:self._o = _obj;return\n")
|
||||
classes.write(" self._o = None\n\n");
|
||||
if classes_destructors.has_key(classname):
|
||||
@ -1029,9 +1041,30 @@ def buildWrappers():
|
||||
classes.write(
|
||||
" if ret is None:raise treeError('%s() failed')\n"
|
||||
% (name))
|
||||
classes.write(" return ");
|
||||
|
||||
#
|
||||
# generate the returned class wrapper for the object
|
||||
#
|
||||
classes.write(" __tmp = ");
|
||||
classes.write(classes_type[ret[0]][1] % ("ret"));
|
||||
classes.write("\n");
|
||||
|
||||
#
|
||||
# Sometime one need to keep references of the source
|
||||
# class in the returned class object.
|
||||
# See reference_keepers for the list
|
||||
#
|
||||
tclass = classes_type[ret[0]][2]
|
||||
if reference_keepers.has_key(tclass):
|
||||
list = reference_keepers[tclass]
|
||||
for pref in list:
|
||||
if pref[0] == ref[0]:
|
||||
classes.write(" __tmp.%s = self\n" %
|
||||
pref[1])
|
||||
#
|
||||
# return the class
|
||||
#
|
||||
classes.write(" return __tmp\n");
|
||||
elif converter_type.has_key(ret[0]):
|
||||
#
|
||||
# Raise an exception
|
||||
|
Loading…
x
Reference in New Issue
Block a user