tp_itemsize == 1 for str in PyPy3
It looks like str
on PyPy3 is reporting tp_itemsize == 1
. In CPython tp_itemsize == 0
This makes it a variable length object and so difficult to inherit from in the C API (because you need to leave an unknown size for the base class).
Looking at the definition in cpyext_unicodeobject.h
it doesn't look like you define it as a variable length object (i.e. it's defined with pointers rather than with an final array member). However, I guess it's possible that PyPy allocates the object and the storage in one block and directs the pointers to the storage
If you do intend to set tp_itemsize
to 1 then you're missing an ob_size
field (https://docs.python.org/3/c-api/typeobj.html#c.PyTypeObject.tp_itemsize). I guess this'd be a case of making length
and ob_size
a union?
For a type with variable-length instances, the instances must have an
ob_size
field.
I'm running into this issue when trying to add some checks on Cython for inheritance from variable length types. https://github.com/cython/cython/runs/7161476068?check_suite_focus=true. It'd just prevent Cython cdef classes from inheriting from str/unicode
on PyPy3, which probably isn't a huge incompatibility.