[pypy-issue] Issue #2482: cpyext: tp_basicsize only considers first base class to determine derived tp_basicsize (pypy/pypy)
issues-reply at bitbucket.org
Thu Feb 23 14:25:41 EST 2017
New issue 2482: cpyext: tp_basicsize only considers first base class to determine derived tp_basicsize
When using multiple inheritance to inherit from both a Python object and an extension object (with a larger `tp_basicsize`) the `tp_basicsize` is the correct (larger) size only if the extension object is inherited first.
For example, if `CBase` is an extension object with `tp_basicsize = 48` and the basic Python object size is 24 (as it seems to be for PyPy on my system) then with this code:
class A(CBase, PyBase):
class B(PyBase, CBase):
a = A()
b = B()
will call `CBase->tp_new` is called for the `A()` constructor, it'll be called with the `PyTypeObject *obj` having `obj->tp_basicsize = 48` (correctly), but for the `B()` constructor it'll have `obj->tp_basicsize = 24`.
Under CPython both get invoked with the correct 48.
I'm fairly sure that the issue is in `module/cpyext/typeobject.py`, in `finish_type_2`: it calls `inherit_special()` to set `tp_basicsize` to the `tp_basicsize` using only `base` (and so never considers inherited classes beyond the first one).
More information about the pypy-issue