Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(9)

Unified Diff: Include/ceval.h

Issue 3276: Stack overflow checking dysfunctional with USE_STACKCHECK (Closed) SVN Base: http://svn.python.org/view/*checkout*/python/branches/py3k/
Patch Set: Created 1 year, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side by-side-diff with in-line comments
Download patch
« no previous file | Python/ceval.c » ('j') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Include/ceval.h
===================================================================
--- Include/ceval.h (revision 66050)
+++ Include/ceval.h (working copy)
@@ -46,22 +46,34 @@
PyAPI_FUNC(void) Py_SetRecursionLimit(int);
PyAPI_FUNC(int) Py_GetRecursionLimit(void);
-#define Py_EnterRecursiveCall(where) \
+#define Py_EnterRecursiveCall(where) \
(_Py_MakeRecCheck(PyThreadState_GET()->recursion_depth) && \
_Py_CheckRecursiveCall(where))
#define Py_LeaveRecursiveCall() \
- do{ if((--PyThreadState_GET()->recursion_depth) < \
- _Py_CheckRecursionLimit - 50) \
- PyThreadState_GET()->overflowed = 0; \
- } while(0)
+ do{ if(_Py_MakeEndRecCheck(PyThreadState_GET()->recursion_depth)) \
+ PyThreadState_GET()->overflowed = 0; \
+ } while(0)
PyAPI_FUNC(int) _Py_CheckRecursiveCall(char *where);
PyAPI_DATA(int) _Py_CheckRecursionLimit;
+
#ifdef USE_STACKCHECK
-# define _Py_MakeRecCheck(x) (++(x) > --_Py_CheckRecursionLimit)
+/* With USE_STACKCHECK, we artificially decrement the recursion limit in order
+ to trigger regular stack checks in _Py_CheckRecursiveCall(), except if
+ the "overflowed" flag is set, in which case we need the true value
+ of _Py_CheckRecursionLimit for _Py_MakeEndRecCheck() to function properly.
+*/
+# define _Py_MakeRecCheck(x) \
+ (++(x) > (_Py_CheckRecursionLimit += PyThreadState_GET()->overflowed - 1))
#else
# define _Py_MakeRecCheck(x) (++(x) > _Py_CheckRecursionLimit)
#endif
+#ifdef USE_STACKCHECK
+# define _Py_MakeEndRecCheck(x) (--(x) < _Py_CheckRecursionLimit - 50)
+#else
+# define _Py_MakeEndRecCheck(x) (--(x) < _Py_CheckRecursionLimit - 50)
+#endif
+
#define Py_ALLOW_RECURSION \
do { unsigned char _old = PyThreadState_GET()->recursion_critical;\
PyThreadState_GET()->recursion_critical = 1;
« no previous file | Python/ceval.c » ('j')

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld r483