#include "Python.h"
#include "pycore_context.h"
+#include "pycore_initconfig.h"
#include "pycore_object.h"
#include "pycore_pymem.h"
#include "pycore_pystate.h"
#define GEN_HEAD(state, n) (&(state)->generations[n].head)
void
-_PyGC_Initialize(struct _gc_runtime_state *state)
+_PyGC_InitializeRuntime(struct _gc_runtime_state *state)
{
state->enabled = 1; /* automatic collection enabled? */
state->permanent_generation = permanent_generation;
}
+
+PyStatus
+_PyGC_Init(_PyRuntimeState *runtime)
+{
+ struct _gc_runtime_state *state = &runtime->gc;
+ if (state->garbage == NULL) {
+ state->garbage = PyList_New(0);
+ if (state->garbage == NULL) {
+ return _PyStatus_NO_MEMORY();
+ }
+ }
+ return _PyStatus_OK();
+}
+
+
/*
_gc_prev values
---------------
PyGC_Head *finalizers, PyGC_Head *old)
{
assert(!PyErr_Occurred());
+ assert(state->garbage != NULL);
PyGC_Head *gc = GC_NEXT(finalizers);
- if (state->garbage == NULL) {
- state->garbage = PyList_New(0);
- if (state->garbage == NULL)
- Py_FatalError("gc couldn't create gc.garbage list");
- }
for (; gc != finalizers; gc = GC_NEXT(gc)) {
PyObject *op = FROM_GC(gc);
static PyStatus
-pycore_init_types(void)
+pycore_init_types(_PyRuntimeState *runtime)
{
- PyStatus status = _PyTypes_Init();
+ PyStatus status;
+
+ status = _PyGC_Init(runtime);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
+ }
+
+ status = _PyTypes_Init();
if (_PyStatus_EXCEPTION(status)) {
return status;
}
config = &tstate->interp->config;
*tstate_p = tstate;
- status = pycore_init_types();
+ status = pycore_init_types(runtime);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
}
config = &interp->config;
- status = pycore_init_types();
+ status = pycore_init_types(runtime);
/* XXX The following is lax in error checking */
PyObject *modules = PyDict_New();
runtime->open_code_userdata = open_code_userdata;
runtime->audit_hook_head = audit_hook_head;
- _PyGC_Initialize(&runtime->gc);
+ _PyGC_InitializeRuntime(&runtime->gc);
_PyEval_Initialize(&runtime->ceval);
PyPreConfig_InitPythonConfig(&runtime->preconfig);