8000 gh-107630: Initialize Each Interpreter's refchain Properly by ericsnowcurrently · Pull Request #107733 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-107630: Initialize Each Interpreter's refchain Properly #107733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Include/internal/pycore_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ _PyType_HasFeature(PyTypeObject *type, unsigned long feature) {

extern void _PyType_InitCache(PyInterpreterState *interp);

extern void _PyObject_InitState(PyInterpreterState *interp);

/* Inline functions trading binary compatibility for speed:
_PyObject_Init() is the fast version of PyObject_Init(), and
Expand Down
22 changes: 21 additions & 1 deletion Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ _PyDebug_PrintTotalRefs(void) {

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

static inline void
init_refchain(PyInterpreterState *interp)
{
PyObject *refchain = REFCHAIN(interp);
refchain->_ob_prev = refchain;
refchain->_ob_next = refchain;
}

/* Insert op at the front of the list of all objects. If force is true,
* op is added even if _ob_prev and _ob_next are non-NULL already. If
* force is false amd _ob_prev or _ob_next are non-NULL, do nothing.
Expand Down Expand Up @@ -2019,6 +2027,18 @@ PyObject _Py_NotImplementedStruct = {
&_PyNotImplemented_Type
};


void
_PyObject_InitState(PyInterpreterState *interp)
{
#ifdef Py_TRACE_REFS
if (!_Py_IsMainInterpreter(interp)) {
init_refchain(interp);
}
#endif
}


extern PyTypeObject _Py_GenericAliasIterType;
extern PyTypeObject _PyMemoryIter_Type;
extern PyTypeObject _PyLineIterator;
Expand Down Expand Up @@ -2326,7 +2346,7 @@ _Py_GetObjects(PyObject *self, PyObject *args)

#undef REFCHAIN

#endif
#endif /* Py_TRACE_REFS */


/* Hack to force loading of abstract.o */
Expand Down
2 changes: 2 additions & 0 deletions Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -2075,6 +2075,8 @@ new_interpreter(PyThreadState **tstate_p, const PyInterpreterConfig *config)
}
has_gil = 1;

/* No objects have been created yet. */

status = pycore_interp_init(tstate);
if (_PyStatus_EXCEPTION(status)) {
goto error;
Expand Down
1 change: 1 addition & 0 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ init_interpreter(PyInterpreterState *interp,
_obmalloc_pools_INIT(interp->obmalloc.pools);
memcpy(&interp->obmalloc.pools.used, temp, sizeof(temp));
}
_PyObject_InitState(interp);

_PyEval_InitState(interp, pending_lock);
_PyGC_InitState(&interp->gc);
Expand Down
0