[Python-checkins] cpython (3.5): Issue #24769: Interpreter now starts properly when dynamic loading

larry.hastings python-checkins at python.org
Tue Aug 25 23:25:20 CEST 2015


https://hg.python.org/cpython/rev/931593401e3e
changeset: 97497:931593401e3e
branch: 3.5
user: Larry Hastings <larry at hastings.org>
date: Mon Aug 24 19:53:56 2015 -0700
summary:
 Issue #24769: Interpreter now starts properly when dynamic loading
is disabled. Patch by Petr Viktorin.
files:
 Lib/importlib/_bootstrap.py | 2 +-
 Misc/NEWS | 4 +
 Python/clinic/import.c.h | 29 ++++++++++-
 Python/import.c | 69 ++++++++++++++++--------
 Python/importlib.h | 2 +-
 5 files changed, 80 insertions(+), 26 deletions(-)
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -745,7 +745,7 @@
 @classmethod
 def exec_module(self, module):
 """Exec a built-in module"""
- _call_with_frames_removed(_imp.exec_dynamic, module)
+ _call_with_frames_removed(_imp.exec_builtin, module)
 
 @classmethod
 @_requires_builtin
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@
 Core and Builtins
 -----------------
 
+- Issue #24769: Interpreter now starts properly when dynamic loading
+ is disabled. Patch by Petr Viktorin.
+
 - Issue #21167: NAN operations are now handled correctly when python is
 compiled with ICC even if -fp-model strict is not specified.
 
@@ -20,6 +23,7 @@
 
 - Issue #24839: platform._syscmd_ver raises DeprecationWarning
 
+
 What's New in Python 3.5.0 release candidate 1?
 ===============================================
 
diff --git a/Python/clinic/import.c.h b/Python/clinic/import.c.h
--- a/Python/clinic/import.c.h
+++ b/Python/clinic/import.c.h
@@ -318,6 +318,33 @@
 
 #endif /* defined(HAVE_DYNAMIC_LOADING) */
 
+PyDoc_STRVAR(_imp_exec_builtin__doc__,
+"exec_builtin($module, mod, /)\n"
+"--\n"
+"\n"
+"Initialize an extension module.");
+
+#define _IMP_EXEC_BUILTIN_METHODDEF \
+ {"exec_builtin", (PyCFunction)_imp_exec_builtin, METH_O, _imp_exec_builtin__doc__},
+
+static int
+_imp_exec_builtin_impl(PyModuleDef *module, PyObject *mod);
+
+static PyObject *
+_imp_exec_builtin(PyModuleDef *module, PyObject *mod)
+{
+ PyObject *return_value = NULL;
+ int _return_value;
+
+ _return_value = _imp_exec_builtin_impl(module, mod);
+ if ((_return_value == -1) && PyErr_Occurred())
+ goto exit;
+ return_value = PyLong_FromLong((long)_return_value);
+
+exit:
+ return return_value;
+}
+
 #ifndef _IMP_CREATE_DYNAMIC_METHODDEF
 #define _IMP_CREATE_DYNAMIC_METHODDEF
 #endif /* !defined(_IMP_CREATE_DYNAMIC_METHODDEF) */
@@ -325,4 +352,4 @@
 #ifndef _IMP_EXEC_DYNAMIC_METHODDEF
 #define _IMP_EXEC_DYNAMIC_METHODDEF
 #endif /* !defined(_IMP_EXEC_DYNAMIC_METHODDEF) */
-/*[clinic end generated code: output=0f1059766dd58f88 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=c38749cebcadbc3b input=a9049054013a1b77]*/
diff --git a/Python/import.c b/Python/import.c
--- a/Python/import.c
+++ b/Python/import.c
@@ -1943,6 +1943,34 @@
 return PyBool_FromLong((long) (p == NULL ? 0 : p->size));
 }
 
+/* Common implementation for _imp.exec_dynamic and _imp.exec_builtin */
+static int
+exec_builtin_or_dynamic(PyObject *mod) {
+ PyModuleDef *def;
+ void *state;
+
+ if (!PyModule_Check(mod)) {
+ return 0;
+ }
+
+ def = PyModule_GetDef(mod);
+ if (def == NULL) {
+ if (PyErr_Occurred()) {
+ return -1;
+ }
+ return 0;
+ }
+ state = PyModule_GetState(mod);
+ if (PyErr_Occurred()) {
+ return -1;
+ }
+ if (state) {
+ /* Already initialized; skip reload */
+ return 0;
+ }
+ return PyModule_ExecDef(mod, def);
+}
+
 #ifdef HAVE_DYNAMIC_LOADING
 
 /*[clinic input]
@@ -2014,35 +2042,29 @@
 _imp_exec_dynamic_impl(PyModuleDef *module, PyObject *mod)
 /*[clinic end generated code: output=4b84f1301b22d4bd input=9fdbfcb250280d3a]*/
 {
- PyModuleDef *def;
- void *state;
-
- if (!PyModule_Check(mod)) {
- return 0;
- }
-
- def = PyModule_GetDef(mod);
- if (def == NULL) {
- if (PyErr_Occurred()) {
- return -1;
- }
- return 0;
- }
- state = PyModule_GetState(mod);
- if (PyErr_Occurred()) {
- return -1;
- }
- if (state) {
- /* Already initialized; skip reload */
- return 0;
- }
- return PyModule_ExecDef(mod, def);
+ return exec_builtin_or_dynamic(mod);
 }
 
 
 #endif /* HAVE_DYNAMIC_LOADING */
 
 /*[clinic input]
+_imp.exec_builtin -> int
+
+ mod: object
+ /
+
+Initialize a built-in module.
+[clinic start generated code]*/
+
+static int
+_imp_exec_builtin_impl(PyModuleDef *module, PyObject *mod)
+/*[clinic end generated code: output=215e99876a27e284 input=77ebec0c2a10ecca]*/
+{
+ return exec_builtin_or_dynamic(mod);
+}
+
+/*[clinic input]
 dump buffer
 [clinic start generated code]*/
 /*[clinic end generated code: output=da39a3ee5e6b4b0d input=524ce2e021e4eba6]*/
@@ -2064,6 +2086,7 @@
 _IMP_IS_FROZEN_METHODDEF
 _IMP_CREATE_DYNAMIC_METHODDEF
 _IMP_EXEC_DYNAMIC_METHODDEF
+ _IMP_EXEC_BUILTIN_METHODDEF
 _IMP__FIX_CO_FILENAME_METHODDEF
 {NULL, NULL} /* sentinel */
 };
diff --git a/Python/importlib.h b/Python/importlib.h
--- a/Python/importlib.h
+++ b/Python/importlib.h
[stripped]
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /