diff options
author | Mark Hammond <mhammond@skippinet.com.au> | 2003-02-19 00:33:33 (GMT) |
---|---|---|
committer | Mark Hammond <mhammond@skippinet.com.au> | 2003-02-19 00:33:33 (GMT) |
commit | a43fd0c8996eec2bdd0ec59edc252cb4f4ff4436 (patch) | |
tree | a77757f7e42f4a6caa040e93d393215f54541d50 /Python | |
parent | 4ccf3e14f017d7314bc9cbc44ad6a0eec417e437 (diff) | |
download | cpython-a43fd0c8996eec2bdd0ec59edc252cb4f4ff4436.zip cpython-a43fd0c8996eec2bdd0ec59edc252cb4f4ff4436.tar.gz cpython-a43fd0c8996eec2bdd0ec59edc252cb4f4ff4436.tar.bz2 |
Fix bug 683658 - PyErr_Warn may cause import deadlock.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/errors.c | 9 | ||||
-rw-r--r-- | Python/pythonrun.c | 11 |
2 files changed, 15 insertions, 5 deletions
diff --git a/Python/errors.c b/Python/errors.c index e509606..d08c1af 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -600,18 +600,17 @@ PyErr_WriteUnraisable(PyObject *obj) Py_XDECREF(tb); } +extern PyObject *PyModule_WarningsModule; /* Function to issue a warning message; may raise an exception. */ int PyErr_Warn(PyObject *category, char *message) { - PyObject *mod, *dict, *func = NULL; + PyObject *dict, *func = NULL; - mod = PyImport_ImportModule("warnings"); - if (mod != NULL) { - dict = PyModule_GetDict(mod); + if (PyModule_WarningsModule != NULL) { + dict = PyModule_GetDict(PyModule_WarningsModule); func = PyDict_GetItemString(dict, "warn"); - Py_DECREF(mod); } if (func == NULL) { PySys_WriteStderr("warning: %s\n", message); diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 1faab50..2845d24 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -60,6 +60,11 @@ int Py_IgnoreEnvironmentFlag; /* e.g. PYTHONPATH, PYTHONHOME */ true divisions (which they will be in 2.3). */ int _Py_QnewFlag = 0; +/* Reference to 'warnings' module, to avoid importing it + on the fly when the import lock may be held. See 683658 +*/ +PyObject *PyModule_WarningsModule = NULL; + static int initialized = 0; /* API to access the initialized flag -- useful for esoteric use */ @@ -169,6 +174,8 @@ Py_Initialize(void) _PyImportHooks_Init(); + PyModule_WarningsModule = PyImport_ImportModule("warnings"); + initsigs(); /* Signal handling stuff, including initintr() */ initmain(); /* Module __main__ */ @@ -225,6 +232,10 @@ Py_Finalize(void) /* Cleanup Codec registry */ _PyCodecRegistry_Fini(); + /* drop module references we saved */ + Py_XDECREF(PyModule_WarningsModule); + PyModule_WarningsModule = NULL; + /* Destroy all modules */ PyImport_Cleanup(); |