Xavier de Gaye added the comment:

> Why recursion limit is restored? Couldn't the test be simpler without it?

For the sake of explicitness, so that the interpreter will not raise a 
RuntimeError during finalization when checking for the recursion limit after 
g.throw(MyException) has raised PyExc_RecursionErrorInst.


> %a should be used instead of '%s' (file path can contain backslashes).
> And it would be more robust to open file in binary mode (may be even in 
> non-buffered). It can contain non-ascii characters.
> May be the test should be marked as CPython only.
> To check that script is executed at all we should print something from it and 
> than test the out. Otherwise syntax error in script will make all test passed.

Thanks.
New patch attached.

The reason why the PyExc_RecursionErrorInst singleton keeps the frames alive 
longer than expected is that the reference count of the 
PyExc_RecursionErrorInst static variable never reaches zero until 
_PyExc_Fini().  So decrementing the reference count of this exception after the 
traceback has been printed in PyErr_PrintEx() does not decrement the reference 
count of its traceback attribute (as it is the case with the other exceptions) 
and the traceback is not freed. The following patch to PyErr_PrintEx() does 
that.  With this new patch and without the changes made by warn_4.patch, the 
interpreter does not crash with the runtimerror_singleton_2.py reproducer and 
the ResourceWarning is now printed instead of being ignored as with the 
warn_4.patch:

diff --git a/Python/pythonrun.c b/Python/pythonrun.c
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -1876,6 +1876,8 @@
         PyErr_Display(exception, v, tb);
     }
     Py_XDECREF(exception);
+    if (v == PyExc_RecursionErrorInst)
+        Py_CLEAR(((PyBaseExceptionObject *)v)->traceback);
     Py_XDECREF(v);
     Py_XDECREF(tb);
 }

If both patches were to be included, the test case in warn_4.patch would test 
the above patch and not the changes made in Python/_warnings.c.

----------
Added file: http://bugs.python.org/file37288/warn_4.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue22898>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to