summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2017-09-14 06:46:04 (GMT)
committerGitHub <noreply@github.com>2017-09-14 06:46:04 (GMT)
commit93c92f7d1dbb6e7e472f1d0444c6968858113de2 (patch)
tree031230f9b0cf2e8a8ef21f7fc40c4f5f98d20c6c /Objects
parent13ad3b7a82bf56d803fbe48ee5df6c4b08986c78 (diff)
downloadcpython-93c92f7d1dbb6e7e472f1d0444c6968858113de2.zip
cpython-93c92f7d1dbb6e7e472f1d0444c6968858113de2.tar.gz
cpython-93c92f7d1dbb6e7e472f1d0444c6968858113de2.tar.bz2
bpo-31404: Revert "remove modules from Py_InterpreterState (#1638)" (#3565)
PR #1638, for bpo-28411, causes problems in some (very) edge cases. Until that gets sorted out, we're reverting the merge. PR #3506, a fix on top of #1638, is also getting reverted.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/moduleobject.c12
-rw-r--r--Objects/object.c27
-rw-r--r--Objects/typeobject.c3
3 files changed, 17 insertions, 25 deletions
diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c
index 2be49fb..5fab06d 100644
--- a/Objects/moduleobject.c
+++ b/Objects/moduleobject.c
@@ -162,17 +162,11 @@ _add_methods_to_object(PyObject *module, PyObject *name, PyMethodDef *functions)
PyObject *
PyModule_Create2(struct PyModuleDef* module, int module_api_version)
{
- if (!_PyImport_IsInitialized(PyThreadState_GET()->interp))
- Py_FatalError("Python import machinery not initialized");
- return _PyModule_CreateInitialized(module, module_api_version);
-}
-
-PyObject *
-_PyModule_CreateInitialized(struct PyModuleDef* module, int module_api_version)
-{
const char* name;
PyModuleObject *m;
-
+ PyInterpreterState *interp = PyThreadState_Get()->interp;
+ if (interp->modules == NULL)
+ Py_FatalError("Python import machinery not initialized");
if (!PyModuleDef_Init(module))
return NULL;
name = module->m_name;
diff --git a/Objects/object.c b/Objects/object.c
index ed8a62a..74893e3 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -29,23 +29,20 @@ _Py_GetRefTotal(void)
return total;
}
-PyObject *
-_PyDebug_XOptionShowRefCount(void)
-{
- PyObject *xoptions = PySys_GetXOptions();
- if (xoptions == NULL)
- return NULL;
-
- _Py_IDENTIFIER(showrefcount);
- return _PyDict_GetItemId(xoptions, &PyId_showrefcount);
-}
-
void
_PyDebug_PrintTotalRefs(void) {
- fprintf(stderr,
- "[%" PY_FORMAT_SIZE_T "d refs, "
- "%" PY_FORMAT_SIZE_T "d blocks]\n",
- _Py_GetRefTotal(), _Py_GetAllocatedBlocks());
+ PyObject *xoptions, *value;
+ _Py_IDENTIFIER(showrefcount);
+
+ xoptions = PySys_GetXOptions();
+ if (xoptions == NULL)
+ return;
+ value = _PyDict_GetItemId(xoptions, &PyId_showrefcount);
+ if (value == Py_True)
+ fprintf(stderr,
+ "[%" PY_FORMAT_SIZE_T "d refs, "
+ "%" PY_FORMAT_SIZE_T "d blocks]\n",
+ _Py_GetRefTotal(), _Py_GetAllocatedBlocks());
}
#endif /* Py_REF_DEBUG */
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index a06cab7..dc4d2ed 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -3902,6 +3902,7 @@ import_copyreg(void)
{
PyObject *copyreg_str;
PyObject *copyreg_module;
+ PyInterpreterState *interp = PyThreadState_GET()->interp;
_Py_IDENTIFIER(copyreg);
copyreg_str = _PyUnicode_FromId(&PyId_copyreg);
@@ -3913,7 +3914,7 @@ import_copyreg(void)
by storing a reference to the cached module in a static variable, but
this broke when multiple embedded interpreters were in use (see issue
#17408 and #19088). */
- copyreg_module = _PyImport_GetModuleWithError(copyreg_str);
+ copyreg_module = PyDict_GetItemWithError(interp->modules, copyreg_str);
if (copyreg_module != NULL) {
Py_INCREF(copyreg_module);
return copyreg_module;