summaryrefslogtreecommitdiffstats
path: root/Python/_warnings.c
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2010-10-24 15:11:22 (GMT)
committerGeorg Brandl <georg@python.org>2010-10-24 15:11:22 (GMT)
commit08be72d0aa0112118b79d271479598c218adfd23 (patch)
tree5c885e7f573248c725915ed00f4a0476daa7a556 /Python/_warnings.c
parent872a702bbd3c471278e07d773f7a5a49eb9dc5b2 (diff)
downloadcpython-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/_warnings.c')
-rw-r--r--Python/_warnings.c22
1 files changed, 19 insertions, 3 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);