8000 gh-99741: Implement Multi-Phase Init for the _xxsubinterpreters Module by ericsnowcurrently · Pull Request #99742 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-99741: Implement Multi-Phase Init for the _xxsubinterpreters Module #99742

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

Prev Previous commit
Next Next commit
Add module state.
  • Loading branch information
ericsnowcurrently committed Dec 5, 2022
commit fe3fd40654d40832ee8214595ecf4f567b8e4efc
56 changes: 55 additions & 1 deletion Modules/_xxsubinterpretersmodule.c
8000
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,33 @@ _release_xid_data(_PyCrossInterpreterData *data, int ignoreexc)
}


/* module state *************************************************************/

typedef struct {
int _not_used;
} module_state;

static inline module_state *
get_module_state(PyObject *mod)
{
module_state *state = PyModule_GetState(mod);
assert(state != NULL);
return state;
}

static int
traverse_module_state(module_state *state, visitproc visit, void *arg)
{
return 0;
}

static int
clear_module_state(module_state *state)
{
return 0;
}


/* data-sharing-specific code ***********************************************/

struct _sharednsitem {
Expand Down Expand Up @@ -2934,12 +2961,39 @@ module_exec(PyObject *mod)
return -1;
}

static int
module_traverse(PyObject *mod, visitproc visit, void *arg)
{
module_state *state = get_module_state(mod);
traverse_module_state(state, visit, arg);
return 0;
}

static int
module_clear(PyObject *mod)
{
module_state *state = get_module_state(mod);
clear_module_state(state);
return 0;
}

static void
module_free(void *mod)
{
(void)module_clear((PyObject *)mod);
(void)_PyCrossInterpreterData_UnregisterClass(&ChannelIDType);
_globals_fini();
}

static struct PyModuleDef moduledef = {
.m_base = PyModuleDef_HEAD_INIT,
.m_name = MODULE_NAME,
.m_doc = module_doc,
.m_size = -1,
.m_size = sizeof(module_state),
.m_methods = module_functions,
.m_traverse = module_traverse,
.m_clear = module_clear,
.m_free = (freefunc)module_free,
};


Expand Down
0