[Python-Dev] stack check on Unix: any suggestions?
Fredrik Lundh
Fredrik Lundh" <effbot@telia.com
Wed, 30 Aug 2000 12:27:12 +0200
mal wrote:
> See my comments in the patch manager... the patch looks fine
> except for two things: getrlimit() should be tested for
> usability in the configure script and the call frequency
> of PyOS_CheckStack() should be lowered to only use it for
> potentially recursive programs.
the latter would break windows and mac versions of Python,
where Python can run on very small stacks (not to mention
embedded systems...)
for those platforms, CheckStack is designed to work with an
8k safety margin (PYOS_STACK_MARGIN)
:::
one way to address this is to introduce a scale factor, so that
you can add checks based on the default 8k limit, but auto-
magically apply them less often platforms where the safety
margin is much larger...
/* checkstack, but with a "scale" factor */
#if windows or mac
/* default safety margin */
#define PYOS_CHECKSTACK(v, n)\
(((v) % (n) == 0) && PyOS_CheckStack())
#elif linux
/* at least 10 times the default safety margin */
#define PYOS_CHECKSTACK(v, n)\
(((v) % ((n)*10) == 0) && PyOS_CheckStack())
#endif
if (PYOS_CHECKSTACK(tstate->recursion_depth, 10)
...
</F>