[Python-Dev] PyOS_CheckStack for windows

Fredrik Lundh Fredrik Lundh" <effbot@telia.com
Tue, 15 Aug 2000 21:11:11 +0200


trent wrote:
> This test on Win32 and Linux32 hits the recursion limit check of 10000 in
> SRE_MATCH(). However, on Linux64 the segfault occurs at a recursion depth of
> 7500. I don't want to just willy-nilly drop the recursion limit down to make
> the problem go away.

SRE is overflowing the stack, of course :-(

:::

I spent a little time surfing around on the MSDN site, and came
up with the following little PyOS_CheckStack implementation for
Visual C (and compatibles):

#include <malloc.h>

int __inline
PyOS_CheckStack()
{
    __try {
        /* alloca throws a stack overflow exception if there's less
           than 2k left on the stack */
        alloca(2000);
        return 0;
    } __except (1) {
        /* just ignore the error */
    }
    return 1;
}

a quick look at the resulting assembler code indicates that this
should be pretty efficient (some exception-related stuff, and a
call to an internal stack probe function), but I haven't added it
to the interpreter (and I don't have time to dig deeper into this
before the weekend).

maybe someone else has a little time to spare?

it shouldn't be that hard to figure out 1) where to put this, 2) what
ifdef's to use around it, and 3) what "2000" should be changed to...

(and don't forget to set USE_STACKCHECK)

</F>