Skip to content

Commit 97d6e8d

Browse files
DinoVreidenong
authored andcommitted
pythongh-143531: Use macro to check if PEP 523 is hooked (python#143532)
Use macro to check if PEP 523 is hooked
1 parent 1023fde commit 97d6e8d

4 files changed

Lines changed: 46 additions & 44 deletions

File tree

Python/bytecodes.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,7 @@ dummy_func(
13461346
PyObject *receiver_o = PyStackRef_AsPyObjectBorrow(receiver);
13471347
PyObject *retval_o;
13481348
assert(frame->owner != FRAME_OWNED_BY_INTERPRETER);
1349-
if ((tstate->interp->eval_frame == NULL) &&
1349+
if (!IS_PEP523_HOOKED(tstate) &&
13501350
(Py_TYPE(receiver_o) == &PyGen_Type || Py_TYPE(receiver_o) == &PyCoro_Type) &&
13511351
gen_try_set_executing((PyGenObject *)receiver_o))
13521352
{
@@ -2593,7 +2593,7 @@ dummy_func(
25932593
PyObject *owner_o = PyStackRef_AsPyObjectBorrow(owner);
25942594

25952595
assert((oparg & 1) == 0);
2596-
DEOPT_IF(tstate->interp->eval_frame);
2596+
DEOPT_IF(IS_PEP523_HOOKED(tstate));
25972597
PyTypeObject *cls = Py_TYPE(owner_o);
25982598
assert(type_version != 0);
25992599
DEOPT_IF(FT_ATOMIC_LOAD_UINT_RELAXED(cls->tp_version_tag) != type_version);
@@ -3743,7 +3743,7 @@ dummy_func(
37433743
}
37443744
// Check if the call can be inlined or not
37453745
if (Py_TYPE(callable_o) == &PyFunction_Type &&
3746-
tstate->interp->eval_frame == NULL &&
3746+
!IS_PEP523_HOOKED(tstate) &&
37473747
((PyFunctionObject *)callable_o)->vectorcall == _PyFunction_Vectorcall)
37483748
{
37493749
int code_flags = ((PyCodeObject*)PyFunction_GET_CODE(callable_o))->co_flags;
@@ -3935,7 +3935,7 @@ dummy_func(
39353935
}
39363936

39373937
op(_CHECK_PEP_523, (--)) {
3938-
DEOPT_IF(tstate->interp->eval_frame);
3938+
DEOPT_IF(IS_PEP523_HOOKED(tstate));
39393939
}
39403940

39413941
op(_CHECK_FUNCTION_EXACT_ARGS, (callable, self_or_null, unused[oparg] -- callable, self_or_null, unused[oparg])) {
@@ -3971,7 +3971,7 @@ dummy_func(
39713971
}
39723972

39733973
op(_PUSH_FRAME, (new_frame -- )) {
3974-
assert(tstate->interp->eval_frame == NULL);
3974+
assert(!IS_PEP523_HOOKED(tstate));
39753975
_PyInterpreterFrame *temp = PyStackRef_Unwrap(new_frame);
39763976
DEAD(new_frame);
39773977
SYNC_SP();
@@ -4604,7 +4604,7 @@ dummy_func(
46044604
int positional_args = total_args - (int)PyTuple_GET_SIZE(kwnames_o);
46054605
// Check if the call can be inlined or not
46064606
if (Py_TYPE(callable_o) == &PyFunction_Type &&
4607-
tstate->interp->eval_frame == NULL &&
4607+
!IS_PEP523_HOOKED(tstate) &&
46084608
((PyFunctionObject *)callable_o)->vectorcall == _PyFunction_Vectorcall)
46094609
{
46104610
int code_flags = ((PyCodeObject*)PyFunction_GET_CODE(callable_o))->co_flags;
@@ -4848,7 +4848,7 @@ dummy_func(
48484848
}
48494849
else {
48504850
if (Py_TYPE(func) == &PyFunction_Type &&
4851-
tstate->interp->eval_frame == NULL &&
4851+
!IS_PEP523_HOOKED(tstate) &&
48524852
((PyFunctionObject *)func)->vectorcall == _PyFunction_Vectorcall) {
48534853
PyObject *callargs = PyStackRef_AsPyObjectSteal(callargs_st);
48544854
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)