Skip to content

Commit 24a455a

Browse files
Initialize each interpreter's refchain properly.
1 parent 6f8b84f commit 24a455a

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

Include/internal/pycore_object.h

+1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ _PyType_HasFeature(PyTypeObject *type, unsigned long feature) {
152152

153153
extern void _PyType_InitCache(PyInterpreterState *interp);
154154

155+
extern void _PyObject_InitState(PyInterpreterState *interp);
155156

156157
/* Inline functions trading binary compatibility for speed:
157158
_PyObject_Init() is the fast version of PyObject_Init(), and

Objects/object.c

+21-1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,14 @@ _PyDebug_PrintTotalRefs(void) {
161161

162162
#define REFCHAIN(interp) &interp->object_state.refchain
163163

164+
static inline void
165+
init_refchain(PyInterpreterState *interp)
166+
{
167+
PyObject *refchain = REFCHAIN(interp);
168+
refchain->_ob_prev = refchain;
169+
refchain->_ob_next = refchain;
170+
}
171+
164172
/* Insert op at the front of the list of all objects. If force is true,
165173
* op is added even if _ob_prev and _ob_next are non-NULL already. If
166174
* force is false amd _ob_prev or _ob_next are non-NULL, do nothing.
@@ -1996,6 +2004,18 @@ PyObject _Py_NotImplementedStruct = {
19962004
&_PyNotImplemented_Type
19972005
};
19982006

2007+
2008+
void
2009+
_PyObject_InitState(PyInterpreterState *interp)
2010+
{
2011+
#ifdef Py_TRACE_REFS
2012+
if (!_Py_IsMainInterpreter(interp)) {
2013+
init_refchain(interp);
2014+
}
2015+
#endif
2016+
}
2017+
2018+
19992019
extern PyTypeObject _Py_GenericAliasIterType;
20002020
extern PyTypeObject _PyMemoryIter_Type;
20012021
extern PyTypeObject _PyLineIterator;
@@ -2303,7 +2323,7 @@ _Py_GetObjects(PyObject *self, PyObject *args)
23032323

23042324
#undef REFCHAIN
23052325

2306-
#endif
2326+
#endif /* Py_TRACE_REFS */
23072327

23082328

23092329
/* Hack to force loading of abstract.o */

Python/pylifecycle.c

+2
Original file line numberDiff line numberDiff line change
@@ -2074,6 +2074,8 @@ new_interpreter(PyThreadState **tstate_p, const PyInterpreterConfig *config)
20742074
}
20752075
has_gil = 1;
20762076

2077+
/* No objects have been created yet. */
2078+
20772079
status = pycore_interp_init(tstate);
20782080
if (_PyStatus_EXCEPTION(status)) {
20792081
goto error;

Python/pystate.c

+1
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,7 @@ init_interpreter(PyInterpreterState *interp,
673673
_obmalloc_pools_INIT(interp->obmalloc.pools);
674674
memcpy(&interp->obmalloc.pools.used, temp, sizeof(temp));
675675
}
676+
_PyObject_InitState(interp);
676677

677678
_PyEval_InitState(interp, pending_lock);
678679
_PyGC_InitState(&interp->gc);

0 commit comments

Comments
 (0)