-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
[WIP, DO NOT MERGE] bpo-41188: Prepare CPython for opague PyObject structure. #21262
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
Changes from 1 commit
3d5826b
ff05339
8aa000e
8774b02
da3b98a
686d657
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -263,8 +263,10 @@ struct _typeobject { | |
|
|
||
| destructor tp_finalize; | ||
| vectorcallfunc tp_vectorcall; | ||
|
|
||
| /* INTERNAL USE ONLY! MODIFYING THIS CAN CRASH PYTHON! */ | ||
| const Py_ssize_t tp_obj_offset; | ||
| const Py_ssize_t tp_obj_offset; /* Offset from "PyObject *" pointer */ | ||
| const Py_ssize_t tp_obj_size; /* Total memory allocation size */ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see the point of adding a new member. You can just check for Py_TPFLAGS_USES_OPAQUE_OBJECT flag in functions like PyType_GenericAlloc(), _PyObject_SIZE() and _PyObject_VAR_SIZE(). If the flag is set, add sizeof(PyObject).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See previous comment. |
||
| }; | ||
|
|
||
| /* The *real* layout of a type object when allocated on the heap */ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that this is needed. When I get a "PyObject *ob", the offset to the PyObject structure is 0: "PyObject copy = *ob;" in Python internals is valid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not required if everything inherited ONLY PyObject, that will never be true.
The offset is calculated from the immediate base type of the type, which can be for example: list, tuple, dict, type, custom types.
Same thing applies to "tp_obj_size", without these members, heap corruption can be very likely.