gh-90868: Add _PyStaticObject_CheckRefcnt() function (#99261)

Add _PyStaticObject_CheckRefcnt() function to make
_PyStaticObjects_CheckRefcnt() shorter. Use
_PyObject_ASSERT_FAILED_MSG() to log the object causing the fatal
error.
This commit is contained in:
Victor Stinner 2022-11-09 08:40:40 +01:00 committed by GitHub
parent f7a82cde59
commit 0124b5dd28
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 1458 additions and 5782 deletions

View file

@ -388,11 +388,8 @@ def generate_global_object_finalizers(immortal_objects):
printer.write("static inline void")
with printer.block("_PyStaticObjects_CheckRefcnt(void)"):
for i in immortal_objects:
with printer.block(f'if (Py_REFCNT({i}) < _PyObject_IMMORTAL_REFCNT)', ';'):
printer.write(f'_PyObject_Dump({i});')
printer.write(f'Py_FatalError("immortal object has less refcnt than '
'expected _PyObject_IMMORTAL_REFCNT");')
printer.write('#endif')
printer.write(f'_PyStaticObject_CheckRefcnt({i});')
printer.write('#endif // Py_DEBUG')
printer.write(END)
printer.write(after)