-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement stack overflow protection for supported platforms #91079
Comments
python/steering-council#102 (definitely not PEP-651 ;)) We should implement efficient stack checks on those platforms that allow us to introspect stack extents. C allows addresses of stack variables to be taken. This means that C stacks cannot be moved. My plan is to maintain a per-thread "safe region" of 32or 64k. We can check if the current stack pointer (or near enough) is in that region cheaply. Personally I'd prefer a new exception |
+1 on a new exception (presumably a subclass of MemoryError). How about using OverflowedStack instead? The situation is not quite as bad as you suggest. Googling for "stack overflow" alone (with a space and no other qualifications):
I expect that going forward, "python stack overflow exception" will be sufficient to hit the Python docs somewhere on the first page. Besides, presumably this OverflowedStack exception is likely to be rare, so I expect that few people will need to google it. |
bpo-33955 is an older issue about implementing the current functionality for this on macOS, which has an API for querying stack limits. |
It looks like The use of So, I think the way to go is to add two subclasses of Another reason for making them both subclasses of Given that we are subclassing Portability of stack overflows.Since we do not use the C stack for Python recursion, and we will hopefully modify the compiler to use less stack, we could reduce the amount of C stack available on linux to more closely match Windows, increasing the portability of code. Code that raises a |
I'm not sure we should differentiate at the Exception class level between C and Py |
I don't recommend this. It would break someones code that is working just fine in their existing environment who has no interest in other environments. A nicer long term consistent goal would be to allow RecursionError to be eliminated for pure Python recursion entirely by those who want to turn off our default limit. (ultimately they'd hit a MemoryError if their process wasn't OOM killed) |
OK. Let's reuse
Eliminating recursion limits is probably a bad idea, we need memory to build all those frame objects and traceback objects. |
|
Symbols of the C API should be prefixed by "Py_" to avoid conflict with existing names in 3rd party C extensions on #include <Python.h>.
Symbols of the C API should be prefixed by "Py_" to avoid conflict with existing names in 3rd party C extensions on #include <Python.h>.
Symbols of the C API should be prefixed by "Py_" to avoid conflict with existing names in 3rd party C extensions on "#include <Python.h>". test.pythoninfo now logs Py_C_RECURSION_LIMIT constant and other _testcapi and _testinternalcapi constants.
Having the c recursion limit being constant seems like a pretty major blunder imo, this code has no reason to fail import sys
sys.setrecursionlimit(1_000_000)
class funner:
def __call__(𝕊, x):
if x:
𝕊(x-1)
funner()(498) # works
funner()(499) # fails |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs
The text was updated successfully, but these errors were encountered: