summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2008-01-03 22:16:32 (GMT)
committerChristian Heimes <christian@cheimes.de>2008-01-03 22:16:32 (GMT)
commit000a074c955a1964959ee908300ef49b41170a06 (patch)
treeaf32b732d8b3285969bd524a4af25b6533adbb4c /Modules
parent0a83d79268e9d2b36decc78845cf71baced4ccc6 (diff)
downloadcpython-000a074c955a1964959ee908300ef49b41170a06.zip
cpython-000a074c955a1964959ee908300ef49b41170a06.tar.gz
cpython-000a074c955a1964959ee908300ef49b41170a06.tar.bz2
Modified PyImport_Import and PyImport_ImportModule to always use absolute imports by calling __import__ with an explicit level of 0
Added a new API function PyImport_ImportModuleNoBlock. It solves the problem with dead locks when mixing threads and imports
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_ctypes/callbacks.c4
-rw-r--r--Modules/_cursesmodule.c2
-rw-r--r--Modules/cjkcodecs/cjkcodecs.h2
-rw-r--r--Modules/datetimemodule.c8
-rw-r--r--Modules/gcmodule.c2
-rw-r--r--Modules/parsermodule.c2
-rw-r--r--Modules/posixmodule.c2
-rw-r--r--Modules/socketmodule.h2
-rw-r--r--Modules/timemodule.c4
-rw-r--r--Modules/zipimport.c2
10 files changed, 15 insertions, 15 deletions
diff --git a/Modules/_ctypes/callbacks.c b/Modules/_ctypes/callbacks.c
index 18af288..5362584 100644
--- a/Modules/_ctypes/callbacks.c
+++ b/Modules/_ctypes/callbacks.c
@@ -370,7 +370,7 @@ long Call_GetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
if (context == NULL)
context = PyString_FromString("_ctypes.DllGetClassObject");
- mod = PyImport_ImportModule("ctypes");
+ mod = PyImport_ImportModuleNoBlock("ctypes");
if (!mod) {
PyErr_WriteUnraisable(context ? context : Py_None);
/* There has been a warning before about this already */
@@ -449,7 +449,7 @@ long Call_CanUnloadNow(void)
if (context == NULL)
context = PyString_FromString("_ctypes.DllCanUnloadNow");
- mod = PyImport_ImportModule("ctypes");
+ mod = PyImport_ImportModuleNoBlock("ctypes");
if (!mod) {
/* OutputDebugString("Could not import ctypes"); */
/* We assume that this error can only occur when shutting
diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c
index e7c4bc1..a805b2d 100644
--- a/Modules/_cursesmodule.c
+++ b/Modules/_cursesmodule.c
@@ -2255,7 +2255,7 @@ static int
update_lines_cols(void)
{
PyObject *o;
- PyObject *m = PyImport_ImportModule("curses");
+ PyObject *m = PyImport_ImportModuleNoBlock("curses");
if (!m)
return 0;
diff --git a/Modules/cjkcodecs/cjkcodecs.h b/Modules/cjkcodecs/cjkcodecs.h
index 71c54f0..4005bcf 100644
--- a/Modules/cjkcodecs/cjkcodecs.h
+++ b/Modules/cjkcodecs/cjkcodecs.h
@@ -245,7 +245,7 @@ getmultibytecodec(void)
static PyObject *cofunc = NULL;
if (cofunc == NULL) {
- PyObject *mod = PyImport_ImportModule("_multibytecodec");
+ PyObject *mod = PyImport_ImportModuleNoBlock("_multibytecodec");
if (mod == NULL)
return NULL;
cofunc = PyObject_GetAttrString(mod, "__create_codec");
diff --git a/Modules/datetimemodule.c b/Modules/datetimemodule.c
index b94812b..83e547e 100644
--- a/Modules/datetimemodule.c
+++ b/Modules/datetimemodule.c
@@ -1305,7 +1305,7 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
if (_PyString_Resize(&newfmt, usednew) < 0)
goto Done;
{
- PyObject *time = PyImport_ImportModule("time");
+ PyObject *time = PyImport_ImportModuleNoBlock("time");
if (time == NULL)
goto Done;
result = PyObject_CallMethod(time, "strftime", "OO",
@@ -1353,7 +1353,7 @@ static PyObject *
time_time(void)
{
PyObject *result = NULL;
- PyObject *time = PyImport_ImportModule("time");
+ PyObject *time = PyImport_ImportModuleNoBlock("time");
if (time != NULL) {
result = PyObject_CallMethod(time, "time", "()");
@@ -1371,7 +1371,7 @@ build_struct_time(int y, int m, int d, int hh, int mm, int ss, int dstflag)
PyObject *time;
PyObject *result = NULL;
- time = PyImport_ImportModule("time");
+ time = PyImport_ImportModuleNoBlock("time");
if (time != NULL) {
result = PyObject_CallMethod(time, "struct_time",
"((iiiiiiiii))",
@@ -3827,7 +3827,7 @@ datetime_strptime(PyObject *cls, PyObject *args)
if (!PyArg_ParseTuple(args, "ss:strptime", &string, &format))
return NULL;
- if ((module = PyImport_ImportModule("time")) == NULL)
+ if ((module = PyImport_ImportModuleNoBlock("time")) == NULL)
return NULL;
obj = PyObject_CallMethod(module, "strptime", "ss", string, format);
Py_DECREF(module);
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c
index 0edf523..522cc89 100644
--- a/Modules/gcmodule.c
+++ b/Modules/gcmodule.c
@@ -1236,7 +1236,7 @@ initgc(void)
* the import and triggers an assertion.
*/
if (tmod == NULL) {
- tmod = PyImport_ImportModule("time");
+ tmod = PyImport_ImportModuleNoBlock("time");
if (tmod == NULL)
PyErr_Clear();
}
diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c
index 6c4a6ad..5764c24 100644
--- a/Modules/parsermodule.c
+++ b/Modules/parsermodule.c
@@ -3269,7 +3269,7 @@ initparser(void)
* If this fails, the import of this module will fail because an
* exception will be raised here; should we clear the exception?
*/
- copyreg = PyImport_ImportModule("copy_reg");
+ copyreg = PyImport_ImportModuleNoBlock("copy_reg");
if (copyreg != NULL) {
PyObject *func, *pickler;
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 85725f4..696df0d 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -5651,7 +5651,7 @@ wait_helper(int pid, int status, struct rusage *ru)
return posix_error();
if (struct_rusage == NULL) {
- PyObject *m = PyImport_ImportModule("resource");
+ PyObject *m = PyImport_ImportModuleNoBlock("resource");
if (m == NULL)
return NULL;
struct_rusage = PyObject_GetAttrString(m, "struct_rusage");
diff --git a/Modules/socketmodule.h b/Modules/socketmodule.h
index a4382ab..fb9ec67 100644
--- a/Modules/socketmodule.h
+++ b/Modules/socketmodule.h
@@ -222,7 +222,7 @@ int PySocketModule_ImportModuleAndAPI(void)
void *api;
DPRINTF("Importing the %s C API...\n", apimodule);
- mod = PyImport_ImportModule(apimodule);
+ mod = PyImport_ImportModuleNoBlock(apimodule);
if (mod == NULL)
goto onError;
DPRINTF(" %s package found\n", apimodule);
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
index 842ce94..5b4d210 100644
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -515,7 +515,7 @@ is not present, current time as returned by localtime() is used.");
static PyObject *
time_strptime(PyObject *self, PyObject *args)
{
- PyObject *strptime_module = PyImport_ImportModule("_strptime");
+ PyObject *strptime_module = PyImport_ImportModuleNoBlock("_strptime");
PyObject *strptime_result;
if (!strptime_module)
@@ -627,7 +627,7 @@ time_tzset(PyObject *self, PyObject *unused)
{
PyObject* m;
- m = PyImport_ImportModule("time");
+ m = PyImport_ImportModuleNoBlock("time");
if (m == NULL) {
return NULL;
}
diff --git a/Modules/zipimport.c b/Modules/zipimport.c
index fe5e1b0..dec6091 100644
--- a/Modules/zipimport.c
+++ b/Modules/zipimport.c
@@ -776,7 +776,7 @@ get_decompress_func(void)
let's avoid a stack overflow. */
return NULL;
importing_zlib = 1;
- zlib = PyImport_ImportModule("zlib"); /* import zlib */
+ zlib = PyImport_ImportModuleNoBlock("zlib");
importing_zlib = 0;
if (zlib != NULL) {
decompress = PyObject_GetAttrString(zlib,