diff options
Diffstat (limited to 'Python/pystate.c')
| -rw-r--r-- | Python/pystate.c | 53 | 
1 files changed, 47 insertions, 6 deletions
| diff --git a/Python/pystate.c b/Python/pystate.c index 42bc3ec..772aa53 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -69,7 +69,6 @@ PyInterpreterState_New(void)              Py_FatalError("Can't initialize threads for interpreter");  #endif          interp->modules = NULL; -        interp->modules_reloading = NULL;          interp->modules_by_index = NULL;          interp->sysdict = NULL;          interp->builtins = NULL; @@ -79,6 +78,7 @@ PyInterpreterState_New(void)          interp->codec_error_registry = NULL;          interp->codecs_initialized = 0;          interp->fscodec_initialized = 0; +        interp->importlib = NULL;  #ifdef HAVE_DLOPEN  #ifdef RTLD_NOW          interp->dlopenflags = RTLD_NOW; @@ -113,9 +113,9 @@ PyInterpreterState_Clear(PyInterpreterState *interp)      Py_CLEAR(interp->codec_error_registry);      Py_CLEAR(interp->modules);      Py_CLEAR(interp->modules_by_index); -    Py_CLEAR(interp->modules_reloading);      Py_CLEAR(interp->sysdict);      Py_CLEAR(interp->builtins); +    Py_CLEAR(interp->importlib);  } @@ -242,9 +242,9 @@ _PyThreadState_Init(PyThreadState *tstate)  }  PyObject* -PyState_FindModule(struct PyModuleDef* m) +PyState_FindModule(struct PyModuleDef* module)  { -    Py_ssize_t index = m->m_base.m_index; +    Py_ssize_t index = module->m_base.m_index;      PyInterpreterState *state = PyThreadState_GET()->interp;      PyObject *res;      if (index == 0) @@ -276,6 +276,47 @@ _PyState_AddModule(PyObject* module, struct PyModuleDef* def)                            def->m_base.m_index, module);  } +int +PyState_AddModule(PyObject* module, struct PyModuleDef* def) +{ +    Py_ssize_t index; +    PyInterpreterState *state = PyThreadState_GET()->interp; +    if (!def) { +        Py_FatalError("PyState_AddModule: Module Definition is NULL"); +        return -1; +    } +    index = def->m_base.m_index; +    if (state->modules_by_index) { +        if(PyList_GET_SIZE(state->modules_by_index) >= index) { +            if(module == PyList_GET_ITEM(state->modules_by_index, index)) { +                Py_FatalError("PyState_AddModule: Module already added!"); +                return -1; +            } +        } +    } +    return _PyState_AddModule(module, def); +} + +int +PyState_RemoveModule(struct PyModuleDef* def) +{ +    Py_ssize_t index = def->m_base.m_index; +    PyInterpreterState *state = PyThreadState_GET()->interp; +    if (index == 0) { +        Py_FatalError("PyState_RemoveModule: Module index invalid."); +        return -1; +    } +    if (state->modules_by_index == NULL) { +        Py_FatalError("PyState_RemoveModule: Interpreters module-list not acessible."); +        return -1; +    } +    if (index > PyList_GET_SIZE(state->modules_by_index)) { +        Py_FatalError("PyState_RemoveModule: Module index out of bounds."); +        return -1; +    } +    return PyList_SetItem(state->modules_by_index, index, Py_None); +} +  void  PyThreadState_Clear(PyThreadState *tstate)  { @@ -347,11 +388,11 @@ PyThreadState_Delete(PyThreadState *tstate)  {      if (tstate == _Py_atomic_load_relaxed(&_PyThreadState_Current))          Py_FatalError("PyThreadState_Delete: tstate is still current"); -    tstate_delete_common(tstate);  #ifdef WITH_THREAD      if (autoInterpreterState && PyThread_get_key_value(autoTLSkey) == tstate)          PyThread_delete_key_value(autoTLSkey);  #endif /* WITH_THREAD */ +    tstate_delete_common(tstate);  } @@ -365,9 +406,9 @@ PyThreadState_DeleteCurrent()          Py_FatalError(              "PyThreadState_DeleteCurrent: no current tstate");      _Py_atomic_store_relaxed(&_PyThreadState_Current, NULL); -    tstate_delete_common(tstate);      if (autoInterpreterState && PyThread_get_key_value(autoTLSkey) == tstate)          PyThread_delete_key_value(autoTLSkey); +    tstate_delete_common(tstate);      PyEval_ReleaseLock();  }  #endif /* WITH_THREAD */ | 
