8000 bpo-1635741: Port gc module to multiphase initialization by tiran · Pull Request #23377 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-1635741: Port gc module to multiphase initialization #2 8000 3377

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 3 commits into from
Nov 19, 2020
Merged
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
Create gc callbacks in _PyGC_init()
  • Loading branch information
tiran committed Nov 19, 2020
commit 7ad98d9bbb48ce1a0bcdd6c39f457bbcf958d46c
31 changes: 14 additions & 17 deletions Modules/gcmodule.c
536C
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,17 @@ PyStatus
_PyGC_Init(PyThreadState *tstate)
{
GCState *gcstate = &tstate->interp->gc;

gcstate->garbage = PyList_New(0);
if (gcstate->garbage == NULL) {
gcstate->garbage = PyList_New(0);
if (gcstate->garbage == NULL) {
return _PyStatus_NO_MEMORY();
}
return _PyStatus_NO_MEMORY();
}

gcstate->callbacks = PyList_New(0);
if (gcstate->callbacks == NULL) {
return _PyStatus_NO_MEMORY();
}

return _PyStatus_OK();
}

Expand Down Expand Up @@ -1997,21 +2002,13 @@ gcmodule_exec(PyObject *module)
{
GCState *gcstate = get_gc_state();

/* Initialized by _PyGC_Init() early in interpreter lifecycle */
if (gcstate->garbage == NULL) {
PyErr_SetString(PyExc_SystemError,
"GC garbage bin is not initialized");
return -1;
}
/* garbage and callbacks are initialized by _PyGC_Init() early in
* interpreter lifecycle. */
assert(gcstate->garbage != NULL);
if (PyModule_AddObjectRef(module, "garbage", gcstate->garbage) < 0) {
return -1;
}

assert(gcstate->callbacks == NULL);
gcstate->callbacks = PyList_New(0);
if (gcstate->callbacks == NULL) {
return -1;
}
assert(gcstate->callbacks != NULL);
if (PyModule_AddObjectRef(module, "callbacks", gcstate->callbacks) < 0) {
return -1;
}
Expand All @@ -2035,7 +2032,7 @@ static struct PyModuleDef gcmodule = {
PyModuleDef_HEAD_INIT,
.m_name = "gc",
.m_doc = gc__doc__,
.m_size = 0, /* special case, state is part of interpreter state */
.m_size = 0, // per interpreter state, see: get_gc_state()
.m_methods = GcMethods,
.m_slots = gcmodule_slots
};
Expand Down
0