Commit 327267f2 authored by Stefan Behnel's avatar Stefan Behnel

Remove redundant helper function "__Pyx_ImportModule()" which was only needed...

Remove redundant helper function "__Pyx_ImportModule()" which was only needed in Py<2.6 when PyObject_GetAttrString() and PyImport_ImportModule() did not take const string arguments.
parent d8645c03
...@@ -270,7 +270,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -270,7 +270,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
h_code.putln("static %s = 0;" % type.declaration_code(cname)) h_code.putln("static %s = 0;" % type.declaration_code(cname))
h_code.putln("#define %s (*%s)" % (entry.name, cname)) h_code.putln("#define %s (*%s)" % (entry.name, cname))
h_code.put(UtilityCode.load_as_string("PyIdentifierFromString", "ImportExport.c")[0]) h_code.put(UtilityCode.load_as_string("PyIdentifierFromString", "ImportExport.c")[0])
h_code.put(UtilityCode.load_as_string("ModuleImport", "ImportExport.c")[1])
if api_vars: if api_vars:
h_code.put(UtilityCode.load_as_string("VoidPtrImport", "ImportExport.c")[1]) h_code.put(UtilityCode.load_as_string("VoidPtrImport", "ImportExport.c")[1])
if api_funcs: if api_funcs:
...@@ -280,7 +279,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -280,7 +279,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
h_code.putln("") h_code.putln("")
h_code.putln("static int import_%s(void) {" % self.api_name(env)) h_code.putln("static int import_%s(void) {" % self.api_name(env))
h_code.putln("PyObject *module = 0;") h_code.putln("PyObject *module = 0;")
h_code.putln('module = __Pyx_ImportModule("%s");' % env.qualified_name) h_code.putln('module = PyImport_ImportModule("%s");' % env.qualified_name)
h_code.putln("if (!module) goto bad;") h_code.putln("if (!module) goto bad;")
for entry in api_funcs: for entry in api_funcs:
cname = env.mangle(Naming.func_prefix_api, entry.name) cname = env.mangle(Naming.func_prefix_api, entry.name)
...@@ -2903,13 +2902,11 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -2903,13 +2902,11 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
if entry.defined_in_pxd: if entry.defined_in_pxd:
entries.append(entry) entries.append(entry)
if entries: if entries:
env.use_utility_code(
UtilityCode.load_cached("ModuleImport", "ImportExport.c"))
env.use_utility_code( env.use_utility_code(
UtilityCode.load_cached("VoidPtrImport", "ImportExport.c")) UtilityCode.load_cached("VoidPtrImport", "ImportExport.c"))
temp = code.funcstate.allocate_temp(py_object_type, manage_ref=True) temp = code.funcstate.allocate_temp(py_object_type, manage_ref=True)
code.putln( code.putln(
'%s = __Pyx_ImportModule("%s"); if (!%s) %s' % ( '%s = PyImport_ImportModule("%s"); if (!%s) %s' % (
temp, temp,
module.qualified_name, module.qualified_name,
temp, temp,
...@@ -2933,13 +2930,11 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -2933,13 +2930,11 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
if entry.defined_in_pxd and entry.used: if entry.defined_in_pxd and entry.used:
entries.append(entry) entries.append(entry)
if entries: if entries:
env.use_utility_code(
UtilityCode.load_cached("ModuleImport", "ImportExport.c"))
env.use_utility_code( env.use_utility_code(
UtilityCode.load_cached("FunctionImport", "ImportExport.c")) UtilityCode.load_cached("FunctionImport", "ImportExport.c"))
temp = code.funcstate.allocate_temp(py_object_type, manage_ref=True) temp = code.funcstate.allocate_temp(py_object_type, manage_ref=True)
code.putln( code.putln(
'%s = __Pyx_ImportModule("%s"); if (!%s) %s' % ( '%s = PyImport_ImportModule("%s"); if (!%s) %s' % (
temp, temp,
module.qualified_name, module.qualified_name,
temp, temp,
...@@ -3099,7 +3094,7 @@ class ModuleImportGenerator(object): ...@@ -3099,7 +3094,7 @@ class ModuleImportGenerator(object):
code = self.code code = self.code
temp = code.funcstate.allocate_temp(py_object_type, manage_ref=True) temp = code.funcstate.allocate_temp(py_object_type, manage_ref=True)
self.temps.append(temp) self.temps.append(temp)
code.putln('%s = __Pyx_ImportModule(%s); if (unlikely(!%s)) %s' % ( code.putln('%s = PyImport_ImportModule(%s); if (unlikely(!%s)) %s' % (
temp, module_name_string, temp, error_code)) temp, module_name_string, temp, error_code))
code.put_gotref(temp) code.put_gotref(temp)
self.imported[module_name_string] = temp self.imported[module_name_string] = temp
......
...@@ -222,31 +222,6 @@ bad: ...@@ -222,31 +222,6 @@ bad:
} }
/////////////// ModuleImport.proto ///////////////
static PyObject *__Pyx_ImportModule(const char *name); /*proto*/
/////////////// ModuleImport ///////////////
//@requires: PyIdentifierFromString
#ifndef __PYX_HAVE_RT_ImportModule
#define __PYX_HAVE_RT_ImportModule
static PyObject *__Pyx_ImportModule(const char *name) {
PyObject *py_name = 0;
PyObject *py_module = 0;
py_name = __Pyx_PyIdentifier_FromString(name);
if (!py_name)
goto bad;
py_module = PyImport_Import(py_name);
Py_DECREF(py_name);
return py_module;
bad:
return 0;
}
#endif
/////////////// SetPackagePathFromImportLib.proto /////////////// /////////////// SetPackagePathFromImportLib.proto ///////////////
// PY_VERSION_HEX >= 0x03030000 // PY_VERSION_HEX >= 0x03030000
...@@ -336,8 +311,6 @@ set_path: ...@@ -336,8 +311,6 @@ set_path:
static PyTypeObject *__Pyx_ImportType(PyObject* module, const char *module_name, const char *class_name, size_t size, int strict); /*proto*/ static PyTypeObject *__Pyx_ImportType(PyObject* module, const char *module_name, const char *class_name, size_t size, int strict); /*proto*/
/////////////// TypeImport /////////////// /////////////// TypeImport ///////////////
//@requires: PyIdentifierFromString
//@requires: ModuleImport
#ifndef __PYX_HAVE_RT_ImportType #ifndef __PYX_HAVE_RT_ImportType
#define __PYX_HAVE_RT_ImportType #define __PYX_HAVE_RT_ImportType
...@@ -345,19 +318,13 @@ static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name, ...@@ -345,19 +318,13 @@ static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name,
size_t size, int strict) size_t size, int strict)
{ {
PyObject *result = 0; PyObject *result = 0;
PyObject *py_name = 0;
char warning[200]; char warning[200];
Py_ssize_t basicsize; Py_ssize_t basicsize;
#ifdef Py_LIMITED_API #ifdef Py_LIMITED_API
PyObject *py_basicsize; PyObject *py_basicsize;
#endif #endif
py_name = __Pyx_PyIdentifier_FromString(class_name); result = PyObject_GetAttrString(module, class_name);
if (!py_name)
goto bad;
result = PyObject_GetAttr(module, py_name);
Py_DECREF(py_name);
py_name = 0;
if (!result) if (!result)
goto bad; goto bad;
if (!PyType_Check(result)) { if (!PyType_Check(result)) {
......
...@@ -1168,11 +1168,15 @@ if (!__Pyx_RefNanny) { ...@@ -1168,11 +1168,15 @@ if (!__Pyx_RefNanny) {
//@substitute: naming //@substitute: naming
static void ${cleanup_cname}(PyObject *self); /*proto*/ static void ${cleanup_cname}(PyObject *self); /*proto*/
#if PY_MAJOR_VERSION < 3 || CYTHON_COMPILING_IN_PYPY
static int __Pyx_RegisterCleanup(void); /*proto*/ static int __Pyx_RegisterCleanup(void); /*proto*/
#else
#define __Pyx_RegisterCleanup() (0)
#endif
/////////////// RegisterModuleCleanup /////////////// /////////////// RegisterModuleCleanup ///////////////
//@substitute: naming //@substitute: naming
//@requires: ImportExport.c::ModuleImport
#if PY_MAJOR_VERSION < 3 || CYTHON_COMPILING_IN_PYPY #if PY_MAJOR_VERSION < 3 || CYTHON_COMPILING_IN_PYPY
static PyObject* ${cleanup_cname}_atexit(PyObject *module, CYTHON_UNUSED PyObject *unused) { static PyObject* ${cleanup_cname}_atexit(PyObject *module, CYTHON_UNUSED PyObject *unused) {
...@@ -1202,7 +1206,7 @@ static int __Pyx_RegisterCleanup(void) { ...@@ -1202,7 +1206,7 @@ static int __Pyx_RegisterCleanup(void) {
if (!cleanup_func) if (!cleanup_func)
goto bad; goto bad;
atexit = __Pyx_ImportModule("atexit"); atexit = PyImport_ImportModule("atexit");
if (!atexit) if (!atexit)
goto bad; goto bad;
reg = PyObject_GetAttrString(atexit, "_exithandlers"); reg = PyObject_GetAttrString(atexit, "_exithandlers");
...@@ -1244,12 +1248,6 @@ bad: ...@@ -1244,12 +1248,6 @@ bad:
Py_XDECREF(res); Py_XDECREF(res);
return ret; return ret;
} }
#else
// fake call purely to work around "unused function" warning for __Pyx_ImportModule()
static int __Pyx_RegisterCleanup(void) {
(void)__Pyx_ImportModule; /* unused */
return 0;
}
#endif #endif
/////////////// FastGil.init /////////////// /////////////// FastGil.init ///////////////
......
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