-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setting negative tp_dictoffset on PyLong subclass leads to crash #112743
Comments
Has anyone reported this as an actual issue, or is it just a hypothetical problem? >>> Py_TPFLAGS_MANAGED_DICT = 1 << 4
>>> class I(int): pass
>>> I.__flags__ & Py_TPFLAGS_MANAGED_DICT
16 |
We could treat any negative Since you're not supposed to do you own dictionary offset computations, but rely on |
Yes, Thrameos from jpype.
How would that work? Document it in 3.12 What's New?
|
It's documented here https://docs.python.org/3/c-api/typeobj.html#c.Py_TPFLAGS_MANAGED_DICT (the 3.12 docs might need updating) Yes. My guess is that no one did that calculation when accessing the |
@encukou You say in the issue that "nothing to imply it would be different than |
It'd be an issue for any subclassable type whose If so, I guess the way is to:
I can do it if it sound good to you. |
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: