Commit 3fceadcd authored by Stefan Behnel's avatar Stefan Behnel

moved helper function __Pyx_Import() into ImportExport.c utility code file

parent c8019db7
...@@ -1948,7 +1948,7 @@ class ImportNode(ExprNode): ...@@ -1948,7 +1948,7 @@ class ImportNode(ExprNode):
self.name_list.analyse_types(env) self.name_list.analyse_types(env)
self.name_list.coerce_to_pyobject(env) self.name_list.coerce_to_pyobject(env)
self.is_temp = 1 self.is_temp = 1
env.use_utility_code(import_utility_code) env.use_utility_code(UtilityCode.load_cached("Import", "ImportExport.c"))
gil_message = "Python import" gil_message = "Python import"
...@@ -9901,86 +9901,6 @@ static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) { ...@@ -9901,86 +9901,6 @@ static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
#------------------------------------------------------------------------------------ #------------------------------------------------------------------------------------
import_utility_code = UtilityCode(
proto = """
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level); /*proto*/
""",
impl = """
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level) {
PyObject *py_import = 0;
PyObject *empty_list = 0;
PyObject *module = 0;
PyObject *global_dict = 0;
PyObject *empty_dict = 0;
PyObject *list;
py_import = __Pyx_GetAttrString(%(BUILTINS)s, "__import__");
if (!py_import)
goto bad;
if (from_list)
list = from_list;
else {
empty_list = PyList_New(0);
if (!empty_list)
goto bad;
list = empty_list;
}
global_dict = PyModule_GetDict(%(GLOBALS)s);
if (!global_dict)
goto bad;
empty_dict = PyDict_New();
if (!empty_dict)
goto bad;
#if PY_VERSION_HEX >= 0x02050000
{
#if PY_MAJOR_VERSION >= 3
if (level == -1) {
if (strchr(__Pyx_MODULE_NAME, '.')) {
/* try package relative import first */
PyObject *py_level = PyInt_FromLong(1);
if (!py_level)
goto bad;
module = PyObject_CallFunctionObjArgs(py_import,
name, global_dict, empty_dict, list, py_level, NULL);
Py_DECREF(py_level);
if (!module) {
if (!PyErr_ExceptionMatches(PyExc_ImportError))
goto bad;
PyErr_Clear();
}
}
level = 0; /* try absolute import on failure */
}
#endif
if (!module) {
PyObject *py_level = PyInt_FromLong(level);
if (!py_level)
goto bad;
module = PyObject_CallFunctionObjArgs(py_import,
name, global_dict, empty_dict, list, py_level, NULL);
Py_DECREF(py_level);
}
}
#else
if (level>0) {
PyErr_SetString(PyExc_RuntimeError, "Relative import is not supported for Python <=2.4.");
goto bad;
}
module = PyObject_CallFunctionObjArgs(py_import,
name, global_dict, empty_dict, list, NULL);
#endif
bad:
Py_XDECREF(empty_list);
Py_XDECREF(py_import);
Py_XDECREF(empty_dict);
return module;
}
""" % {
"BUILTINS": Naming.builtins_cname,
"GLOBALS": Naming.module_cname,
})
#------------------------------------------------------------------------------------
pyerr_occurred_withgil_utility_code= UtilityCode( pyerr_occurred_withgil_utility_code= UtilityCode(
proto = """ proto = """
static CYTHON_INLINE int __Pyx_ErrOccurredWithGIL(void); /* proto */ static CYTHON_INLINE int __Pyx_ErrOccurredWithGIL(void); /* proto */
......
...@@ -580,7 +580,7 @@ class FusedCFuncDefNode(StatListNode): ...@@ -580,7 +580,7 @@ class FusedCFuncDefNode(StatListNode):
if all_buffer_types: if all_buffer_types:
self._buffer_declarations(pyx_code, decl_code, all_buffer_types) self._buffer_declarations(pyx_code, decl_code, all_buffer_types)
env.use_utility_code(ExprNodes.import_utility_code) env.use_utility_code(Code.UtilityCode.load_cached("Import", "ImportExport.c"))
pyx_code.put_chunk( pyx_code.put_chunk(
u""" u"""
......
...@@ -8,6 +8,83 @@ ...@@ -8,6 +8,83 @@
#endif #endif
#endif #endif
/////////////// Import.proto ///////////////
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level); /*proto*/
/////////////// Import ///////////////
//@substitute: naming
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level) {
PyObject *py_import = 0;
PyObject *empty_list = 0;
PyObject *module = 0;
PyObject *global_dict = 0;
PyObject *empty_dict = 0;
PyObject *list;
py_import = __Pyx_GetAttrString($builtins_cname, "__import__");
if (!py_import)
goto bad;
if (from_list)
list = from_list;
else {
empty_list = PyList_New(0);
if (!empty_list)
goto bad;
list = empty_list;
}
global_dict = PyModule_GetDict($module_cname);
if (!global_dict)
goto bad;
empty_dict = PyDict_New();
if (!empty_dict)
goto bad;
#if PY_VERSION_HEX >= 0x02050000
{
#if PY_MAJOR_VERSION >= 3
if (level == -1) {
if (strchr(__Pyx_MODULE_NAME, '.')) {
/* try package relative import first */
PyObject *py_level = PyInt_FromLong(1);
if (!py_level)
goto bad;
module = PyObject_CallFunctionObjArgs(py_import,
name, global_dict, empty_dict, list, py_level, NULL);
Py_DECREF(py_level);
if (!module) {
if (!PyErr_ExceptionMatches(PyExc_ImportError))
goto bad;
PyErr_Clear();
}
}
level = 0; /* try absolute import on failure */
}
#endif
if (!module) {
PyObject *py_level = PyInt_FromLong(level);
if (!py_level)
goto bad;
module = PyObject_CallFunctionObjArgs(py_import,
name, global_dict, empty_dict, list, py_level, NULL);
Py_DECREF(py_level);
}
}
#else
if (level>0) {
PyErr_SetString(PyExc_RuntimeError, "Relative import is not supported for Python <=2.4.");
goto bad;
}
module = PyObject_CallFunctionObjArgs(py_import,
name, global_dict, empty_dict, list, NULL);
#endif
bad:
Py_XDECREF(empty_list);
Py_XDECREF(py_import);
Py_XDECREF(empty_dict);
return module;
}
/////////////// ModuleImport.proto /////////////// /////////////// ModuleImport.proto ///////////////
static PyObject *__Pyx_ImportModule(const char *name); /*proto*/ static PyObject *__Pyx_ImportModule(const char *name); /*proto*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment