Skip to content

Commit 79a165d

Browse files
Create slotdefs_cache only for main interpreter
1 parent b0ad875 commit 79a165d

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

Objects/typeobject.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11381,10 +11381,18 @@ update_all_slots(PyTypeObject* type)
1138111381
int
1138211382
_PyType_InitSlotDefsCache(PyInterpreterState *interp)
1138311383
{
11384+
PyObject *cache;
11385+
PyObject *bytes = NULL;
11386+
1138411387
assert (!_Py_INTERP_CACHED_OBJECT(interp, slotdefs_cache));
11388+
PyInterpreterState *main = interp->runtime->interpreters.main;
11389+
if (interp != main) {
11390+
cache = _Py_INTERP_CACHED_OBJECT(main, slotdefs_cache);
11391+
_Py_INTERP_CACHED_OBJECT(interp, slotdefs_cache) = Py_NewRef(cache);
11392+
return 0;
11393+
}
1138511394

11386-
PyObject *bytes = NULL;
11387-
PyObject* cache = PyDict_New();
11395+
cache = PyDict_New();
1138811396
if (!cache) {
1138911397
goto error;
1139011398
}
@@ -11431,7 +11439,7 @@ _PyType_InitSlotDefsCache(PyInterpreterState *interp)
1143111439
Py_CLEAR(bytes);
1143211440
}
1143311441

11434-
Py_XSETREF(_Py_INTERP_CACHED_OBJECT(interp, slotdefs_cache), cache);
11442+
_Py_INTERP_CACHED_OBJECT(interp, slotdefs_cache) = cache;
1143511443
return 0;
1143611444

1143711445
error:

0 commit comments

Comments
 (0)