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

Thomas Wouters thomas@xs4all.net
Tue, 29 Aug 2000 23:43:29 +0200


On Tue, Aug 29, 2000 at 04:05:21PM -0500, Charles G Waldman wrote:

> Jeremy Hylton writes:
>  > Does anyone have suggestions for how to detect unbounded recursion in
>  > the Python core on Unix platforms?

> Hey, check this out! - it's not portable in general, but it works for Linux,
> which certainly covers a large number of the systems out there in the world.

'large' in terms of "number of instances", perhaps, but not very large in
terms of total number of operating system types/versions, I think. I know of
two operating systems that implement that info in /proc (FreeBSD and Linux)
and one where it's optional (but default off and probably untested: BSDI.) I
also think that this is a very costly thing to do every ten (or even every
hundred) recursions.... I would go for the auto-vrbl-address-check, in
combination with either a fixed stack limit, or getrlimit() - which does
seem to work. Or perhaps the alloca() check for systems that have it (which
can be checked) and seems to work properly (which can be checked, too, but
not as reliable.)

The vrbl-address check only does a few integer calculations, and we can
forgo the getrlimit() call if we do it somewhere during Python init, and
after every call of resource.setrlimit(). (Or just do it anyway: it's
probably not *that* expensive, and if we don't do it each time, we can still
run into trouble if another extention module sets limits, or if python is
embedded in something that changes limits on the fly.)

-- 
Thomas Wouters <thomas@xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!