Skip to content

[WIP] bpo-39984: Add PyInterpreterState.ceval #19034

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 4 additions & 3 deletions Include/internal/pycore_ceval.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ struct _frame;

#include "pycore_pystate.h" /* PyInterpreterState.eval_frame */

PyAPI_FUNC(void) _Py_FinishPendingCalls(PyThreadState *tstate);
PyAPI_FUNC(void) _PyEval_Initialize(struct _ceval_runtime_state *);
PyAPI_FUNC(void) _PyEval_FiniThreads(
extern void _Py_FinishPendingCalls(PyThreadState *tstate);
extern void _PyEval_InitializeRuntime(struct _ceval_runtime_state *);
extern void _PyEval_InitializeInterp(struct _ceval_state *);
extern void _PyEval_FiniThreads(
struct _ceval_runtime_state *ceval);
PyAPI_FUNC(void) _PyEval_SignalReceived(
struct _ceval_runtime_state *ceval);
Expand Down
6 changes: 5 additions & 1 deletion Include/internal/pycore_pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ struct _pending_calls {
};

struct _ceval_runtime_state {
int recursion_limit;
/* Records whether tracing is on for any thread. Counts the number
of threads for which tstate->c_tracefunc is non-NULL, so if the
value is 0, we know we don't have to check this thread's
Expand All @@ -52,6 +51,10 @@ struct _ceval_runtime_state {
struct _gil_runtime_state gil;
};

struct _ceval_state {
int recursion_limit;
};

/* interpreter state */

#define _PY_NSMALLPOSINTS 257
Expand All @@ -75,6 +78,7 @@ struct _is {

int finalizing;

struct _ceval_state ceval;
struct _gc_runtime_state gc;

PyObject *modules;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
subinterpreters: Move ``_PyRuntimeState.ceval.recursion_limit`` to
``PyInterpreterState.ceval.recursion_limit``: make the limit
per-interpreter.
24 changes: 14 additions & 10 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,26 +638,31 @@ Py_MakePendingCalls(void)
int _Py_CheckRecursionLimit = Py_DEFAULT_RECURSION_LIMIT;

void
_PyEval_Initialize(struct _ceval_runtime_state *state)
_PyEval_InitializeRuntime(struct _ceval_runtime_state *ceval)
{
state->recursion_limit = Py_DEFAULT_RECURSION_LIMIT;
_Py_CheckRecursionLimit = Py_DEFAULT_RECURSION_LIMIT;
_gil_initialize(&state->gil);
_gil_initialize(&ceval->gil);
}

void
_PyEval_InitializeInterp(struct _ceval_state *ceval)
{
ceval->recursion_limit = Py_DEFAULT_RECURSION_LIMIT;
}

int
Py_GetRecursionLimit(void)
{
struct _ceval_runtime_state *ceval = &_PyRuntime.ceval;
return ceval->recursion_limit;
PyThreadState *tstate = _PyThreadState_GET();
return tstate->interp->ceval.recursion_limit;
}

void
Py_SetRecursionLimit(int new_limit)
{
struct _ceval_runtime_state *ceval = &_PyRuntime.ceval;
ceval->recursion_limit = new_limit;
_Py_CheckRecursionLimit = ceval->recursion_limit;
PyThreadState *tstate = _PyThreadState_GET();
tstate->interp->ceval.recursion_limit = new_limit;
_Py_CheckRecursionLimit = new_limit;
}

/* The function _Py_EnterRecursiveCall() only calls _Py_CheckRecursiveCall()
Expand All @@ -668,8 +673,7 @@ Py_SetRecursionLimit(int new_limit)
int
_Py_CheckRecursiveCall(PyThreadState *tstate, const char *where)
{
_PyRuntimeState *runtime = tstate->interp->runtime;
int recursion_limit = runtime->ceval.recursion_limit;
int recursion_limit = tstate->interp->ceval.recursion_limit;

#ifdef USE_STACKCHECK
tstate->stackcheck_counter = 0;
Expand Down
3 changes: 2 additions & 1 deletion Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ _PyRuntimeState_Init_impl(_PyRuntimeState *runtime)
runtime->open_code_userdata = open_code_userdata;
runtime->audit_hook_head = audit_hook_head;

_PyEval_Initialize(&runtime->ceval);
_PyEval_InitializeRuntime(&runtime->ceval);

PyPreConfig_InitPythonConfig(&runtime->preconfig);

Expand Down Expand Up @@ -213,6 +213,7 @@ PyInterpreterState_New(void)
_PyRuntimeState *runtime = &_PyRuntime;
interp->runtime = runtime;

_PyEval_InitializeInterp(&interp->ceval);
_PyGC_InitState(&interp->gc);
PyConfig_InitPythonConfig(&interp->config);

Expand Down