Skip to content

Commit bfc3d8d

Browse files
authored
gh-143531: Use macro to check if PEP 523 is hooked (#143532)
Use macro to check if PEP 523 is hooked
1 parent 9a3263f commit bfc3d8d

File tree

4 files changed

+46
-44
lines changed

4 files changed

+46
-44
lines changed

Python/bytecodes.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,7 +1349,7 @@ dummy_func(
13491349
PyObject *receiver_o = PyStackRef_AsPyObjectBorrow(receiver);
13501350
PyObject *retval_o;
13511351
assert(frame->owner != FRAME_OWNED_BY_INTERPRETER);
1352-
if ((tstate->interp->eval_frame == NULL) &&
1352+
if (!IS_PEP523_HOOKED(tstate) &&
13531353
(Py_TYPE(receiver_o) == &PyGen_Type || Py_TYPE(receiver_o) == &PyCoro_Type) &&
13541354
gen_try_set_executing((PyGenObject *)receiver_o))
13551355
{
@@ -2596,7 +2596,7 @@ dummy_func(
25962596
PyObject *owner_o = PyStackRef_AsPyObjectBorrow(owner);
25972597

25982598
assert((oparg & 1) == 0);
2599-
DEOPT_IF(tstate->interp->eval_frame);
2599+
DEOPT_IF(IS_PEP523_HOOKED(tstate));
26002600
PyTypeObject *cls = Py_TYPE(owner_o);
26012601
assert(type_version != 0);
26022602
DEOPT_IF(FT_ATOMIC_LOAD_UINT_RELAXED(cls->tp_version_tag) != type_version);
@@ -3746,7 +3746,7 @@ dummy_func(
37463746
}
37473747
// Check if the call can be inlined or not
37483748
if (Py_TYPE(callable_o) == &PyFunction_Type &&
3749-
tstate->interp->eval_frame == NULL &&
3749+
!IS_PEP523_HOOKED(tstate) &&
37503750
((PyFunctionObject *)callable_o)->vectorcall == _PyFunction_Vectorcall)
37513751
{
37523752
int code_flags = ((PyCodeObject*)PyFunction_GET_CODE(callable_o))->co_flags;
@@ -3938,7 +3938,7 @@ dummy_func(
39383938
}
39393939

39403940
op(_CHECK_PEP_523, (--)) {
3941-
DEOPT_IF(tstate->interp->eval_frame);
3941+
DEOPT_IF(IS_PEP523_HOOKED(tstate));
39423942
}
39433943

39443944
op(_CHECK_FUNCTION_EXACT_ARGS, (callable, self_or_null, unused[oparg] -- callable, self_or_null, unused[oparg])) {
@@ -3974,7 +3974,7 @@ dummy_func(
39743974
}
39753975

39763976
op(_PUSH_FRAME, (new_frame -- )) {
3977-
assert(tstate->interp->eval_frame == NULL);
3977+
assert(!IS_PEP523_HOOKED(tstate));
39783978
_PyInterpreterFrame *temp = PyStackRef_Unwrap(new_frame);
39793979
DEAD(new_frame);
39803980
SYNC_SP();
@@ -4607,7 +4607,7 @@ dummy_func(
46074607
int positional_args = total_args - (int)PyTuple_GET_SIZE(kwnames_o);
46084608
// Check if the call can be inlined or not
46094609
if (Py_TYPE(callable_o) == &PyFunction_Type &&
4610-
tstate->interp->eval_frame == NULL &&
4610+
!IS_PEP523_HOOKED(tstate) &&
46114611
((PyFunctionObject *)callable_o)->vectorcall == _PyFunction_Vectorcall)
46124612
{
46134613
int code_flags = ((PyCodeObject*)PyFunction_GET_CODE(callable_o))->co_flags;
@@ -4851,7 +4851,7 @@ dummy_func(
48514851
}
48524852
else {
48534853
if (Py_TYPE(func) == &PyFunction_Type &&
4854-
tstate->interp->eval_frame == NULL &&
4854+
!IS_PEP523_HOOKED(tstate) &&
48554855
((PyFunctionObject *)func)->vectorcall == _PyFunction_Vectorcall) {
48564856
PyObject *callargs = PyStackRef_AsPyObjectSteal(callargs_st);
48574857
assert(PyTuple_CheckExact(callargs));

Python/ceval_macros.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,8 @@ do { \
489489
#define CHECK_CURRENT_CACHED_VALUES(N) ((void)0)
490490
#endif
491491

492+
#define IS_PEP523_HOOKED(tstate) (tstate->interp->eval_frame != NULL)
493+
492494
static inline int
493495
check_periodics(PyThreadState *tstate) {
494496
_Py_CHECK_EMSCRIPTEN_SIGNALS_PERIODICALLY();

Python/executor_cases.c.h

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)