From 94efbe0ac4d55d812c49fa29accc75e135526975 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 27 Apr 2011 00:24:21 +0200 Subject: Issue #10914: Initialize correctly the filesystem codec when creating a new subinterpreter to fix a bootstrap issue with codecs implemented in Python, as the ISO-8859-15 codec. Add fscodec_initialized attribute to the PyInterpreterState structure. --- Python/pystate.c | 1 + 1 file changed, 1 insertion(+) (limited to 'Python/pystate.c') diff --git a/Python/pystate.c b/Python/pystate.c index 922e9a3780..65219eb6b6 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -79,6 +79,7 @@ PyInterpreterState_New(void) interp->codec_search_cache = NULL; interp->codec_error_registry = NULL; interp->codecs_initialized = 0; + interp->fscodec_initialized = 0; #ifdef HAVE_DLOPEN #ifdef RTLD_NOW interp->dlopenflags = RTLD_NOW; -- cgit v1.2.1 From e6ecc6d13e7b3c963d6cabfdacca8138f968e970 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Sat, 14 Apr 2012 14:10:13 -0400 Subject: Issue #2377: Make importlib the implementation of __import__(). importlib._bootstrap is now frozen into Python/importlib.h and stored as _frozen_importlib in sys.modules. Py_Initialize() loads the frozen code along with sys and imp and then uses _frozen_importlib._install() to set builtins.__import__() w/ _frozen_importlib.__import__(). --- Python/pystate.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'Python/pystate.c') diff --git a/Python/pystate.c b/Python/pystate.c index 31b5423d38..fdcbbcec87 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -79,6 +79,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; @@ -116,6 +117,7 @@ PyInterpreterState_Clear(PyInterpreterState *interp) Py_CLEAR(interp->modules_reloading); Py_CLEAR(interp->sysdict); Py_CLEAR(interp->builtins); + Py_CLEAR(interp->importlib); } -- cgit v1.2.1 From 50f76bdf6a49c9e80d8c092db2e93fc8c02ecb5c Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Sun, 29 Apr 2012 14:38:11 -0400 Subject: Issues #13959, 14647: Re-implement imp.reload() in Lib/imp.py. Thanks to Eric Snow for the patch. --- Python/pystate.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'Python/pystate.c') diff --git a/Python/pystate.c b/Python/pystate.c index fdcbbcec87..a0489ad08a 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; @@ -114,7 +113,6 @@ 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); -- cgit v1.2.1 From c4a7260c32412a742ebd14714a731c44d6b4fba7 Mon Sep 17 00:00:00 2001 From: "Martin v. L?wis" Date: Fri, 22 Jun 2012 12:20:55 +0200 Subject: Issue #15042: Add PyState_AddModule and PyState_RemoveModule. Add version guard for Py_LIMITED_API additions. Issue #15081: Document PyState_FindModule. Patch by Robin Schreiber. --- Python/pystate.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) (limited to 'Python/pystate.c') diff --git a/Python/pystate.c b/Python/pystate.c index a0489ad08a..cf08a2b4c6 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -239,9 +239,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) @@ -273,6 +273,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) { -- cgit v1.2.1 From ad9913285e1396716c192883510c0febdb7c2b94 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Thu, 6 Sep 2012 00:59:49 +0200 Subject: Issue #13992: The trashcan mechanism is now thread-safe. This eliminates sporadic crashes in multi-thread programs when several long deallocator chains ran concurrently and involved subclasses of built-in container types. Because of this change, a couple extension modules compiled for 3.2.4 (those which use the trashcan mechanism, despite it being undocumented) will not be loadable by 3.2.3 and earlier. However, extension modules compiled for 3.2.3 and earlier will be loadable by 3.2.4. --- Python/pystate.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'Python/pystate.c') diff --git a/Python/pystate.c b/Python/pystate.c index 8dc570ab75..cfd61d0098 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -206,6 +206,9 @@ new_threadstate(PyInterpreterState *interp, int init) tstate->c_profileobj = NULL; tstate->c_traceobj = NULL; + tstate->trash_delete_nesting = 0; + tstate->trash_delete_later = NULL; + if (init) _PyThreadState_Init(tstate); -- cgit v1.2.1