@@ -1067,19 +1067,21 @@ builtin_exec_impl(PyObject *module, PyObject *source, PyObject *globals,
10671067static PyObject *
10681068builtin_getattr (PyObject * self , PyObject * const * args , Py_ssize_t nargs )
10691069{
1070- PyObject * v , * result , * dflt = NULL ;
1071- PyObject * name ;
1070+ PyObject * v , * name , * result ;
10721071
1073- if (!_PyArg_UnpackStack ( args , nargs , "getattr" , 2 , 3 , & v , & name , & dflt ))
1072+ if (!_PyArg_CheckPositional ( "getattr" , nargs , 2 , 3 ))
10741073 return NULL ;
10751074
1075+ v = args [0 ];
1076+ name = args [1 ];
10761077 if (!PyUnicode_Check (name )) {
10771078 PyErr_SetString (PyExc_TypeError ,
10781079 "getattr(): attribute name must be string" );
10791080 return NULL ;
10801081 }
1081- if (dflt != NULL ) {
1082+ if (nargs > 2 ) {
10821083 if (_PyObject_LookupAttr (v , name , & result ) == 0 ) {
1084+ PyObject * dflt = args [2 ];
10831085 Py_INCREF (dflt );
10841086 return dflt ;
10851087 }
@@ -1372,11 +1374,11 @@ static PyObject *
13721374builtin_next (PyObject * self , PyObject * const * args , Py_ssize_t nargs )
13731375{
13741376 PyObject * it , * res ;
1375- PyObject * def = NULL ;
13761377
1377- if (!_PyArg_UnpackStack ( args , nargs , "next" , 1 , 2 , & it , & def ))
1378+ if (!_PyArg_CheckPositional ( "next" , nargs , 1 , 2 ))
13781379 return NULL ;
13791380
1381+ it = args [0 ];
13801382 if (!PyIter_Check (it )) {
13811383 PyErr_Format (PyExc_TypeError ,
13821384 "'%.200s' object is not an iterator" ,
@@ -1387,7 +1389,8 @@ builtin_next(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
13871389 res = (* it -> ob_type -> tp_iternext )(it );
13881390 if (res != NULL ) {
13891391 return res ;
1390- } else if (def != NULL ) {
1392+ } else if (nargs > 1 ) {
1393+ PyObject * def = args [1 ];
13911394 if (PyErr_Occurred ()) {
13921395 if (!PyErr_ExceptionMatches (PyExc_StopIteration ))
13931396 return NULL ;
@@ -1503,20 +1506,22 @@ builtin_hex(PyObject *module, PyObject *number)
15031506
15041507/* AC: cannot convert yet, as needs PEP 457 group support in inspect */
15051508static PyObject *
1506- builtin_iter (PyObject * self , PyObject * args )
1509+ builtin_iter (PyObject * self , PyObject * const * args , Py_ssize_t nargs )
15071510{
1508- PyObject * v , * w = NULL ;
1511+ PyObject * v ;
15091512
1510- if (!PyArg_UnpackTuple ( args , "iter" , 1 , 2 , & v , & w ))
1513+ if (!_PyArg_CheckPositional ( "iter" , nargs , 1 , 2 ))
15111514 return NULL ;
1512- if (w == NULL )
1515+ v = args [0 ];
1516+ if (nargs == 1 )
15131517 return PyObject_GetIter (v );
15141518 if (!PyCallable_Check (v )) {
15151519 PyErr_SetString (PyExc_TypeError ,
15161520 "iter(v, w): v must be callable" );
15171521 return NULL ;
15181522 }
1519- return PyCallIter_New (v , w );
1523+ PyObject * sentinel = args [1 ];
1524+ return PyCallIter_New (v , sentinel );
15201525}
15211526
15221527PyDoc_STRVAR (iter_doc ,
@@ -2718,7 +2723,7 @@ static PyMethodDef builtin_methods[] = {
27182723 BUILTIN_INPUT_METHODDEF
27192724 BUILTIN_ISINSTANCE_METHODDEF
27202725 BUILTIN_ISSUBCLASS_METHODDEF
2721- {"iter" , builtin_iter , METH_VARARGS , iter_doc },
2726+ {"iter" , ( PyCFunction )( void ( * )( void )) builtin_iter , METH_FASTCALL , iter_doc },
27222727 BUILTIN_LEN_METHODDEF
27232728 BUILTIN_LOCALS_METHODDEF
27242729 {"max" , (PyCFunction )(void (* )(void ))builtin_max , METH_VARARGS | METH_KEYWORDS , max_doc },
0 commit comments