I'm not clear on how you plan to implement this in CPython.

I can totally see that if a Python function calls another Python function,
you can avoid the C stack frame and hence you can have as many Python call
levels as you want.

However, there are many scenarios where a Python function calls a C
function (e.g. `filter()`, or `dict.__setitem__()`) and that C function at
some point calls a Python function (e.g. the `__hash__()` method of the
key, or even the `__del__()` method of the value being replaced). Then that
Python function can recursively do a similar thing.

Are you proposing to also support that kind of thing to go on for a million
levels of C stack frames?

(Do we even have a cross-platform way of avoiding segfaults due to C stack
overflow?)

On Tue, Jan 19, 2021 at 5:38 AM Mark Shannon <m...@hotpy.org> wrote:

> Hi everyone,
>
> It's time for yet another PEP :)
>
> Fortunately, this one is a small one that doesn't change much.
> It's aim is to make the VM more robust.
>
> Abstract
> ========
>
> This PEP proposes that machine stack overflow is treated differently
> from runaway recursion. This would allow programs to set the maximum
> recursion depth to fit their needs and provide additional safety
> guarantees.
>
> The following program will run safely to completion:
>
>      sys.setrecursionlimit(1_000_000)
>
>      def f(n):
>          if n:
>              f(n-1)
>
>      f(500_000)
>
> The following program will raise a StackOverflow, without causing a VM
> crash:
>
>      sys.setrecursionlimit(1_000_000)
>
>      class X:
>          def __add__(self, other):
>              return self + other
>
>      X() + 1
>
> -----------
>
> The full PEP can be found here:
> https://www.python.org/dev/peps/pep-0651
>
> As always, comments are welcome.
>
> Cheers,
> Mark.
> _______________________________________________
> Python-Dev mailing list -- python-dev@python.org
> To unsubscribe send an email to python-dev-le...@python.org
> https://mail.python.org/mailman3/lists/python-dev.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-dev@python.org/message/ZY32N43YZJM3WYXSVD7OCGVNDGPR6DUM/
> Code of Conduct: http://python.org/psf/codeofconduct/
>


-- 
--Guido van Rossum (python.org/~guido)
*Pronouns: he/him **(why is my pronoun here?)*
<http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/KQLHJY3CDWK42T5GTCB6QYIH4J3TGNCT/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to