diff options
author | Jack Jansen <jack.jansen@cwi.nl> | 2006-02-07 22:28:09 (GMT) |
---|---|---|
committer | Jack Jansen <jack.jansen@cwi.nl> | 2006-02-07 22:28:09 (GMT) |
commit | 35f82d7051093ffe3ab181a05ed61982560149be (patch) | |
tree | 41363bf405279a1ff19754fbb3ed978be7687dac /Tools | |
parent | e0f85926d676d7284eef9cb06c825ae8d1a54469 (diff) | |
download | cpython-35f82d7051093ffe3ab181a05ed61982560149be.zip cpython-35f82d7051093ffe3ab181a05ed61982560149be.tar.gz cpython-35f82d7051093ffe3ab181a05ed61982560149be.tar.bz2 |
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
Diffstat (limited to 'Tools')
-rw-r--r-- | Tools/bgen/bgen/bgenObjectDefinition.py | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/Tools/bgen/bgen/bgenObjectDefinition.py b/Tools/bgen/bgen/bgenObjectDefinition.py index 1a44ca4..422ebfd 100644 --- a/Tools/bgen/bgen/bgenObjectDefinition.py +++ b/Tools/bgen/bgen/bgenObjectDefinition.py @@ -141,7 +141,7 @@ class ObjectDefinition(GeneratorGroup): OutLbrace() self.outputCleanupStructMembers() if self.basetype: - Output("self->ob_type->tp_base->tp_dealloc((PyObject *)self);") + Output("%s.tp_dealloc((PyObject *)self);", self.basetype) elif hasattr(self, 'output_tp_free'): # This is a new-style object with tp_free slot Output("self->ob_type->tp_free((PyObject *)self);") @@ -382,12 +382,20 @@ class PEP253Mixin(PEP252Mixin): def outputHook_tp_free(self): Output("%s_tp_free, /* tp_free */", self.prefix) + def output_tp_initBody_basecall(self): + if self.basetype: + Output("if (%s.tp_init)", self.basetype) + OutLbrace() + Output("if ( (*%s.tp_init)(_self, _args, _kwds) < 0) return -1;", self.basetype) + OutRbrace() + output_tp_initBody = None def output_tp_init(self): if self.output_tp_initBody: Output("static int %s_tp_init(PyObject *_self, PyObject *_args, PyObject *_kwds)", self.prefix) OutLbrace() + self.output_tp_initBody_basecall() self.output_tp_initBody() OutRbrace() else: @@ -414,7 +422,17 @@ class PEP253Mixin(PEP252Mixin): Output() Output("if (!PyArg_ParseTupleAndKeywords(_args, _kwds, \"O&\", kw, %s_Convert, &itself)) return NULL;", self.prefix); - Output("if ((_self = type->tp_alloc(type, 0)) == NULL) return NULL;") + if self.basetype: + Output("if (%s.tp_new)", self.basetype) + OutLbrace() + Output("if ( (*%s.tp_init)(_self, _args, _kwds) == NULL) return NULL;", self.basetype) + Dedent() + Output("} else {") + Indent() + Output("if ((_self = type->tp_alloc(type, 0)) == NULL) return NULL;") + OutRbrace() + else: + Output("if ((_self = type->tp_alloc(type, 0)) == NULL) return NULL;") Output("((%s *)_self)->ob_itself = itself;", self.objecttype) Output("return _self;") |