@@ -309,7 +309,6 @@ type_cache_clear(struct type_cache *cache, PyObject *value)
309
309
void
310
310
_PyType_InitCache (PyInterpreterState * interp )
311
311
{
312
- int is_main = _Py_IsMainInterpreter (interp );
313
312
struct type_cache * cache = & interp -> types .type_cache ;
314
313
for (Py_ssize_t i = 0 ; i < (1 << MCACHE_SIZE_EXP ); i ++ ) {
315
314
struct type_cache_entry * entry = & cache -> hashtable [i ];
@@ -318,21 +317,21 @@ _PyType_InitCache(PyInterpreterState *interp)
318
317
entry -> version = 0 ;
319
318
// Set to None so _PyType_Lookup() can use Py_SETREF(),
320
319
// rather than using slower Py_XSETREF().
320
+ // (See _PyType_FixCacheRefcounts() about the refcount.)
321
321
entry -> name = Py_None ;
322
- // Currently, this happens before the GIL has been created,
323
- // which is a problem without "immortality" (PEP 683).
324
- // Until we have immortal objects, we must avoid an INCREF
325
- // in the main interpreter here. Instead, we fix the refcount
326
- // in the main interpreer as soon as the GIL has been created.
327
- // (See pycore_create_interpreter() in pylifecycle.c.)
328
- if (!is_main ) {
329
- Py_INCREF (Py_None );
330
- }
331
322
entry -> value = NULL ;
332
323
}
333
324
}
334
325
335
- // This is the temporary fix used by pycore_create_interpreter().
326
+ // This is the temporary fix used by pycore_create_interpreter(),
327
+ // in pylifecycle.c. _PyType_InitCache() is called before the GIL
328
+ // has been created (for the main interpreter) and without the
329
+ // "current" thread state set. This causes crashes when the
330
+ // reftotal is updated, so we don't modify the refcount in
331
+ // _PyType_InitCache(), and instead do it later by calling
332
+ // _PyType_FixCacheRefcounts().
333
+ // XXX This workaround should be removed once we have immortal
334
+ // objects (PEP 683).
336
335
void
337
336
_PyType_FixCacheRefcounts (void )
338
337
{
0 commit comments