> So the check would look something like this: > > if (tstate->recursion_depth >= 50 && > tstate->recursion_depth%10 == 0 && > PyOS_CheckStack()) { > PyErr_SetString(PyExc_MemoryError, "Stack overflow"); > return NULL; > } That sounds like a good solution to me. A recursion depth of 50 should be guaranteed on most systems supported by Python. > I'm not exactly sure how large the safety margin is with > Martin's patch, but this seems a good idea. I chose 3% of the rlimit, which must accomodate the space above the known start of stack plus a single page. That number was chosen arbitarily; on my Linux system, the stack limit is 8MB, so 3% give 200k. Given the maximum limitation of environment pages and argv pages, I felt that this is safe enough. OTOH, if you've used more than 7MB of stack, it is likely that the last 200k won't help, either. Regards, Martin
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4