Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 35.2k
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
d5085db0d88de4d922903c03e6cb621ea3b67daab534c7171c237e79f80befaa0c11e4bc1ebc80dc68a4084519c3744f3275ee5a0162764c82ece1b6a762ed9dbc8dd4a1f7b709121f9c384b05ee5cf2a005b42b48d849e682217c0ff1709895a9441b4302aecd4204c05d01dd441d7b3395bc2ccceffb7700177File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
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)); | ||
Contributor 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. MemberAuthor 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? Contributor 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 MemberAuthor 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, MemberAuthor 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.
Uh oh!There was an error while loading. Please reload this page. | ||
| } 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.
Uh oh!
There was an error while loading. Please reload this page.
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.
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.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.