You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A negative offset is more expensive to use, and should only be used when the instance structure contains a variable-length part. This is used for example to add an instance variable dictionary to subtypes of str or tuple.
That is, while int is not given as an explicit example, but there's nothing to imply it would be different than str or tuple.
Indeed, it works on Python 3.11, but fails in 3.12 when accessing the __dict__, as Python calls _PyObject_ComputedDictPointer, which tries to compute the dict offset using abs(ob_size), which is invalid for int on 3.12.
I'm not the best person to judge whether this is a bad bug, acceptable backwards-incompatible change, or perhaps it's a misuse of 3.11 API (but I can't see exactly how it's misused).
The use of tp_dictoffset and tp_weaklistoffset is still supported, but does not fully support multiple inheritance (gh-95589), and performance may be worse.
Compiling is tricky with distutils gone, but on Fedora a command to compile & run is: gcc $(python3.12-config --cflags --ldflags) -fPIC --shared extmodule.c -o ext.so && python3.12d -Xdev repro.py
Crashes on 3.12, works on 3.11 or with basetype = &PyUnicode_Type.
CPython versions tested on:
3.11, 3.12
Operating systems tested on:
Linux
The text was updated successfully, but these errors were encountered:
Bug report
Bug description:
In Python 3.12, it is no longer possible to subclass
int
by extendingbasicsize
and setting a negativetp_dictoffset
.The 3.11 docs suggest that this might work:
That is, while
int
is not given as an explicit example, but there's nothing to imply it would be different thanstr
ortuple
.Indeed, it works on Python 3.11, but fails in 3.12 when accessing the
__dict__
, as Python calls_PyObject_ComputedDictPointer
, which tries to compute the dict offset usingabs(ob_size)
, which is invalid forint
on 3.12.I'm not the best person to judge whether this is a bad bug, acceptable backwards-incompatible change, or perhaps it's a misuse of 3.11 API (but I can't see exactly how it's misused).
The 3.12 What's new does mention tp_dictoffset-related breaking changes:
But multiple inheritance is not in play here.
@markshannon, any thoughts?
Reproducer (hope I didn't simplify too much):
extmodule.c
:repro.py
:Compiling is tricky with
distutils
gone, but on Fedora a command to compile & run is:gcc $(python3.12-config --cflags --ldflags) -fPIC --shared extmodule.c -o ext.so && python3.12d -Xdev repro.py
Crashes on 3.12, works on 3.11 or with
basetype = &PyUnicode_Type
.CPython versions tested on:
3.11, 3.12
Operating systems tested on:
Linux
The text was updated successfully, but these errors were encountered: