Skip to content

Commit cf690d5

Browse files
asvetlovbdraco
andauthored
Fix custom PyType_GetModuleByDef when non-heap type object was passed (#1147)
Co-authored-by: J. Nick Koston <[email protected]>
1 parent 57c09c0 commit cf690d5

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

CHANGES/1147.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed custom ``PyType_GetModuleByDef()`` when non-heap type object was passed.

multidict/_multilib/state.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ PyObject *
4848
PyType_GetModuleByDef(PyTypeObject *tp, PyModuleDef *def)
4949
{
5050
PyModuleDef * mod_def;
51-
assert(PyType_HasFeature(tp, Py_TPFLAGS_HEAPTYPE));
51+
if (!PyType_HasFeature(tp, Py_TPFLAGS_HEAPTYPE)) {
52+
goto err;
53+
}
5254
PyObject *mod = NULL;
5355

5456
mod = PyType_GetModule(tp);
@@ -84,6 +86,7 @@ PyType_GetModuleByDef(PyTypeObject *tp, PyModuleDef *def)
8486
}
8587
}
8688

89+
err:
8790
PyErr_Format(
8891
PyExc_TypeError,
8992
"PyType_GetModuleByDef: No superclass of '%s' has the given module",

0 commit comments

Comments
 (0)