Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 2dec467

Browse files
committed
typeobject: make some method descriptors immortal
This makes method descriptors for non-heap types immortal. The underlying logic is that the types are immortal so the methods will live for the lifetime of the program as well. See #77
1 parent d015495 commit 2dec467

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Objects/typeobject.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4913,6 +4913,13 @@ add_methods(PyTypeObject *type, PyMethodDef *meth)
49134913
if (descr == NULL)
49144914
return -1;
49154915

4916+
if (!PyType_HasFeature(type, Py_TPFLAGS_HEAPTYPE)) {
4917+
// make descriptors immortal if type is immortal
4918+
assert(_PyObject_IS_IMMORTAL((PyObject *)type));
4919+
descr->ob_tid = 0;
4920+
descr->ob_ref_local = _Py_REF_IMMORTAL_MASK;
4921+
}
4922+
49164923
if (isdescr) {
49174924
name = PyDescr_NAME(descr);
49184925
}

0 commit comments

Comments
 (0)