"Martin v. Loewis" wrote:
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.
Jeremy: Could get at least this patch into 2.0b1 ?
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.
Looks like I don't have any limits set on my dev-machine... Linux has no problems offering me 3GB of (virtual) stack space even though it only has 64MB real memory and 200MB swap space available ;-) I guess the proposed user settable recursion depth limit is the best way to go. Testing for the right limit is rather easy by doing some trial and error processing using Python. At least for my Linux installation a limit of 9000 seems reasonable. Perhaps everybody on the list could do a quick check on their platform ? Here's a sample script: i = 0 def foo(x): global i print i i = i + 1 foo(x) foo(None) -- Marc-Andre Lemburg ______________________________________________________________________ Business: http://www.lemburg.com/ Python Pages: http://www.lemburg.com/python/