@@ -1451,7 +1451,9 @@ typedef struct PyAsyncGenAThrow {
1451
1451
1452
1452
/* Can be NULL, when in the "aclose()" mode
1453
1453
(equivalent of "athrow(GeneratorExit)") */
1454
- PyObject * agt_args ;
1454
+ PyObject * agt_typ ;
1455
+ PyObject * agt_tb ;
1456
+ PyObject * agt_val ;
1455
1457
1456
1458
AwaitableState agt_state ;
1457
1459
} PyAsyncGenAThrow ;
@@ -2078,7 +2080,9 @@ async_gen_athrow_dealloc(PyObject *self)
2078
2080
2079
2081
_PyObject_GC_UNTRACK (self );
2080
2082
Py_CLEAR (agt -> agt_gen );
2081
- Py_CLEAR (agt -> agt_args );
2083
+ Py_XDECREF (agt -> agt_typ );
2084
+ Py_XDECREF (agt -> agt_tb );
2085
+ Py_XDECREF (agt -> agt_val );
2082
2086
PyObject_GC_Del (self );
2083
2087
}
2084
2088
@@ -2088,7 +2092,9 @@ async_gen_athrow_traverse(PyObject *self, visitproc visit, void *arg)
2088
2092
{
2089
2093
PyAsyncGenAThrow * agt = _PyAsyncGenAThrow_CAST (self );
2090
2094
Py_VISIT (agt -> agt_gen );
2091
- Py_VISIT (agt -> agt_args );
2095
+ Py_VISIT (agt -> agt_typ );
2096
+ Py_VISIT (agt -> agt_tb );
2097
+ Py_VISIT (agt -> agt_val );
2092
2098
return 0 ;
2093
2099
}
2094
2100
@@ -2116,7 +2122,7 @@ async_gen_athrow_send(PyObject *self, PyObject *arg)
2116
2122
if (o -> agt_state == AWAITABLE_STATE_INIT ) {
2117
2123
if (o -> agt_gen -> ag_running_async ) {
2118
2124
o -> agt_state = AWAITABLE_STATE_CLOSED ;
2119
- if (o -> agt_args == NULL ) {
2125
+ if (o -> agt_typ == NULL ) {
2120
2126
PyErr_SetString (
2121
2127
PyExc_RuntimeError ,
2122
2128
"aclose(): asynchronous generator is already running" );
@@ -2143,7 +2149,7 @@ async_gen_athrow_send(PyObject *self, PyObject *arg)
2143
2149
o -> agt_state = AWAITABLE_STATE_ITER ;
2144
2150
o -> agt_gen -> ag_running_async = 1 ;
2145
2151
2146
- if (o -> agt_args == NULL ) {
2152
+ if (o -> agt_typ == NULL ) {
2147
2153
/* aclose() mode */
2148
2154
o -> agt_gen -> ag_closed = 1 ;
2149
2155
@@ -2157,19 +2163,10 @@ async_gen_athrow_send(PyObject *self, PyObject *arg)
2157
2163
goto yield_close ;
2158
2164
}
2159
2165
} else {
2160
- PyObject * typ ;
2161
- PyObject * tb = NULL ;
2162
- PyObject * val = NULL ;
2163
-
2164
- if (!PyArg_UnpackTuple (o -> agt_args , "athrow" , 1 , 3 ,
2165
- & typ , & val , & tb )) {
2166
- return NULL ;
2167
- }
2168
-
2169
2166
retval = _gen_throw ((PyGenObject * )gen ,
2170
2167
0 , /* Do not close generator when
2171
2168
PyExc_GeneratorExit is passed */
2172
- typ , val , tb );
2169
+ o -> agt_typ , o -> agt_val , o -> agt_tb );
2173
2170
retval = async_gen_unwrap_value (o -> agt_gen , retval );
2174
2171
}
2175
2172
if (retval == NULL ) {
@@ -2181,7 +2178,7 @@ async_gen_athrow_send(PyObject *self, PyObject *arg)
2181
2178
assert (o -> agt_state == AWAITABLE_STATE_ITER );
2182
2179
2183
2180
retval = gen_send ((PyObject * )gen , arg );
2184
- if (o -> agt_args ) {
2181
+ if (o -> agt_typ ) {
2185
2182
return async_gen_unwrap_value (o -> agt_gen , retval );
2186
2183
} else {
2187
2184
/* aclose() mode */
@@ -2212,7 +2209,7 @@ async_gen_athrow_send(PyObject *self, PyObject *arg)
2212
2209
if (PyErr_ExceptionMatches (PyExc_StopAsyncIteration ) ||
2213
2210
PyErr_ExceptionMatches (PyExc_GeneratorExit ))
2214
2211
{
2215
- if (o -> agt_args == NULL ) {
2212
+ if (o -> agt_typ == NULL ) {
2216
2213
/* when aclose() is called we don't want to propagate
2217
2214
StopAsyncIteration or GeneratorExit; just raise
2218
2215
StopIteration, signalling that this 'aclose()' await
@@ -2241,7 +2238,7 @@ async_gen_athrow_throw(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
2241
2238
if (o -> agt_state == AWAITABLE_STATE_INIT ) {
2242
2239
if (o -> agt_gen -> ag_running_async ) {
2243
2240
o -> agt_state = AWAITABLE_STATE_CLOSED ;
2244
- if (o -> agt_args == NULL ) {
2241
+ if (o -> agt_typ == NULL ) {
2245
2242
PyErr_SetString (
2246
2243
PyExc_RuntimeError ,
2247
2244
"aclose(): asynchronous generator is already running" );
@@ -2259,7 +2256,7 @@ async_gen_athrow_throw(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
2259
2256
}
2260
2257
2261
2258
PyObject * retval = gen_throw ((PyObject * )o -> agt_gen , args , nargs );
2262
- if (o -> agt_args ) {
2259
+ if (o -> agt_typ ) {
2263
2260
retval = async_gen_unwrap_value (o -> agt_gen , retval );
2264
2261
if (retval == NULL ) {
2265
2262
o -> agt_gen -> ag_running_async = 0 ;
@@ -2334,7 +2331,7 @@ async_gen_athrow_finalize(PyObject *op)
2334
2331
{
2335
2332
PyAsyncGenAThrow * o = (PyAsyncGenAThrow * )op ;
2336
2333
if (o -> agt_state == AWAITABLE_STATE_INIT ) {
2337
- PyObject * method = o -> agt_args ? & _Py_ID (athrow ) : & _Py_ID (aclose );
2334
+ PyObject * method = o -> agt_typ ? & _Py_ID (athrow ) : & _Py_ID (aclose );
2338
2335
_PyErr_WarnUnawaitedAgenMethod (o -> agt_gen , method );
2339
2336
}
2340
2337
}
@@ -2403,13 +2400,23 @@ PyTypeObject _PyAsyncGenAThrow_Type = {
2403
2400
static PyObject *
2404
2401
async_gen_athrow_new (PyAsyncGenObject * gen , PyObject * args )
2405
2402
{
2403
+ PyObject * typ = NULL ;
2404
+ PyObject * tb = NULL ;
2405
+ PyObject * val = NULL ;
2406
+ if (args && !PyArg_UnpackTuple (args , "athrow" , 1 , 3 , & typ , & val , & tb )) {
2407
+ return NULL ;
2408
+ }
2409
+
2406
2410
PyAsyncGenAThrow * o ;
2407
2411
o = PyObject_GC_New (PyAsyncGenAThrow , & _PyAsyncGenAThrow_Type );
2408
2412
if (o == NULL ) {
2409
2413
return NULL ;
2410
2414
}
2411
2415
o -> agt_gen = (PyAsyncGenObject * )Py_NewRef (gen );
2412
- o -> agt_args = Py_XNewRef (args );
2416
+ o -> agt_typ = Py_XNewRef (typ );
2417
+ o -> agt_tb = Py_XNewRef (tb );
2418
+ o -> agt_val = Py_XNewRef (val );
2419
+
2413
2420
o -> agt_state = AWAITABLE_STATE_INIT ;
2414
2421
_PyObject_GC_TRACK ((PyObject * )o );
2415
2422
return (PyObject * )o ;
0 commit comments