@@ -561,16 +561,23 @@ _gen_throw(PyGenObject *gen, int close_on_genexit,
561
561
562
562
563
563
static PyObject *
564
- gen_throw (PyGenObject * gen , PyObject * args )
564
+ gen_throw (PyGenObject * gen , PyObject * const * args , Py_ssize_t nargs )
565
565
{
566
566
PyObject * typ ;
567
567
PyObject * tb = NULL ;
568
568
PyObject * val = NULL ;
569
569
570
- if (!PyArg_UnpackTuple ( args , "throw" , 1 , 3 , & typ , & val , & tb )) {
570
+ if (!_PyArg_CheckPositional ( "throw" , nargs , 1 , 3 )) {
571
571
return NULL ;
572
572
}
573
-
573
+ typ = args [0 ];
574
+ if (nargs == 3 ) {
575
+ val = args [1 ];
576
+ tb = args [2 ];
577
+ }
578
+ else if (nargs == 2 ) {
579
+ val = args [1 ];
580
+ }
574
581
return _gen_throw (gen , 1 , typ , val , tb );
575
582
}
576
583
@@ -813,7 +820,7 @@ PyDoc_STRVAR(sizeof__doc__,
813
820
814
821
static PyMethodDef gen_methods [] = {
815
822
{"send" ,(PyCFunction )gen_send , METH_O , send_doc },
816
- {"throw" ,(PyCFunction )gen_throw , METH_VARARGS , throw_doc },
823
+ {"throw" ,(PyCFunction )( void ( * )( void )) gen_throw , METH_FASTCALL , throw_doc },
817
824
{"close" ,(PyCFunction )gen_close , METH_NOARGS , close_doc },
818
825
{"__sizeof__" , (PyCFunction )gen_sizeof , METH_NOARGS , sizeof__doc__ },
819
826
{NULL , NULL } /* Sentinel */
@@ -1159,7 +1166,7 @@ PyDoc_STRVAR(coro_close_doc,
1159
1166
1160
1167
static PyMethodDef coro_methods [] = {
1161
1168
{"send" ,(PyCFunction )gen_send , METH_O , coro_send_doc },
1162
- {"throw" ,(PyCFunction )gen_throw , METH_VARARGS , coro_throw_doc },
1169
+ {"throw" ,(PyCFunction )( void ( * )( void )) gen_throw , METH_FASTCALL , coro_throw_doc },
1163
1170
{"close" ,(PyCFunction )gen_close , METH_NOARGS , coro_close_doc },
1164
1171
{"__sizeof__" , (PyCFunction )gen_sizeof , METH_NOARGS , sizeof__doc__ },
1165
1172
{NULL , NULL } /* Sentinel */
@@ -1246,9 +1253,9 @@ coro_wrapper_send(PyCoroWrapper *cw, PyObject *arg)
1246
1253
}
1247
1254
1248
1255
static PyObject *
1249
- coro_wrapper_throw (PyCoroWrapper * cw , PyObject * args )
1256
+ coro_wrapper_throw (PyCoroWrapper * cw , PyObject * const * args , Py_ssize_t nargs )
1250
1257
{
1251
- return gen_throw ((PyGenObject * )cw -> cw_coroutine , args );
1258
+ return gen_throw ((PyGenObject * )cw -> cw_coroutine , args , nargs );
1252
1259
}
1253
1260
1254
1261
static PyObject *
@@ -1266,7 +1273,8 @@ coro_wrapper_traverse(PyCoroWrapper *cw, visitproc visit, void *arg)
1266
1273
1267
1274
static PyMethodDef coro_wrapper_methods [] = {
1268
1275
{"send" ,(PyCFunction )coro_wrapper_send , METH_O , coro_send_doc },
1269
- {"throw" ,(PyCFunction )coro_wrapper_throw , METH_VARARGS , coro_throw_doc },
1276
+ {"throw" ,(PyCFunction )(void (* )(void ))coro_wrapper_throw ,
1277
+ METH_FASTCALL , coro_throw_doc },
1270
1278
{"close" ,(PyCFunction )coro_wrapper_close , METH_NOARGS , coro_close_doc },
1271
1279
{NULL , NULL } /* Sentinel */
1272
1280
};
@@ -1789,7 +1797,7 @@ async_gen_asend_iternext(PyAsyncGenASend *o)
1789
1797
1790
1798
1791
1799
static PyObject *
1792
- async_gen_asend_throw (PyAsyncGenASend * o , PyObject * args )
1800
+ async_gen_asend_throw (PyAsyncGenASend * o , PyObject * const * args , Py_ssize_t nargs )
1793
1801
{
1794
1802
PyObject * result ;
1795
1803
@@ -1800,7 +1808,7 @@ async_gen_asend_throw(PyAsyncGenASend *o, PyObject *args)
1800
1808
return NULL ;
1801
1809
}
1802
1810
1803
- result = gen_throw ((PyGenObject * )o -> ags_gen , args );
1811
+ result = gen_throw ((PyGenObject * )o -> ags_gen , args , nargs );
1804
1812
result = async_gen_unwrap_value (o -> ags_gen , result );
1805
1813
1806
1814
if (result == NULL ) {
@@ -1821,7 +1829,7 @@ async_gen_asend_close(PyAsyncGenASend *o, PyObject *args)
1821
1829
1822
1830
static PyMethodDef async_gen_asend_methods [] = {
1823
1831
{"send" , (PyCFunction )async_gen_asend_send , METH_O , send_doc },
1824
- {"throw" , (PyCFunction )async_gen_asend_throw , METH_VARARGS , throw_doc },
1832
+ {"throw" , (PyCFunction )( void ( * )( void )) async_gen_asend_throw , METH_FASTCALL , throw_doc },
1825
1833
{"close" , (PyCFunction )async_gen_asend_close , METH_NOARGS , close_doc },
1826
1834
{NULL , NULL } /* Sentinel */
1827
1835
};
@@ -2183,7 +2191,7 @@ async_gen_athrow_send(PyAsyncGenAThrow *o, PyObject *arg)
2183
2191
2184
2192
2185
2193
static PyObject *
2186
- async_gen_athrow_throw (PyAsyncGenAThrow * o , PyObject * args )
2194
+ async_gen_athrow_throw (PyAsyncGenAThrow * o , PyObject * const * args , Py_ssize_t nargs )
2187
2195
{
2188
2196
PyObject * retval ;
2189
2197
@@ -2194,7 +2202,7 @@ async_gen_athrow_throw(PyAsyncGenAThrow *o, PyObject *args)
2194
2202
return NULL ;
2195
2203
}
2196
2204
2197
- retval = gen_throw ((PyGenObject * )o -> agt_gen , args );
2205
+ retval = gen_throw ((PyGenObject * )o -> agt_gen , args , nargs );
2198
2206
if (o -> agt_args ) {
2199
2207
return async_gen_unwrap_value (o -> agt_gen , retval );
2200
2208
} else {
@@ -2239,7 +2247,8 @@ async_gen_athrow_close(PyAsyncGenAThrow *o, PyObject *args)
2239
2247
2240
2248
static PyMethodDef async_gen_athrow_methods [] = {
2241
2249
{"send" , (PyCFunction )async_gen_athrow_send , METH_O , send_doc },
2242
- {"throw" , (PyCFunction )async_gen_athrow_throw , METH_VARARGS , throw_doc },
2250
+ {"throw" , (PyCFunction )(void (* )(void ))async_gen_athrow_throw ,
2251
+ METH_FASTCALL , throw_doc },
2243
2252
{"close" , (PyCFunction )async_gen_athrow_close , METH_NOARGS , close_doc },
2244
2253
{NULL , NULL } /* Sentinel */
2245
2254
};
0 commit comments