[Python-Dev] stack check on Unix: any suggestions?

Martin v. Loewis martin@loewis.home.cs.tu-berlin.de
Wed, 30 Aug 2000 20:32:30 +0200


> 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