diff options
author | Georg Brandl <georg@python.org> | 2010-10-24 15:11:22 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2010-10-24 15:11:22 (GMT) |
commit | 08be72d0aa0112118b79d271479598c218adfd23 (patch) | |
tree | 5c885e7f573248c725915ed00f4a0476daa7a556 /Python | |
parent | 872a702bbd3c471278e07d773f7a5a49eb9dc5b2 (diff) | |
download | cpython-08be72d0aa0112118b79d271479598c218adfd23.zip cpython-08be72d0aa0112118b79d271479598c218adfd23.tar.gz cpython-08be72d0aa0112118b79d271479598c218adfd23.tar.bz2 |
Add a new warning gategory, ResourceWarning, as discussed on python-dev. It is silent by default,
except when configured --with-pydebug.
Emit this warning from the GC shutdown procedure, rather than just printing to stderr.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/_warnings.c | 22 | ||||
-rw-r--r-- | Python/errors.c | 6 |
2 files changed, 23 insertions, 5 deletions
diff --git a/Python/_warnings.c b/Python/_warnings.c index a4e9d48..87755e1 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -835,6 +835,7 @@ create_filter(PyObject *category, const char *action) static PyObject *ignore_str = NULL; static PyObject *error_str = NULL; static PyObject *default_str = NULL; + static PyObject *always_str = NULL; PyObject *action_obj = NULL; PyObject *lineno, *result; @@ -862,6 +863,14 @@ create_filter(PyObject *category, const char *action) } action_obj = default_str; } + else if (!strcmp(action, "always")) { + if (always_str == NULL) { + always_str = PyUnicode_InternFromString("always"); + if (always_str == NULL) + return NULL; + } + action_obj = always_str; + } else { Py_FatalError("unknown action"); } @@ -879,10 +888,10 @@ static PyObject * init_filters(void) { /* Don't silence DeprecationWarning if -3 was used. */ - PyObject *filters = PyList_New(4); + PyObject *filters = PyList_New(5); unsigned int pos = 0; /* Post-incremented in each use. */ unsigned int x; - const char *bytes_action; + const char *bytes_action, *resource_action; if (filters == NULL) return NULL; @@ -901,7 +910,14 @@ init_filters(void) bytes_action = "ignore"; PyList_SET_ITEM(filters, pos++, create_filter(PyExc_BytesWarning, bytes_action)); - + /* resource usage warnings are enabled by default in pydebug mode */ +#ifdef Py_DEBUG + resource_action = "always"; +#else + resource_action = "ignore"; +#endif + PyList_SET_ITEM(filters, pos++, create_filter(PyExc_ResourceWarning, + resource_action)); for (x = 0; x < pos; x += 1) { if (PyList_GET_ITEM(filters, x) == NULL) { Py_DECREF(filters); diff --git a/Python/errors.c b/Python/errors.c index e3486b9..0490614 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -767,8 +767,10 @@ PyErr_WriteUnraisable(PyObject *obj) } Py_XDECREF(moduleName); } - PyFile_WriteString(" in ", f); - PyFile_WriteObject(obj, f, 0); + if (obj) { + PyFile_WriteString(" in ", f); + PyFile_WriteObject(obj, f, 0); + } PyFile_WriteString(" ignored\n", f); PyErr_Clear(); /* Just in case */ } |