@@ -115,8 +115,6 @@ static PyObject * call_function(PyObject ***, Py_ssize_t, PyObject *);
115
115
#endif
116
116
static PyObject * fast_function (PyObject * , PyObject * * , Py_ssize_t , PyObject * );
117
117
static PyObject * do_call_core (PyObject * , PyObject * , PyObject * );
118
- static PyObject * create_keyword_args (PyObject * , PyObject * * * , PyObject * );
119
- static PyObject * load_args (PyObject * * * , Py_ssize_t );
120
118
121
119
#ifdef LLTRACE
122
120
static int lltrace ;
@@ -4892,21 +4890,6 @@ PyEval_GetFuncDesc(PyObject *func)
4892
4890
return " object" ;
4893
4891
}
4894
4892
4895
- static void
4896
- err_args (PyObject * func , int flags , Py_ssize_t nargs )
4897
- {
4898
- if (flags & METH_NOARGS )
4899
- PyErr_Format (PyExc_TypeError ,
4900
- "%.200s() takes no arguments (%zd given)" ,
4901
- ((PyCFunctionObject * )func )-> m_ml -> ml_name ,
4902
- nargs );
4903
- else
4904
- PyErr_Format (PyExc_TypeError ,
4905
- "%.200s() takes exactly one argument (%zd given)" ,
4906
- ((PyCFunctionObject * )func )-> m_ml -> ml_name ,
4907
- nargs );
4908
- }
4909
-
4910
4893
#define C_TRACE (x , call ) \
4911
4894
if (tstate->use_tracing && tstate->c_profilefunc) { \
4912
4895
if (call_trace(tstate->c_profilefunc, tstate->c_profileobj, \
@@ -4950,91 +4933,49 @@ call_function(PyObject ***pp_stack, Py_ssize_t oparg, PyObject *kwnames
4950
4933
PyObject * x , * w ;
4951
4934
Py_ssize_t nkwargs = (kwnames == NULL ) ? 0 : PyTuple_GET_SIZE (kwnames );
4952
4935
Py_ssize_t nargs = oparg - nkwargs ;
4936
+ PyObject * * stack ;
4953
4937
4954
4938
/* Always dispatch PyCFunction first, because these are
4955
4939
presumed to be the most frequent callable object.
4956
4940
*/
4957
4941
if (PyCFunction_Check (func )) {
4958
- int flags = PyCFunction_GET_FLAGS (func );
4959
4942
PyThreadState * tstate = PyThreadState_GET ();
4960
4943
4961
4944
PCALL (PCALL_CFUNCTION );
4962
- if (kwnames == NULL && flags & (METH_NOARGS | METH_O )) {
4963
- PyCFunction meth = PyCFunction_GET_FUNCTION (func );
4964
- PyObject * self = PyCFunction_GET_SELF (func );
4965
- if (flags & METH_NOARGS && nargs == 0 ) {
4966
- C_TRACE (x , (* meth )(self ,NULL ));
4967
4945
4968
- x = _Py_CheckFunctionResult (func , x , NULL );
4969
- }
4970
- else if (flags & METH_O && nargs == 1 ) {
4971
- PyObject * arg = EXT_POP (* pp_stack );
4972
- C_TRACE (x , (* meth )(self ,arg ));
4973
- Py_DECREF (arg );
4946
+ stack = (* pp_stack ) - nargs - nkwargs ;
4947
+ C_TRACE (x , _PyCFunction_FastCallKeywords (func , stack , nargs , kwnames ));
4948
+ }
4949
+ else {
4950
+ if (PyMethod_Check (func ) && PyMethod_GET_SELF (func ) != NULL ) {
4951
+ /* optimize access to bound methods */
4952
+ PyObject * self = PyMethod_GET_SELF (func );
4953
+ PCALL (PCALL_METHOD );
4954
+ PCALL (PCALL_BOUND_METHOD );
4955
+ Py_INCREF (self );
4956
+ func = PyMethod_GET_FUNCTION (func );
4957
+ Py_INCREF (func );
4958
+ Py_SETREF (* pfunc , self );
4959
+ nargs ++ ;
4960
+ }
4961
+ else {
4962
+ Py_INCREF (func );
4963
+ }
4974
4964
4975
- x = _Py_CheckFunctionResult (func , x , NULL );
4976
- }
4977
- else {
4978
- err_args (func , flags , nargs );
4979
- x = NULL ;
4980
- }
4965
+ stack = (* pp_stack ) - nargs - nkwargs ;
4966
+
4967
+ READ_TIMESTAMP (* pintr0 );
4968
+ if (PyFunction_Check (func )) {
4969
+ x = fast_function (func , stack , nargs , kwnames );
4981
4970
}
4982
4971
else {
4983
- PyObject * callargs , * kwdict = NULL ;
4984
- if (kwnames != NULL ) {
4985
- kwdict = create_keyword_args (kwnames , pp_stack , func );
4986
- if (kwdict == NULL ) {
4987
- x = NULL ;
4988
- goto cfuncerror ;
4989
- }
4990
- }
4991
- callargs = load_args (pp_stack , nargs );
4992
- if (callargs != NULL ) {
4993
- READ_TIMESTAMP (* pintr0 );
4994
- C_TRACE (x , PyCFunction_Call (func , callargs , kwdict ));
4995
- READ_TIMESTAMP (* pintr1 );
4996
- Py_DECREF (callargs );
4997
- }
4998
- else {
4999
- x = NULL ;
5000
- }
5001
- Py_XDECREF (kwdict );
4972
+ x = _PyObject_FastCallKeywords (func , stack , nargs , kwnames );
5002
4973
}
5003
- }
5004
- else {
5005
- Py_ssize_t nkwargs = (kwnames == NULL ) ? 0 : PyTuple_GET_SIZE (kwnames );
5006
- PyObject * * stack ;
5007
-
5008
- if (PyMethod_Check (func ) && PyMethod_GET_SELF (func ) != NULL ) {
5009
- /* optimize access to bound methods */
5010
- PyObject * self = PyMethod_GET_SELF (func );
5011
- PCALL (PCALL_METHOD );
5012
- PCALL (PCALL_BOUND_METHOD );
5013
- Py_INCREF (self );
5014
- func = PyMethod_GET_FUNCTION (func );
5015
- Py_INCREF (func );
5016
- Py_SETREF (* pfunc , self );
5017
- nargs ++ ;
5018
- }
5019
- else {
5020
- Py_INCREF (func );
5021
- }
5022
-
5023
- stack = (* pp_stack ) - nargs - nkwargs ;
5024
-
5025
- READ_TIMESTAMP (* pintr0 );
5026
- if (PyFunction_Check (func )) {
5027
- x = fast_function (func , stack , nargs , kwnames );
5028
- }
5029
- else {
5030
- x = _PyObject_FastCallKeywords (func , stack , nargs , kwnames );
5031
- }
5032
- READ_TIMESTAMP (* pintr1 );
5033
-
5034
- Py_DECREF (func );
4974
+ READ_TIMESTAMP (* pintr1 );
4975
+
4976
+ Py_DECREF (func );
5035
4977
}
5036
4978
5037
- cfuncerror :
5038
4979
assert ((x != NULL ) ^ (PyErr_Occurred () != NULL ));
5039
4980
5040
4981
/* Clear the stack of the function object. Also removes
@@ -5242,55 +5183,6 @@ _PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs,
5242
5183
return result ;
5243
5184
}
5244
5185
5245
- static PyObject *
5246
- create_keyword_args (PyObject * names , PyObject * * * pp_stack ,
5247
- PyObject * func )
5248
- {
5249
- Py_ssize_t nk = PyTuple_GET_SIZE (names );
5250
- PyObject * kwdict = _PyDict_NewPresized (nk );
5251
- if (kwdict == NULL )
5252
- return NULL ;
5253
- while (-- nk >= 0 ) {
5254
- int err ;
5255
- PyObject * key = PyTuple_GET_ITEM (names , nk );
5256
- PyObject * value = EXT_POP (* pp_stack );
5257
- if (PyDict_GetItem (kwdict , key ) != NULL ) {
5258
- PyErr_Format (PyExc_TypeError ,
5259
- "%.200s%s got multiple values "
5260
- "for keyword argument '%U'" ,
5261
- PyEval_GetFuncName (func ),
5262
- PyEval_GetFuncDesc (func ),
5263
- key );
5264
- Py_DECREF (value );
5265
- Py_DECREF (kwdict );
5266
- return NULL ;
5267
- }
5268
- err = PyDict_SetItem (kwdict , key , value );
5269
- Py_DECREF (value );
5270
- if (err ) {
5271
- Py_DECREF (kwdict );
5272
- return NULL ;
5273
- }
5274
- }
5275
- return kwdict ;
5276
- }
5277
-
5278
- static PyObject *
5279
- load_args (PyObject * * * pp_stack , Py_ssize_t nargs )
5280
- {
5281
- PyObject * args = PyTuple_New (nargs );
5282
-
5283
- if (args == NULL ) {
5284
- return NULL ;
5285
- }
5286
-
5287
- while (-- nargs >= 0 ) {
5288
- PyObject * arg = EXT_POP (* pp_stack );
5289
- PyTuple_SET_ITEM (args , nargs , arg );
5290
- }
5291
- return args ;
5292
- }
5293
-
5294
5186
static PyObject *
5295
5187
do_call_core (PyObject * func , PyObject * callargs , PyObject * kwdict )
5296
5188
{
0 commit comments