Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Fix the ABI
  • Loading branch information
vstinner committed Jan 12, 2022
commit 01c415597102f94edc07cee47c99577fed53241e
2 changes: 1 addition & 1 deletion Include/internal/pycore_gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ struct _gc_runtime_state {
Py_ssize_t long_lived_pending;
};

extern void _PyGC_InitializeRuntime(struct _gc_runtime_state *);
extern void _PyGC_InitState(struct _gc_runtime_state *);

extern Py_ssize_t _PyGC_CollectNoFail(PyThreadState *tstate);

Expand Down
4 changes: 4 additions & 0 deletions Include/internal/pycore_interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ extern "C" {
#include "pycore_atomic.h" // _Py_atomic_address
#include "pycore_ast_state.h" // struct ast_state
#include "pycore_gil.h" // struct _gil_runtime_state
#include "pycore_gc.h" // struct _gc_runtime_state
#include "pycore_warnings.h" // struct _warnings_runtime_state

struct _pending_calls {
Expand Down Expand Up @@ -228,6 +229,9 @@ struct _is {
int finalizing;

struct _ceval_state ceval;
// bpo-46070: Even if each PyInterpreterState has a GC state,
// _PyGC_GetState() only uses the state of the main interpreter.
struct _gc_runtime_state gc;

// sys.modules dictionary
PyObject *modules;
Expand Down
14 changes: 12 additions & 2 deletions Include/internal/pycore_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ _PyObject_InitVar(PyVarObject *op, PyTypeObject *typeobj, Py_ssize_t size)
}


static inline struct _gc_runtime_state*
_PyGC_GetState(void)
{
// bpo-46070: Even if each PyInterpreterState has a GC state,
// _PyGC_GetState() only uses the state of the main interpreter.
PyInterpreterState *interp = _PyRuntime.interpreters.main;
return &interp->gc;
}


/* Tell the GC to track this object.
*
* The object must not be tracked by the GC.
Expand Down Expand Up @@ -87,8 +97,8 @@ static inline void _PyObject_GC_TRACK(
"object is in generation which is garbage collected",
filename, lineno, __func__);

_PyRuntimeState *runtime = &_PyRuntime;
PyGC_Head *generation0 = runtime->gc.generation0;
struct _gc_runtime_state *state = _PyGC_GetState();
PyGC_Head *generation0 = state->generation0;
PyGC_Head *last = (PyGC_Head*)(generation0->_gc_prev);
_PyGCHead_SET_NEXT(last, gc);
_PyGCHead_SET_PREV(gc, last);
Expand Down
2 changes: 0 additions & 2 deletions Include/internal/pycore_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ extern "C" {
#endif

#include "pycore_atomic.h" /* _Py_atomic_address */
#include "pycore_gc.h" // struct _gc_runtime_state
#include "pycore_gil.h" // struct _gil_runtime_state

/* ceval state */
Expand Down Expand Up @@ -105,7 +104,6 @@ typedef struct pyruntimestate {
void (*exitfuncs[NEXITFUNCS])(void);
int nexitfuncs;

struct _gc_runtime_state gc;
struct _ceval_runtime_state ceval;
struct _gilstate_runtime_state gilstate;

Expand Down
5 changes: 2 additions & 3 deletions Modules/gcmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,12 @@ gc_decref(PyGC_Head *g)
static GCState *
get_gc_state(void)
{
_PyRuntimeState *runtime = &_PyRuntime;
return &runtime->gc;
return _PyGC_GetState();
}


void
_PyGC_InitializeRuntime(GCState *gcstate)
_PyGC_InitState(GCState *gcstate)
{
gcstate->enabled = 1; /* automatic collection enabled? */

Expand Down
6 changes: 2 additions & 4 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -2099,8 +2099,7 @@ Py_ReprLeave(PyObject *obj)
void
_PyTrash_deposit_object(PyObject *op)
{
_PyRuntimeState *runtime = &_PyRuntime;
struct _gc_runtime_state *gcstate = &runtime->gc;
struct _gc_runtime_state *gcstate = _PyGC_GetState();

_PyObject_ASSERT(op, _PyObject_IS_GC(op));
_PyObject_ASSERT(op, !_PyObject_GC_IS_TRACKED(op));
Expand All @@ -2127,8 +2126,7 @@ _PyTrash_thread_deposit_object(PyObject *op)
void
_PyTrash_destroy_chain(void)
{
_PyRuntimeState *runtime = &_PyRuntime;
struct _gc_runtime_state *gcstate = &runtime->gc;
struct _gc_runtime_state *gcstate = _PyGC_GetState();

while (gcstate->trash_delete_later) {
PyObject *op = gcstate->trash_delete_later;
Expand Down
2 changes: 1 addition & 1 deletion Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ _PyRuntimeState_Init_impl(_PyRuntimeState *runtime)
runtime->audit_hook_head = audit_hook_head;

_PyEval_InitRuntimeState(&runtime->ceval);
_PyGC_InitializeRuntime(&runtime->gc);

PyPreConfig_InitPythonConfig(&runtime->preconfig);

Expand Down Expand Up @@ -229,6 +228,7 @@ PyInterpreterState_New(void)
goto out_of_memory;
}

_PyGC_InitState(&interp->gc);
PyConfig_InitPythonConfig(&interp->config);
_PyType_InitCache(interp);

Expand Down
6 changes: 3 additions & 3 deletions Python/traceback.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "code.h"
#include "pycore_interp.h" // PyInterpreterState.gc
#include "pycore_runtime.h" // _PyRuntime
#include "pycore_object.h" // _PyGC_GetState()
#include "frameobject.h" // PyFrame_GetBack()
#include "structmember.h" // PyMemberDef
#include "osdefs.h" // SEP
Expand Down Expand Up @@ -926,7 +926,7 @@ _Py_DumpTracebackThreads(int fd, PyInterpreterState *interp,
return "unable to get the thread head state";

/* Dump the traceback of each thread */
_PyRuntimeState *runtime = &_PyRuntime;
struct _gc_runtime_state *gcstate = _PyGC_GetState();
tstate = PyInterpreterState_ThreadHead(interp);
nthreads = 0;
_Py_BEGIN_SUPPRESS_IPH
Expand All @@ -939,7 +939,7 @@ _Py_DumpTracebackThreads(int fd, PyInterpreterState *interp,
break;
}
write_thread_id(fd, tstate, tstate == current_tstate);
if (tstate == current_tstate && runtime->gc.collecting) {
if (tstate == current_tstate && gcstate->collecting) {
PUTS(fd, " Garbage-collecting\n");
}
dump_traceback(fd, tstate, 0);
Expand Down