8000 Fix crash with python 3.11 (#223) · aviramha/ormsgpack@e92ac12 · GitHub
[go: up one dir, main page]

Skip to content

Commit e92ac12

Browse files
committed
Fix crash with python 3.11 (#223)
We borrow a reference to the static exceptions TypeError and ValueError and pass these objects to PyModule_AddObject, which steals a reference. In Python 3.11 and newer, Py_Finalize() deallocates static exceptions python/cpython#30805 This results in a crash on termination, because _PyStaticType_Dealloc indirectly calls _Py_Dealloc on the objects as the reference count drops to zero. The issue does not occur in Python 3.12 and newer because the objects are immortal. Signed-off-by: Emanuele Giaquinta <emanuele.giaquinta@gmail.com>
1 parent a959a36 commit e92ac12

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/typeref.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ pub fn init_typerefs() {
149149
DEFAULT = PyUnicode_InternFromString("default\0".as_ptr() as *const c_char);
150150
EXT_HOOK = PyUnicode_InternFromString("ext_hook\0".as_ptr() as *const c_char);
151151
OPTION = PyUnicode_InternFromString("option\0".as_ptr() as *const c_char);
152+
Py_INCREF(PyExc_TypeError);
152153
MsgpackEncodeError = PyExc_TypeError;
154+
Py_INCREF(PyExc_ValueError);
153155
MsgpackDecodeError = PyExc_ValueError;
154156

155157
HASH_BUILDER.get_or_init(ahash_init);

0 commit comments

Comments
 (0)
0