Skip to content

Commit a4ffb9e

Browse files
Apply suggestions from code review
Co-authored-by: Brett Cannon <[email protected]>
1 parent 8e14dad commit a4ffb9e

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

InternalDocs/stack_protection.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
CPython protects against stack overflow in the form of runaway, or just very deep, recursion by raising a `RecursionError` instead of just crashing.
44
Protection against pure Python stack recursion has existed since very early, but in 3.12 we added protection against stack overflow
55
in C code. This was initially implemented using a counter and later improved in 3.14 to use the actual stack depth.
6-
For those platforms that support it (Windows, Mac, and most linuxes) we query the operating system to find the stack bounds.
6+
For those platforms that support it (Windows, Mac, and most Linuxes) we query the operating system to find the stack bounds.
77
For other platforms we use conserative estimates.
88

99

@@ -36,16 +36,15 @@ The soft and hard limits pointers are set by calling `_Py_InitializeRecursionLim
3636

3737
Recursion checks are performed by `_Py_EnterRecursiveCall()` or `_Py_EnterRecursiveCallTstate()` which compare the stack pointer to the soft limit. If the stack pointer is lower than the soft limit, then `_Py_CheckRecursiveCall()` is called which checks against both the hard and soft limits:
3838

39-
```Py
39+
```python
4040
kb_used = (stack_top - stack_pointer)>>10
4141
if stack_pointer < hard_limit:
4242
FatalError(f"Unrecoverable stack overflow (used {kb_used} kB)")
4343
elif stack_pointer < soft_limit:
4444
raise RecursionError(f"Stack overflow (used {kb_used} kB)")
4545
```
4646

47-
### Diagnosing and fixing stack overflows.
48-
47+
### Diagnosing and fixing stack overflows
4948

5049
For stack protection to work correctly the amount of stack consumed between calls to `_Py_EnterRecursiveCall()` must be less than `_PyOS_STACK_MARGIN_BYTES`.
5150

0 commit comments

Comments
 (0)