[Python-Dev] Preventing recursion core dumps

Vladimir Marangozov Vladimir.Marangozov@inrialpes.fr
Fri, 11 Aug 2000 16:32:45 +0200 (CEST)


Moshe Zadka wrote:
> 
> On Fri, 11 Aug 2000, Guido van Rossum wrote:
> 
> > It would be good if there was a way to sense the remaining available
> > stack, even if it wasn't portable.  Any Linux experts out there?
> 
> I'm far from an expert, but I might have an idea. The question is: must
> this works for embedded version of Python, or can I fool around with
> main()?

Probably not main(), but Py_Initialize() for sure.

> 
> Here's the approach:
> 
>  - In main(), get the address of some local variable. Call this
>         min
>  - Call getrlimit, and see the stack size. Call max = min+ (<stack size )
>  - When checking for "too much recursion", take the address of a local 
>    variable and compare it against max. If it's higher, stop.

Sounds good. If getrlimit is not available, we can always fallback to
some (yet to be computed) constant, i.e. the current state.

[Just]
> Gordon, how's that Stackless PEP coming along?
> Sorry, I couldn't resist ;-)

Ah, in this case, we'll get a memory error after filling the whole disk
with frames <wink>

-- 
       Vladimir MARANGOZOV          | Vladimir.Marangozov@inrialpes.fr
http://sirac.inrialpes.fr/~marangoz | tel:(+33-4)76615277 fax:76615252