diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2011-03-14 19:54:52 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2011-03-14 19:54:52 (GMT) |
commit | fe93faf98c0866c20f05dc009a8ac2fecee80692 (patch) | |
tree | 42249c67dc2ec193951ddec2baf21823d50ce756 /Python/import.c | |
parent | 98dbba5d209dda5300df549ef26eb4646cb891f0 (diff) | |
download | cpython-fe93faf98c0866c20f05dc009a8ac2fecee80692.zip cpython-fe93faf98c0866c20f05dc009a8ac2fecee80692.tar.gz cpython-fe93faf98c0866c20f05dc009a8ac2fecee80692.tar.bz2 |
Issue #3080: Add PyImport_ImportModuleLevelObject() function
Use it for the builtin __import__ function.
Diffstat (limited to 'Python/import.c')
-rw-r--r-- | Python/import.c | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/Python/import.c b/Python/import.c index 6594447..7f9042a 100644 --- a/Python/import.c +++ b/Python/import.c @@ -2753,25 +2753,37 @@ import_module_level(PyObject *name, PyObject *globals, PyObject *locals, } PyObject * -PyImport_ImportModuleLevel(char *name, PyObject *globals, PyObject *locals, - PyObject *fromlist, int level) +PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals, + PyObject *locals, PyObject *fromlist, + int level) { - PyObject *nameobj, *result; - nameobj = PyUnicode_FromString(name); - if (nameobj == NULL) - return NULL; + PyObject *mod; _PyImport_AcquireLock(); - result = import_module_level(nameobj, globals, locals, fromlist, level); - Py_DECREF(nameobj); + mod = import_module_level(name, globals, locals, fromlist, level); if (_PyImport_ReleaseLock() < 0) { - Py_XDECREF(result); + Py_XDECREF(mod); PyErr_SetString(PyExc_RuntimeError, "not holding the import lock"); return NULL; } - return result; + return mod; +} + +PyObject * +PyImport_ImportModuleLevel(char *name, PyObject *globals, PyObject *locals, + PyObject *fromlist, int level) +{ + PyObject *nameobj, *mod; + nameobj = PyUnicode_FromString(name); + if (nameobj == NULL) + return NULL; + mod = PyImport_ImportModuleLevelObject(nameobj, globals, locals, + fromlist, level); + Py_DECREF(nameobj); + return mod; } + /* Return the package that an import is being performed in. If globals comes from the module foo.bar.bat (not itself a package), this returns the sys.modules entry for foo.bar. If globals is from a package's __init__.py, |