Skip to content

Commit cd3b739

Browse files
author
jack.jansen
committed
Fixed an oversight and a misunderstanding of PEP253:
- Call tp_dealloc on the static baseclass, not dynamic (which leads to infinite loops with more than one baseclass) - Call tp_new and tp_init on baseclasses (overridable) -This line, and those below, will be ignored-- M bgen/bgenObjectDefinition.py git-svn-id: http://svn.python.org/projects/python/trunk@42261 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 1638b24 commit cd3b739

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

Tools/bgen/bgen/bgenObjectDefinition.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def outputDealloc(self):
141141
OutLbrace()
142142
self.outputCleanupStructMembers()
143143
if self.basetype:
144-
Output("self->ob_type->tp_base->tp_dealloc((PyObject *)self);")
144+
Output("%s.tp_dealloc((PyObject *)self);", self.basetype)
145145
elif hasattr(self, 'output_tp_free'):
146146
# This is a new-style object with tp_free slot
147147
Output("self->ob_type->tp_free((PyObject *)self);")
@@ -382,12 +382,20 @@ def outputHook_tp_new(self):
382382
def outputHook_tp_free(self):
383383
Output("%s_tp_free, /* tp_free */", self.prefix)
384384

385+
def output_tp_initBody_basecall(self):
386+
if self.basetype:
387+
Output("if (%s.tp_init)", self.basetype)
388+
OutLbrace()
389+
Output("if ( (*%s.tp_init)(_self, _args, _kwds) < 0) return -1;", self.basetype)
390+
OutRbrace()
391+
385392
output_tp_initBody = None
386393

387394
def output_tp_init(self):
388395
if self.output_tp_initBody:
389396
Output("static int %s_tp_init(PyObject *_self, PyObject *_args, PyObject *_kwds)", self.prefix)
390397
OutLbrace()
398+
self.output_tp_initBody_basecall()
391399
self.output_tp_initBody()
392400
OutRbrace()
393401
else:
@@ -414,7 +422,17 @@ def output_tp_newBody(self):
414422
Output()
415423
Output("if (!PyArg_ParseTupleAndKeywords(_args, _kwds, \"O&\", kw, %s_Convert, &itself)) return NULL;",
416424
self.prefix);
417-
Output("if ((_self = type->tp_alloc(type, 0)) == NULL) return NULL;")
425+
if self.basetype:
426+
Output("if (%s.tp_new)", self.basetype)
427+
OutLbrace()
428+
Output("if ( (*%s.tp_init)(_self, _args, _kwds) == NULL) return NULL;", self.basetype)
429+
Dedent()
430+
Output("} else {")
431+
Indent()
432+
Output("if ((_self = type->tp_alloc(type, 0)) == NULL) return NULL;")
433+
OutRbrace()
434+
else:
435+
Output("if ((_self = type->tp_alloc(type, 0)) == NULL) return NULL;")
418436
Output("((%s *)_self)->ob_itself = itself;", self.objecttype)
419437
Output("return _self;")
420438

0 commit comments

Comments
 (0)