Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

GH-113655: Use PyOS_CheckStack on those platforms that support it#113701

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
NextNext commit
Use PyOS_CheckStack on those platforms that support it (currently jus…
…t Windows)
  • Loading branch information
@markshannon
markshannon committedDec 31, 2023
commitdbf2efcabbb9d519f44647a5c074c17688e64209
4 changes: 3 additions & 1 deletionInclude/cpython/pystate.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -225,9 +225,11 @@ struct _ts {
# define Py_C_RECURSION_LIMIT 500
#elif defined(__s390x__)
# define Py_C_RECURSION_LIMIT 1200
#elif defined(USE_STACKCHECK)
# define Py_C_RECURSION_LIMIT 4000
#else
// This value is duplicated in Lib/test/support/__init__.py
# define Py_C_RECURSION_LIMIT8000
# define Py_C_RECURSION_LIMIT10000
#endif


Expand Down
9 changes: 0 additions & 9 deletionsInclude/internal/pycore_ceval.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -135,18 +135,9 @@ extern void _PyEval_DeactivateOpCache(void);

/* --- _Py_EnterRecursiveCall() ----------------------------------------- */

#ifdef USE_STACKCHECK
/* With USE_STACKCHECK macro defined, trigger stack checks in
_Py_CheckRecursiveCall() on every 64th call to _Py_EnterRecursiveCall. */
static inline int _Py_MakeRecCheck(PyThreadState *tstate) {
return (tstate->c_recursion_remaining-- <= 0
|| (tstate->c_recursion_remaining & 63) == 0);
}
#else
static inline int _Py_MakeRecCheck(PyThreadState *tstate) {
return tstate->c_recursion_remaining-- <= 0;
}
#endif

// Export for '_json' shared extension, used via _Py_EnterRecursiveCall()
// static inline function.
Expand Down
22 changes: 19 additions & 3 deletionsInclude/pythonrun.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,16 +17,32 @@ PyAPI_FUNC(void) PyErr_Display(PyObject *, PyObject *, PyObject *);
PyAPI_FUNC(void) PyErr_DisplayException(PyObject *);
#endif

/* C frame size approximations in "pointers".
* Note: These are for "typical" C frames, we expect PyEval_EvalDefault
* to use three times as much stack space.
* TO DO: We should determine the numbers more accurately at build time.
*/
#ifdef Py_DEBUG
/* Debug frames are larger, very much so for Clang -O0. */
# ifdef __clang__
# define Py_C_FRAME_SIZE 400
# else
# define Py_C_FRAME_SIZE 100;
# endif
#else
# define Py_C_FRAME_SIZE 25;
#endif


/* Stuff with no proper home (yet) */
PyAPI_DATA(int) (*PyOS_InputHook)(void);

/* Stack size, in "pointers" (so we get extra safety margins
on 64-bit platforms). On a 32-bit platform, this translates
to an8k margin. */
#define PYOS_STACK_MARGIN2048
to an40k margin. */
#define PYOS_STACK_MARGIN10000

#if defined(WIN32) && !defined(MS_WIN64) && !defined(_M_ARM) && defined(_MSC_VER) && _MSC_VER >= 1300
#if defined(WIN32) && !defined(_M_ARM) && defined(_MSC_VER) && _MSC_VER >= 1300
/* Enable stack checking under Microsoft C */
// When changing the platforms, ensure PyOS_CheckStack() docs are still correct
#define USE_STACKCHECK
Expand Down
5 changes: 4 additions & 1 deletionLib/test/support/__init__.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2377,7 +2377,10 @@ def _get_c_recursion_limit():
return _testcapi.Py_C_RECURSION_LIMIT
except (ImportError, AttributeError):
# Originally taken from Include/cpython/pystate.h .
return 8000
if sys.platform == 'win32':
return 4000
else:
return 10000

# The default C recursion limit.
Py_C_RECURSION_LIMIT = _get_c_recursion_limit()
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
Use the PyOS_CheckStack to dynamically check for C stack usage on platforms
that support it (just Windows for now).
4 changes: 4 additions & 0 deletionsPython/ceval.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -285,6 +285,10 @@ _Py_CheckRecursiveCall(PyThreadState *tstate, const char *where)
_PyErr_SetString(tstate, PyExc_MemoryError, "Stack overflow");
return -1;
}
else {
tstate->c_recursion_remaining += (int)(PYOS_STACK_MARGIN/Py_C_FRAME_SIZE);
return 0;
}
#endif
if (tstate->recursion_headroom) {
if (tstate->c_recursion_remaining < -50) {
Expand Down
2 changes: 1 addition & 1 deletionPython/pythonrun.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1525,7 +1525,7 @@ _Py_SourceAsString(PyObject *cmd, const char *funcname, const char *what, PyComp
#include <excpt.h>

/*
* Return non-zero when werun out of memory on the stack; zero otherwise.
* Return non-zero when weare low on memory on the stack; zero otherwise.
*/
int
PyOS_CheckStack(void)
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp