Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1df0b35

Browse files
committed
Issue #24769: Interpreter now starts properly when dynamic loading
is disabled. Patch by Petr Viktorin.
1 parent 7250d02 commit 1df0b35

5 files changed

Lines changed: 80 additions & 26 deletions

File tree

Lib/importlib/_bootstrap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ def create_module(self, spec):
745745
@classmethod
746746
def exec_module(self, module):
747747
"""Exec a built-in module"""
748-
_call_with_frames_removed(_imp.exec_dynamic, module)
748+
_call_with_frames_removed(_imp.exec_builtin, module)
749749

750750
@classmethod
751751
@_requires_builtin

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Release date: 2015-08-23
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #24769: Interpreter now starts properly when dynamic loading
14+
is disabled. Patch by Petr Viktorin.
15+
1316
- Issue #21167: NAN operations are now handled correctly when python is
1417
compiled with ICC even if -fp-model strict is not specified.
1518

@@ -20,6 +23,7 @@ Library
2023

2124
- Issue #24839: platform._syscmd_ver raises DeprecationWarning
2225

26+
2327
What's New in Python 3.5.0 release candidate 1?
2428
===============================================
2529

Python/clinic/import.c.h

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,11 +318,38 @@ _imp_exec_dynamic(PyModuleDef *module, PyObject *mod)
318318

319319
#endif /* defined(HAVE_DYNAMIC_LOADING) */
320320

321+
PyDoc_STRVAR(_imp_exec_builtin__doc__,
322+
"exec_builtin($module, mod, /)\n"
323+
"--\n"
324+
"\n"
325+
"Initialize an extension module.");
326+
327+
#define _IMP_EXEC_BUILTIN_METHODDEF \
328+
{"exec_builtin", (PyCFunction)_imp_exec_builtin, METH_O, _imp_exec_builtin__doc__},
329+
330+
static int
331+
_imp_exec_builtin_impl(PyModuleDef *module, PyObject *mod);
332+
333+
static PyObject *
334+
_imp_exec_builtin(PyModuleDef *module, PyObject *mod)
335+
{
336+
PyObject *return_value = NULL;
337+
int _return_value;
338+
339+
_return_value = _imp_exec_builtin_impl(module, mod);
340+
if ((_return_value == -1) && PyErr_Occurred())
341+
goto exit;
342+
return_value = PyLong_FromLong((long)_return_value);
343+
344+
exit:
345+
return return_value;
346+
}
347+
321348
#ifndef _IMP_CREATE_DYNAMIC_METHODDEF
322349
#define _IMP_CREATE_DYNAMIC_METHODDEF
323350
#endif /* !defined(_IMP_CREATE_DYNAMIC_METHODDEF) */
324351

325352
#ifndef _IMP_EXEC_DYNAMIC_METHODDEF
326353
#define _IMP_EXEC_DYNAMIC_METHODDEF
327354
#endif /* !defined(_IMP_EXEC_DYNAMIC_METHODDEF) */
328-
/*[clinic end generated code: output=0f1059766dd58f88 input=a9049054013a1b77]*/
355+
/*[clinic end generated code: output=c38749cebcadbc3b input=a9049054013a1b77]*/

Python/import.c

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,6 +1943,34 @@ _imp_is_frozen_impl(PyModuleDef *module, PyObject *name)
19431943
return PyBool_FromLong((long) (p == NULL ? 0 : p->size));
19441944
}
19451945

1946+
/* Common implementation for _imp.exec_dynamic and _imp.exec_builtin */
1947+
static int
1948+
exec_builtin_or_dynamic(PyObject *mod) {
1949+
PyModuleDef *def;
1950+
void *state;
1951+
1952+
if (!PyModule_Check(mod)) {
1953+
return 0;
1954+
}
1955+
1956+
def = PyModule_GetDef(mod);
1957+
if (def == NULL) {
1958+
if (PyErr_Occurred()) {
1959+
return -1;
1960+
}
1961+
return 0;
1962+
}
1963+
state = PyModule_GetState(mod);
1964+
if (PyErr_Occurred()) {
1965+
return -1;
1966+
}
1967+
if (state) {
1968+
/* Already initialized; skip reload */
1969+
return 0;
1970+
}
1971+
return PyModule_ExecDef(mod, def);
1972+
}
1973+
19461974
#ifdef HAVE_DYNAMIC_LOADING
19471975

19481976
/*[clinic input]
@@ -2014,34 +2042,28 @@ static int
20142042
_imp_exec_dynamic_impl(PyModuleDef *module, PyObject *mod)
20152043
/*[clinic end generated code: output=4b84f1301b22d4bd input=9fdbfcb250280d3a]*/
20162044
{
2017-
PyModuleDef *def;
2018-
void *state;
2019-
2020-
if (!PyModule_Check(mod)) {
2021-
return 0;
2022-
}
2023-
2024-
def = PyModule_GetDef(mod);
2025-
if (def == NULL) {
2026-
if (PyErr_Occurred()) {
2027-
return -1;
2028-
}
2029-
return 0;
2030-
}
2031-
state = PyModule_GetState(mod);
2032-
if (PyErr_Occurred()) {
2033-
return -1;
2034-
}
2035-
if (state) {
2036-
/* Already initialized; skip reload */
2037-
return 0;
2038-
}
2039-
return PyModule_ExecDef(mod, def);
2045+
return exec_builtin_or_dynamic(mod);
20402046
}
20412047

20422048

20432049
#endif /* HAVE_DYNAMIC_LOADING */
20442050

2051+
/*[clinic input]
2052+
_imp.exec_builtin -> int
2053+
2054+
mod: object
2055+
/
2056+
2057+
Initialize a built-in module.
2058+
[clinic start generated code]*/
2059+
2060+
static int
2061+
_imp_exec_builtin_impl(PyModuleDef *module, PyObject *mod)
2062+
/*[clinic end generated code: output=215e99876a27e284 input=77ebec0c2a10ecca]*/
2063+
{
2064+
return exec_builtin_or_dynamic(mod);
2065+
}
2066+
20452067
/*[clinic input]
20462068
dump buffer
20472069
[clinic start generated code]*/
@@ -2064,6 +2086,7 @@ static PyMethodDef imp_methods[] = {
20642086
_IMP_IS_FROZEN_METHODDEF
20652087
_IMP_CREATE_DYNAMIC_METHODDEF
20662088
_IMP_EXEC_DYNAMIC_METHODDEF
2089+
_IMP_EXEC_BUILTIN_METHODDEF
20672090
_IMP__FIX_CO_FILENAME_METHODDEF
20682091
{NULL, NULL} /* sentinel */
20692092
};

Python/importlib.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,7 @@ const unsigned char _Py_M__importlib[] = {
13041304
0,1,100,1,0,83,41,2,122,22,69,120,101,99,32,97,
13051305
32,98,117,105,108,116,45,105,110,32,109,111,100,117,108,101,
13061306
78,41,3,114,65,0,0,0,114,57,0,0,0,90,12,101,
1307-
120,101,99,95,100,121,110,97,109,105,99,41,2,114,19,0,
1307+
120,101,99,95,98,117,105,108,116,105,110,41,2,114,19,0,
13081308
0,0,114,89,0,0,0,114,10,0,0,0,114,10,0,0,
13091309
0,114,11,0,0,0,114,139,0,0,0,233,2,0,0,115,
13101310
2,0,0,0,0,3,122,27,66,117,105,108,116,105,110,73,

0 commit comments

Comments
 (0)