This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Probable extra semicolon in Py_LeaveRecursiveCall macro
Type: Stage:
Components: Interpreter Core Versions: Python 3.0
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: loewis Nosy List: amaury.forgeotdarc, loewis, orivej
Priority: high Keywords:

Created on 2007-12-11 21:40 by amaury.forgeotdarc, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg58468 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2007-12-11 21:40
In file ceval.h, the macro Py_LeaveRecursiveCall is defined like this:

#define Py_LeaveRecursiveCall()				\
    do{ if((--PyThreadState_GET()->recursion_depth) <   \
	   _Py_CheckRecursionLimit - 50);               \
	  PyThreadState_GET()->overflowed = 0;          \
    } while(0)

The semicolon on the third line seems very suspicious to me: the if()
statement has no side effect, and "overflowed" is always reset to zero.

I don't really understand the consequences, though. The variable seems
to be used as an additional protection against C code that does not
correctly unwind when the recursion limit is hit.
msg58471 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2007-12-11 22:07
I think you are right - that's a bug. As a consequence, overflowed would
be cleared less often than it is now, which in turn may cause a fatal
abort in case it fails to recover from a stack overflow (i.e. if it
consumes another 50 stack frames, instead of unwinding).

This entire machinery is there to guard against hard-to-analyze crashes
resulting from stack overflows, in particular when a dictionary lookup
happened to cause a stack overflow. The overflow would raise the Python
exception, which would then be cleared in the dictionary lookup, as if
nothing happened.
msg62330 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2008-02-12 19:30
Thanks again for pointing that out. Fixed in r60750.
Date User Action Args
2022-04-11 14:56:28adminsetgithub: 45936
2008-02-12 19:30:56loewissetstatus: open -> closed
resolution: fixed
messages: + msg62330
2008-01-29 17:21:01orivejsetnosy: + orivej
2008-01-06 22:29:44adminsetkeywords: - py3k
versions: Python 3.0
2008-01-05 22:12:41christian.heimessetpriority: high
2007-12-11 22:07:44loewissetmessages: + msg58471
2007-12-11 21:40:48amaury.forgeotdarccreate