diff options
author | Brett Cannon <bcannon@gmail.com> | 2009-04-01 18:13:07 (GMT) |
---|---|---|
committer | Brett Cannon <bcannon@gmail.com> | 2009-04-01 18:13:07 (GMT) |
commit | 0759dd66c581a65381412a2ff98dac8edd58ddee (patch) | |
tree | 92ac5c8ad7f4758201b70d4ecaf5b9888b21b38c /Python | |
parent | 86fe876fb5ce8520d915e7b3fa738cb2a09c859d (diff) | |
download | cpython-0759dd66c581a65381412a2ff98dac8edd58ddee.zip cpython-0759dd66c581a65381412a2ff98dac8edd58ddee.tar.gz cpython-0759dd66c581a65381412a2ff98dac8edd58ddee.tar.bz2 |
Merged revisions 70965 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r70965 | brett.cannon | 2009-04-01 11:03:59 -0700 (Wed, 01 Apr 2009) | 5 lines
_warnings was importing itself to get an attribute. That's bad if warnings gets
called in a thread that was spawned by an import itself.
Last part to close #1665206.
........
Diffstat (limited to 'Python')
-rw-r--r-- | Python/_warnings.c | 46 |
1 files changed, 30 insertions, 16 deletions
diff --git a/Python/_warnings.c b/Python/_warnings.c index 43e6b80..da52e35 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -2,7 +2,6 @@ #include "frameobject.h" #define MODULE_NAME "_warnings" -#define DEFAULT_ACTION_NAME "default_action" PyDoc_STRVAR(warnings__doc__, MODULE_NAME " provides basic warning filtering support.\n" @@ -12,6 +11,7 @@ MODULE_NAME " provides basic warning filtering support.\n" get_warnings_attr() will reset these variables accordingly. */ static PyObject *_filters; /* List */ static PyObject *_once_registry; /* Dict */ +static PyObject *_default_action; /* String */ static int @@ -78,12 +78,31 @@ get_once_registry(void) } +static PyObject * +get_default_action(void) +{ + PyObject *default_action; + + default_action = get_warnings_attr("defaultaction"); + if (default_action == NULL) { + if (PyErr_Occurred()) { + return NULL; + } + return _default_action; + } + + Py_DECREF(_default_action); + _default_action = default_action; + return default_action; +} + + /* The item is a borrowed reference. */ static const char * get_filter(PyObject *category, PyObject *text, Py_ssize_t lineno, PyObject *module, PyObject **item) { - PyObject *action, *m, *d; + PyObject *action; Py_ssize_t i; PyObject *warnings_filters; @@ -135,22 +154,17 @@ get_filter(PyObject *category, PyObject *text, Py_ssize_t lineno, return _PyUnicode_AsString(action); } - m = PyImport_ImportModule(MODULE_NAME); - if (m == NULL) - return NULL; - d = PyModule_GetDict(m); - Py_DECREF(m); - if (d == NULL) - return NULL; - action = PyDict_GetItemString(d, DEFAULT_ACTION_NAME); - if (action != NULL) + action = get_default_action(); + if (action != NULL) { return _PyUnicode_AsString(action); + } PyErr_SetString(PyExc_ValueError, - MODULE_NAME "." DEFAULT_ACTION_NAME " not found"); + MODULE_NAME ".defaultaction not found"); return NULL; } + static int already_warned(PyObject *registry, PyObject *key, int should_set) { @@ -874,7 +888,7 @@ static struct PyModuleDef warningsmodule = { PyMODINIT_FUNC _PyWarnings_Init(void) { - PyObject *m, *default_action; + PyObject *m; m = PyModule_Create(&warningsmodule); if (m == NULL) @@ -894,10 +908,10 @@ _PyWarnings_Init(void) if (PyModule_AddObject(m, "once_registry", _once_registry) < 0) return NULL; - default_action = PyUnicode_InternFromString("default"); - if (default_action == NULL) + _default_action = PyUnicode_FromString("default"); + if (_default_action == NULL) return NULL; - if (PyModule_AddObject(m, DEFAULT_ACTION_NAME, default_action) < 0) + if (PyModule_AddObject(m, "default_action", _default_action) < 0) return NULL; return m; } |