-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
GH-115776: Embed the values array into the object, for "normal" Python objects. #116115
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 all commits
d5085db
0d88de4
d922903
c03e6cb
621ea3b
67daab5
34c7171
c237e79
f80befa
a0c11e4
bc1ebc8
0dc68a4
084519c
3744f32
75ee5a0
162764c
82ece1b
6a762ed
9dbc8dd
4a1f7b7
09121f9
c384b05
ee5cf2a
005b42b
48d849e
682217c
0ff1709
895a944
1b4302a
ecd4204
c05d01d
d441d7b
3395bc2
ccceffb
7700177
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -265,9 +265,8 @@ _PyObject_Init(PyObject *op, PyTypeObject *typeobj) | |
{ | ||
assert(op != NULL); | ||
Py_SET_TYPE(op, typeobj); | ||
if (_PyType_HasFeature(typeobj, Py_TPFLAGS_HEAPTYPE)) { | ||
Py_INCREF(typeobj); | ||
} | ||
assert(_PyType_HasFeature(typeobj, Py_TPFLAGS_HEAPTYPE) || _Py_IsImmortal(typeobj)); | ||
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 now hit this assertion in Cython modules. The (static) extension type that we use for generators has
Is this assertion simply wrong, or is there anything I can do to avoid it? The "immortal objects" API doesn't seem to be intended for public use. 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. #19474 sets the reference count to 1 for statically allocated objects unless As a workaround, I'd suggest making these classes immortal and making them immutable if you can.
That does seem to be the case. I don't know why. Want to open an issue for that? 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. Is there a reason why this new assertion exists? The previous 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. All non-heap types are immortal. Requiring that they are declared as such seems reasonable, and is probably necessary for memory safety. I don't think you should need to do so explicitly though, 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. Does #117673 fix the problem for you? |
||
Py_INCREF(typeobj); | ||
_Py_NewReference(op); | ||
} | ||
|
||
|
@@ -611,8 +610,7 @@ extern PyTypeObject* _PyType_CalculateMetaclass(PyTypeObject *, PyObject *); | |
extern PyObject* _PyType_GetDocFromInternalDoc(const char *, const char *); | ||
extern PyObject* _PyType_GetTextSignatureFromInternalDoc(const char *, const char *, int); | ||
|
||
extern int _PyObject_InitializeDict(PyObject *obj); | ||
int _PyObject_InitInlineValues(PyObject *obj, PyTypeObject *tp); | ||
void _PyObject_InitInlineValues(PyObject *obj, PyTypeObject *tp); | ||
extern int _PyObject_StoreInstanceAttribute(PyObject *obj, PyDictValues *values, | ||
PyObject *name, PyObject *value); | ||
PyObject * _PyObject_GetInstanceAttribute(PyObject *obj, PyDictValues *values, | ||
|
@@ -627,46 +625,26 @@ PyObject * _PyObject_GetInstanceAttribute(PyObject *obj, PyDictValues *values, | |
#endif | ||
|
||
typedef union { | ||
PyObject *dict; | ||
/* Use a char* to generate a warning if directly assigning a PyDictValues */ | ||
char *values; | ||
} PyDictOrValues; | ||
PyDictObject *dict; | ||
DinoV marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} PyManagedDictPointer; | ||
|
||
static inline PyDictOrValues * | ||
_PyObject_DictOrValuesPointer(PyObject *obj) | ||
static inline PyManagedDictPointer * | ||
_PyObject_ManagedDictPointer(PyObject *obj) | ||
{ | ||
assert(Py_TYPE(obj)->tp_flags & Py_TPFLAGS_MANAGED_DICT); | ||
return (PyDictOrValues *)((char *)obj + MANAGED_DICT_OFFSET); | ||
} | ||
|
||
static inline int | ||
_PyDictOrValues_IsValues(PyDictOrValues dorv) | ||
{ | ||
return ((uintptr_t)dorv.values) & 1; | ||
return (PyManagedDictPointer *)((char *)obj + MANAGED_DICT_OFFSET); | ||
} | ||
|
||
static inline PyDictValues * | ||
_PyDictOrValues_GetValues(PyDictOrValues dorv) | ||
{ | ||
assert(_PyDictOrValues_IsValues(dorv)); | ||
return (PyDictValues *)(dorv.values + 1); | ||
} | ||
|
||
static inline PyObject * | ||
_PyDictOrValues_GetDict(PyDictOrValues dorv) | ||
_PyObject_InlineValues(PyObject *obj) | ||
{ | ||
assert(!_PyDictOrValues_IsValues(dorv)); | ||
return dorv.dict; | ||
} | ||
|
||
static inline void | ||
_PyDictOrValues_SetValues(PyDictOrValues *ptr, PyDictValues *values) | ||
{ | ||
ptr->values = ((char *)values) - 1; | ||
assert(Py_TYPE(obj)->tp_flags & Py_TPFLAGS_INLINE_VALUES); | ||
assert(Py_TYPE(obj)->tp_flags & Py_TPFLAGS_MANAGED_DICT); | ||
assert(Py_TYPE(obj)->tp_basicsize == sizeof(PyObject)); | ||
return (PyDictValues *)((char *)obj + sizeof(PyObject)); | ||
} | ||
|
||
extern PyObject ** _PyObject_ComputedDictPointer(PyObject *); | ||
extern void _PyObject_FreeInstanceAttributes(PyObject *obj); | ||
extern int _PyObject_IsInstanceDictEmpty(PyObject *); | ||
|
||
// Export for 'math' shared extension | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.