#define GEN_HEAD(gcstate, n) (&(gcstate)->generations[n].head)
void
-_PyGC_InitializeRuntime(GCState *gcstate)
+_PyGC_InitState(GCState *gcstate)
{
gcstate->enabled = 1; /* automatic collection enabled? */
PyStatus
_PyGC_Init(PyThreadState *tstate)
{
- GCState *gcstate = &tstate->interp->runtime->gc;
+ GCState *gcstate = &tstate->interp->gc;
if (gcstate->garbage == NULL) {
gcstate->garbage = PyList_New(0);
if (gcstate->garbage == NULL) {
PyGC_Head finalizers; /* objects with, & reachable from, __del__ */
PyGC_Head *gc;
_PyTime_t t1 = 0; /* initialize to prevent a compiler warning */
- GCState *gcstate = &tstate->interp->runtime->gc;
+ GCState *gcstate = &tstate->interp->gc;
if (gcstate->debug & DEBUG_STATS) {
PySys_WriteStderr("gc: collecting generation %d...\n", generation);
assert(!_PyErr_Occurred(tstate));
/* we may get called very early */
- GCState *gcstate = &tstate->interp->runtime->gc;
+ GCState *gcstate = &tstate->interp->gc;
if (gcstate->callbacks == NULL) {
return;
}
static Py_ssize_t
collect_generations(PyThreadState *tstate)
{
- GCState *gcstate = &tstate->interp->runtime->gc;
+ GCState *gcstate = &tstate->interp->gc;
/* Find the oldest generation (highest numbered) where the count
* exceeds the threshold. Objects in the that generation and
* generations younger than it will be collected. */
/*[clinic end generated code: output=45a427e9dce9155c input=81ac4940ca579707]*/
{
PyThreadState *tstate = _PyThreadState_GET();
- GCState *gcstate = &tstate->interp->runtime->gc;
+ GCState *gcstate = &tstate->interp->gc;
gcstate->enabled = 1;
Py_RETURN_NONE;
}
/*[clinic end generated code: output=97d1030f7aa9d279 input=8c2e5a14e800d83b]*/
{
PyThreadState *tstate = _PyThreadState_GET();
- GCState *gcstate = &tstate->interp->runtime->gc;
+ GCState *gcstate = &tstate->interp->gc;
gcstate->enabled = 0;
Py_RETURN_NONE;
}
/*[clinic end generated code: output=1874298331c49130 input=30005e0422373b31]*/
{
PyThreadState *tstate = _PyThreadState_GET();
- GCState *gcstate = &tstate->interp->runtime->gc;
+ GCState *gcstate = &tstate->interp->gc;
return gcstate->enabled;
}
return -1;
}
- GCState *gcstate = &tstate->interp->runtime->gc;
+ GCState *gcstate = &tstate->interp->gc;
Py_ssize_t n;
if (gcstate->collecting) {
/* already collecting, don't do anything */
/*[clinic end generated code: output=7c8366575486b228 input=5e5ce15e84fbed15]*/
{
PyThreadState *tstate = _PyThreadState_GET();
- GCState *gcstate = &tstate->interp->runtime->gc;
+ GCState *gcstate = &tstate->interp->gc;
gcstate->debug = flags;
Py_RETURN_NONE;
}
/*[clinic end generated code: output=91242f3506cd1e50 input=91a101e1c3b98366]*/
{
PyThreadState *tstate = _PyThreadState_GET();
- GCState *gcstate = &tstate->interp->runtime->gc;
+ GCState *gcstate = &tstate->interp->gc;
return gcstate->debug;
}
gc_set_threshold(PyObject *self, PyObject *args)
{
PyThreadState *tstate = _PyThreadState_GET();
- GCState *gcstate = &tstate->interp->runtime->gc;
+ GCState *gcstate = &tstate->interp->gc;
if (!PyArg_ParseTuple(args, "i|ii:set_threshold",
&gcstate->generations[0].threshold,
&gcstate->generations[1].threshold,
/*[clinic end generated code: output=7902bc9f41ecbbd8 input=286d79918034d6e6]*/
{
PyThreadState *tstate = _PyThreadState_GET();
- GCState *gcstate = &tstate->interp->runtime->gc;
+ GCState *gcstate = &tstate->interp->gc;
return Py_BuildValue("(iii)",
gcstate->generations[0].threshold,
gcstate->generations[1].threshold,
/*[clinic end generated code: output=354012e67b16398f input=a392794a08251751]*/
{
PyThreadState *tstate = _PyThreadState_GET();
- GCState *gcstate = &tstate->interp->runtime->gc;
+ GCState *gcstate = &tstate->interp->gc;
return Py_BuildValue("(iii)",
gcstate->generations[0].count,
gcstate->generations[1].count,
return NULL;
}
- GCState *gcstate = &tstate->interp->runtime->gc;
+ GCState *gcstate = &tstate->interp->gc;
for (i = 0; i < NUM_GENERATIONS; i++) {
if (!(gc_referrers_for(args, GEN_HEAD(gcstate, i), result))) {
Py_DECREF(result);
PyThreadState *tstate = _PyThreadState_GET();
int i;
PyObject* result;
- GCState *gcstate = &tstate->interp->runtime->gc;
+ GCState *gcstate = &tstate->interp->gc;
result = PyList_New(0);
if (result == NULL) {
/* To get consistent values despite allocations while constructing
the result list, we use a snapshot of the running stats. */
- GCState *gcstate = &tstate->interp->runtime->gc;
+ GCState *gcstate = &tstate->interp->gc;
for (i = 0; i < NUM_GENERATIONS; i++) {
stats[i] = gcstate->generation_stats[i];
}
/*[clinic end generated code: output=502159d9cdc4c139 input=b602b16ac5febbe5]*/
{
PyThreadState *tstate = _PyThreadState_GET();
- GCState *gcstate = &tstate->interp->runtime->gc;
+ GCState *gcstate = &tstate->interp->gc;
for (int i = 0; i < NUM_GENERATIONS; ++i) {
gc_list_merge(GEN_HEAD(gcstate, i), &gcstate->permanent_generation.head);
gcstate->generations[i].count = 0;
/*[clinic end generated code: output=1c15f2043b25e169 input=2dd52b170f4cef6c]*/
{
PyThreadState *tstate = _PyThreadState_GET();
- GCState *gcstate = &tstate->interp->runtime->gc;
+ GCState *gcstate = &tstate->interp->gc;
gc_list_merge(&gcstate->permanent_generation.head,
GEN_HEAD(gcstate, NUM_GENERATIONS-1));
Py_RETURN_NONE;
/*[clinic end generated code: output=61cbd9f43aa032e1 input=45ffbc65cfe2a6ed]*/
{
PyThreadState *tstate = _PyThreadState_GET();
- GCState *gcstate = &tstate->interp->runtime->gc;
+ GCState *gcstate = &tstate->interp->gc;
return gc_list_size(&gcstate->permanent_generation.head);
}
PyMODINIT_FUNC
PyInit_gc(void)
{
- PyObject *m;
+ PyThreadState *tstate = _PyThreadState_GET();
+ GCState *gcstate = &tstate->interp->gc;
- m = PyModule_Create(&gcmodule);
+ PyObject *m = PyModule_Create(&gcmodule);
if (m == NULL) {
return NULL;
}
- GCState *gcstate = &_PyRuntime.gc;
if (gcstate->garbage == NULL) {
gcstate->garbage = PyList_New(0);
- if (gcstate->garbage == NULL)
+ if (gcstate->garbage == NULL) {
return NULL;
+ }
}
Py_INCREF(gcstate->garbage);
- if (PyModule_AddObject(m, "garbage", gcstate->garbage) < 0)
+ if (PyModule_AddObject(m, "garbage", gcstate->garbage) < 0) {
return NULL;
+ }
if (gcstate->callbacks == NULL) {
gcstate->callbacks = PyList_New(0);
- if (gcstate->callbacks == NULL)
+ if (gcstate->callbacks == NULL) {
return NULL;
+ }
}
Py_INCREF(gcstate->callbacks);
- if (PyModule_AddObject(m, "callbacks", gcstate->callbacks) < 0)
+ if (PyModule_AddObject(m, "callbacks", gcstate->callbacks) < 0) {
return NULL;
+ }
-#define ADD_INT(NAME) if (PyModule_AddIntConstant(m, #NAME, NAME) < 0) return NULL
+#define ADD_INT(NAME) if (PyModule_AddIntConstant(m, #NAME, NAME) < 0) { return NULL; }
ADD_INT(DEBUG_STATS);
ADD_INT(DEBUG_COLLECTABLE);
ADD_INT(DEBUG_UNCOLLECTABLE);
PyGC_Collect(void)
{
PyThreadState *tstate = _PyThreadState_GET();
- GCState *gcstate = &tstate->interp->runtime->gc;
+ GCState *gcstate = &tstate->interp->gc;
if (!gcstate->enabled) {
return 0;
PyThreadState *tstate = _PyThreadState_GET();
assert(!_PyErr_Occurred(tstate));
- GCState *gcstate = &tstate->interp->runtime->gc;
+ GCState *gcstate = &tstate->interp->gc;
Py_ssize_t n;
/* Ideally, this function is only called on interpreter shutdown,
void
_PyGC_DumpShutdownStats(PyThreadState *tstate)
{
- GCState *gcstate = &tstate->interp->runtime->gc;
+ GCState *gcstate = &tstate->interp->gc;
if (!(gcstate->debug & DEBUG_SAVEALL)
&& gcstate->garbage != NULL && PyList_GET_SIZE(gcstate->garbage) > 0) {
const char *message;
void
_PyGC_Fini(PyThreadState *tstate)
{
- GCState *gcstate = &tstate->interp->runtime->gc;
+ GCState *gcstate = &tstate->interp->gc;
Py_CLEAR(gcstate->garbage);
Py_CLEAR(gcstate->callbacks);
}
_PyObject_GC_Alloc(int use_calloc, size_t basicsize)
{
PyThreadState *tstate = _PyThreadState_GET();
- GCState *gcstate = &tstate->interp->runtime->gc;
+ GCState *gcstate = &tstate->interp->gc;
if (basicsize > PY_SSIZE_T_MAX - sizeof(PyGC_Head)) {
return _PyErr_NoMemory(tstate);
}
gc_list_remove(g);
}
PyThreadState *tstate = _PyThreadState_GET();
- GCState *gcstate = &tstate->interp->runtime->gc;
+ GCState *gcstate = &tstate->interp->gc;
if (gcstate->generations[0].count > 0) {
gcstate->generations[0].count--;
}