Skip to content

Commit 1ac565b

Browse files
committed
Don't expose async_generator_wrapped_value in sys.monitoring
1 parent 6c52ada commit 1ac565b

File tree

4 files changed

+30
-15
lines changed

4 files changed

+30
-15
lines changed

Include/internal/pycore_genobject.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ extern PyObject *_PyAsyncGenValueWrapperNew(PyThreadState *state, PyObject *);
6767
extern PyTypeObject _PyCoroWrapper_Type;
6868
extern PyTypeObject _PyAsyncGenWrappedValue_Type;
6969
extern PyTypeObject _PyAsyncGenAThrow_Type;
70+
extern PyTypeObject _PyAsyncGenWrappedValue_Type;
71+
72+
typedef struct _PyAsyncGenWrappedValue {
73+
PyObject_HEAD
74+
PyObject *agw_val;
75+
} _PyAsyncGenWrappedValue;
76+
77+
#define _PyAsyncGenWrappedValue_CheckExact(o) \
78+
Py_IS_TYPE(o, &_PyAsyncGenWrappedValue_Type)
79+
#define _PyAsyncGenWrappedValue_CAST(op) \
80+
(assert(_PyAsyncGenWrappedValue_CheckExact(op)), \
81+
_Py_CAST(_PyAsyncGenWrappedValue*, (op)))
7082

7183
#ifdef __cplusplus
7284
}

Objects/genobject.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,19 +1441,6 @@ typedef struct PyAsyncGenAThrow {
14411441
} PyAsyncGenAThrow;
14421442

14431443

1444-
typedef struct _PyAsyncGenWrappedValue {
1445-
PyObject_HEAD
1446-
PyObject *agw_val;
1447-
} _PyAsyncGenWrappedValue;
1448-
1449-
1450-
#define _PyAsyncGenWrappedValue_CheckExact(o) \
1451-
Py_IS_TYPE(o, &_PyAsyncGenWrappedValue_Type)
1452-
#define _PyAsyncGenWrappedValue_CAST(op) \
1453-
(assert(_PyAsyncGenWrappedValue_CheckExact(op)), \
1454-
_Py_CAST(_PyAsyncGenWrappedValue*, (op)))
1455-
1456-
14571444
static int
14581445
async_gen_traverse(PyObject *self, visitproc visit, void *arg)
14591446
{

Python/bytecodes.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1312,9 +1312,16 @@ dummy_func(
13121312
}
13131313

13141314
tier1 op(_YIELD_VALUE_EVENT, (val -- val)) {
1315+
PyObject *yielded = PyStackRef_AsPyObjectBorrow(val);
1316+
if (_PyAsyncGenWrappedValue_CheckExact(yielded))
1317+
{
1318+
/* gh-129013: Async generators have a special wrapper that they
1319+
yield. Don't expose that to the user. */
1320+
yielded = _PyAsyncGenWrappedValue_CAST(yielded)->agw_val;
1321+
}
13151322
int err = _Py_call_instrumentation_arg(
13161323
tstate, PY_MONITORING_EVENT_PY_YIELD,
1317-
frame, this_instr, PyStackRef_AsPyObjectBorrow(val));
1324+
frame, this_instr, yielded);
13181325
if (err) {
13191326
ERROR_NO_POP();
13201327
}

Python/generated_cases.c.h

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

0 commit comments

Comments
 (0)