Skip to content

Commit 9654790

Browse files
committed
Tidy up a bit
1 parent c4cd68f commit 9654790

File tree

4 files changed

+4
-28
lines changed

4 files changed

+4
-28
lines changed

Doc/c-api/exceptions.rst

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -921,11 +921,7 @@ because the :ref:`call protocol <call>` takes care of recursion handling.
921921
922922
Marks a point where a recursive C-level call is about to be performed.
923923
924-
If :c:macro:`!USE_STACKCHECK` is defined, this function checks if the OS
925-
stack overflowed using :c:func:`PyOS_CheckStack`. If this is the case, it
926-
sets a :exc:`MemoryError` and returns a nonzero value.
927-
928-
The function then checks if the recursion limit is reached. If this is the
924+
The function then checks if the stack limit is reached. If this is the
929925
case, a :exc:`RecursionError` is set and a nonzero value is returned.
930926
Otherwise, zero is returned.
931927

Include/pythonrun.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ PyAPI_DATA(int) (*PyOS_InputHook)(void);
3333
#define PYOS_STACK_MARGIN_BYTES (PYOS_STACK_MARGIN * sizeof(void *))
3434

3535
#if defined(WIN32)
36-
/* Enable stack checking under Microsoft C */
37-
// When changing the platforms, ensure PyOS_CheckStack() docs are still correct
3836
#define USE_STACKCHECK
3937
#endif
4038

Python/ceval.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,13 +337,11 @@ _Py_EnterRecursiveCallUnchecked(PyThreadState *tstate)
337337
#elif defined(__ANDROID__)
338338
# define Py_C_STACK_SIZE 1200000
339339
#elif defined(__sparc__)
340-
// test_descr crashed on sparc64 with >7000 but let's keep a margin of error.
341340
# define Py_C_STACK_SIZE 1600000
342341
#elif defined(__wasi__)
343342
/* Web assembly has two stacks, so this isn't really the stack depth */
344343
# define Py_C_STACK_SIZE 100000
345344
#elif defined(__hppa__) || defined(__powerpc64__)
346-
// test_descr crashed with >8000 but let's keep a margin of error.
347345
# define Py_C_STACK_SIZE 2000000
348346
#else
349347
# define Py_C_STACK_SIZE 5000000

Python/pythonrun.c

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,37 +1528,21 @@ _Py_SourceAsString(PyObject *cmd, const char *funcname, const char *what, PyComp
15281528
}
15291529

15301530
#if defined(USE_STACKCHECK)
1531-
#if defined(WIN32) && defined(_MSC_VER)
15321531

1533-
/* Stack checking for Microsoft C */
1534-
1535-
#include <malloc.h>
1536-
#include <excpt.h>
1532+
/* Stack checking */
15371533

15381534
/*
15391535
* Return non-zero when we run out of memory on the stack; zero otherwise.
15401536
*/
15411537
int PyOS_CheckStack(void)
15421538
{
1543-
char here;
1544-
uintptr_t here_addr = (uintptr_t)&here;
15451539
PyThreadState *tstate = _PyThreadState_GET();
1546-
_PyThreadStateImpl *_tstate = (_PyThreadStateImpl *)tstate;
1547-
if (_tstate->c_stack_hard_limit == 0) {
1548-
_Py_InitializeRecursionLimits(tstate);
1549-
}
1550-
if (here_addr >= _tstate->c_stack_soft_limit) {
1551-
return 0;
1552-
}
1553-
else {
1540+
if (_Py_ReachedRecursionLimit(tstate)) {
15541541
return -1;
15551542
}
1543+
return 0;
15561544
}
15571545

1558-
#endif /* WIN32 && _MSC_VER */
1559-
1560-
/* Alternate implementations can be added here... */
1561-
15621546
#endif /* USE_STACKCHECK */
15631547

15641548
/* Deprecated C API functions still provided for binary compatibility */

0 commit comments

Comments
 (0)