summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2016-03-19 00:03:51 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2016-03-19 00:03:51 (GMT)
commit914cde89d4c94b0b9206d0fa22322a1142833a56 (patch)
tree7eed294f0da18437f719df470dbee278cfb40787 /Modules
parent1231a4615fd447f0988a72a134a1fc5e7d4e8d69 (diff)
downloadcpython-914cde89d4c94b0b9206d0fa22322a1142833a56.zip
cpython-914cde89d4c94b0b9206d0fa22322a1142833a56.tar.gz
cpython-914cde89d4c94b0b9206d0fa22322a1142833a56.tar.bz2
On ResourceWarning, log traceback where the object was allocated
Issue #26567: * Add a new function PyErr_ResourceWarning() function to pass the destroyed object * Add a source attribute to warnings.WarningMessage * Add warnings._showwarnmsg() which uses tracemalloc to get the traceback where source object was allocated.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_io/fileio.c3
-rw-r--r--Modules/posixmodule.c4
-rw-r--r--Modules/socketmodule.c3
3 files changed, 4 insertions, 6 deletions
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c
index 8bf3922..a02a9c1 100644
--- a/Modules/_io/fileio.c
+++ b/Modules/_io/fileio.c
@@ -92,8 +92,7 @@ fileio_dealloc_warn(fileio *self, PyObject *source)
if (self->fd >= 0 && self->closefd) {
PyObject *exc, *val, *tb;
PyErr_Fetch(&exc, &val, &tb);
- if (PyErr_WarnFormat(PyExc_ResourceWarning, 1,
- "unclosed file %R", source)) {
+ if (PyErr_ResourceWarning(source, 1, "unclosed file %R", source)) {
/* Spurious errors can appear at shutdown */
if (PyErr_ExceptionMatches(PyExc_Warning))
PyErr_WriteUnraisable((PyObject *) self);
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 65b20be..3f22d14 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -12111,8 +12111,8 @@ ScandirIterator_dealloc(ScandirIterator *iterator)
*/
++Py_REFCNT(iterator);
PyErr_Fetch(&exc, &val, &tb);
- if (PyErr_WarnFormat(PyExc_ResourceWarning, 1,
- "unclosed scandir iterator %R", iterator)) {
+ if (PyErr_ResourceWarning((PyObject *)iterator, 1,
+ "unclosed scandir iterator %R", iterator)) {
/* Spurious errors can appear at shutdown */
if (PyErr_ExceptionMatches(PyExc_Warning))
PyErr_WriteUnraisable((PyObject *) iterator);
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 77a6b31..657b04b 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -4170,8 +4170,7 @@ sock_dealloc(PySocketSockObject *s)
Py_ssize_t old_refcount = Py_REFCNT(s);
++Py_REFCNT(s);
PyErr_Fetch(&exc, &val, &tb);
- if (PyErr_WarnFormat(PyExc_ResourceWarning, 1,
- "unclosed %R", s))
+ if (PyErr_ResourceWarning(s, 1, "unclosed %R", s))
/* Spurious errors can appear at shutdown */
if (PyErr_ExceptionMatches(PyExc_Warning))
PyErr_WriteUnraisable((PyObject *) s);