| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -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)); | ||
|
Comment thread
Copy link
Copy Markdown
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI now hit this assertion in Cython modules. The (static) extension type that we use for generators has tp_alloc = PyType_GenericAlloc and calls it in tp_new(): #6 0x00007ffff7cc2e96 in __GI___assert_fail (assertion=assertion@entry=0x5555559db4e0 "_PyType_HasFeature(typeobj, Py_TPFLAGS_HEAPTYPE) || _Py_IsImmortal(typeobj)", file=file@entry=0x5555559db468 "./Include/internal/pycore_object.h", line=line@entry=268, function=function@entry=0x555555a04ad8 <__PRETTY_FUNCTION__.140> "_PyObject_Init") at ./assert/assert.c:101 #7 0x0000555555774e33 in _PyObject_Init (typeobj=0x7ffff6c26d40 <__pyx_type_8buildenv___pyx_scope_struct__genexpr>, op=0x7ffff4f1e210) at ./Include/internal/pycore_object.h:268 #8 0x000055555577cec3 in _PyObject_Init (typeobj=<optimized out>, op=<optimized out>) at ./Include/object.h:430 #9 _PyType_AllocNoTrack (type=type@entry=0x7ffff6c26d40 <__pyx_type_8buildenv___pyx_scope_struct__genexpr>, nitems=0) at Objects/typeobject.c:1908 #10 0x000055555577cf09 in PyType_GenericAlloc (type=0x7ffff6c26d40 <__pyx_type_8buildenv___pyx_scope_struct__genexpr>, nitems=<optimized out>) at Objects/typeobject.c:1922 #11 0x00007ffff6c08100 in __pyx_tp_new_8buildenv___pyx_scope_struct__genexpr (t=<optimized out>, a=<optimized out>, k=k@entry=0x0) at buildenv.c:2954 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.
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Member
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality#19474 sets the reference count to 1 for statically allocated objects unless Py_BUILD_CORE is defined. 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?
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityIs there a reason why this new assertion exists? The previous if condition came from a conservative change that intended to avoid refcounting static types but wanted to make sure (heap) type objects are correctly kept alive as long as their objects. Now the code requires all non-heap types to be declared immortal. That seems a rather heavy change in requirements.
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Member
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityAll 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, PyObject_HEAD_INIT should do it.
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Member
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityDoes #117673 fix the problem for you?
Sorry, something went wrong.
All reactions
|
||
| Py_INCREF(typeobj); | ||
| _Py_NewReference(op); | ||
| } | ||
|
|
||
| Expand Down Expand Up | @@ -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, | ||
| Expand All | @@ -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; | ||
|
Comment thread
DinoV marked this conversation as 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 | ||
| Expand Down | ||
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.
| Back | FazBrowse Home | New Git URL |
Uh oh!
There was an error while loading. Please reload this page.