summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-03-14 01:57:27 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-03-14 01:57:27 (GMT)
commit2e5f11aaa43a7a9af16eeacbae127819cd2189af (patch)
treeec6fdfbaf21689bf9d45d5d80e6aac0d771d13b0 /Python
parent41c5fecce0e20ac7ffd004afd1bda2b86e1b0460 (diff)
downloadcpython-2e5f11aaa43a7a9af16eeacbae127819cd2189af.zip
cpython-2e5f11aaa43a7a9af16eeacbae127819cd2189af.tar.gz
cpython-2e5f11aaa43a7a9af16eeacbae127819cd2189af.tar.bz2
Issue #3080: PyImport_ImportModuleNoBlock() uses Unicode
Diffstat (limited to 'Python')
-rw-r--r--Python/import.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/Python/import.c b/Python/import.c
index 00a9ecc..08237af 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -2591,8 +2591,7 @@ PyImport_ImportModule(const char *name)
PyObject *
PyImport_ImportModuleNoBlock(const char *name)
{
- PyObject *result;
- PyObject *modules;
+ PyObject *nameobj, *modules, *result;
long me;
/* Try to get the module from sys.modules[name] */
@@ -2600,14 +2599,16 @@ PyImport_ImportModuleNoBlock(const char *name)
if (modules == NULL)
return NULL;
- result = PyDict_GetItemString(modules, name);
+ nameobj = PyUnicode_FromString(name);
+ if (nameobj == NULL)
+ return NULL;
+ result = PyDict_GetItem(modules, nameobj);
if (result != NULL) {
+ Py_DECREF(nameobj);
Py_INCREF(result);
return result;
}
- else {
- PyErr_Clear();
- }
+ PyErr_Clear();
#ifdef WITH_THREAD
/* check the import lock
* me might be -1 but I ignore the error here, the lock function
@@ -2615,18 +2616,20 @@ PyImport_ImportModuleNoBlock(const char *name)
me = PyThread_get_thread_ident();
if (import_lock_thread == -1 || import_lock_thread == me) {
/* no thread or me is holding the lock */
- return PyImport_ImportModule(name);
+ result = PyImport_Import(nameobj);
}
else {
PyErr_Format(PyExc_ImportError,
- "Failed to import %.200s because the import lock"
+ "Failed to import %U because the import lock"
"is held by another thread.",
- name);
- return NULL;
+ nameobj);
+ result = NULL;
}
#else
- return PyImport_ImportModule(name);
+ result = PyImport_Import(nameobj);
#endif
+ Py_DECREF(nameobj);
+ return result;
}
/* Forward declarations for helper routines */