@@ -383,26 +383,26 @@ _PyCode_Quicken(PyCodeObject *code)
383383#define SPEC_FAIL_CALL_COMPLEX_PARAMETERS 9
384384#define SPEC_FAIL_CALL_CO_NOT_OPTIMIZED 10
385385/* SPEC_FAIL_METHOD defined as 11 above */
386-
387- #define SPEC_FAIL_CALL_INSTANCE_METHOD 11
388- #define SPEC_FAIL_CALL_CMETHOD 12
389- #define SPEC_FAIL_CALL_PYCFUNCTION 13
390- #define SPEC_FAIL_CALL_PYCFUNCTION_WITH_KEYWORDS 14
391- #define SPEC_FAIL_CALL_PYCFUNCTION_FAST_WITH_KEYWORDS 15
392- #define SPEC_FAIL_CALL_PYCFUNCTION_NOARGS 16
393- #define SPEC_FAIL_CALL_BAD_CALL_FLAGS 17
394- #define SPEC_FAIL_CALL_CLASS 18
395- #define SPEC_FAIL_CALL_PYTHON_CLASS 19
396- #define SPEC_FAIL_CALL_METHOD_DESCRIPTOR 20
397- #define SPEC_FAIL_CALL_BOUND_METHOD 21
398- #define SPEC_FAIL_CALL_STR 22
399- #define SPEC_FAIL_CALL_CLASS_NO_VECTORCALL 23
400- #define SPEC_FAIL_CALL_CLASS_MUTABLE 24
401- #define SPEC_FAIL_CALL_KWNAMES 25
402- #define SPEC_FAIL_CALL_METHOD_WRAPPER 26
403- #define SPEC_FAIL_CALL_OPERATOR_WRAPPER 27
404- #define SPEC_FAIL_CALL_PYFUNCTION 28
405- #define SPEC_FAIL_CALL_PEP_523 29
386+ /* code flag kind */
387+ #define SPEC_FAIL_CALL_CFUNCTION_FLAG_NOARGS 11
388+ #define SPEC_FAIL_CALL_CFUNCTION_FLAG_VARARGS 12
389+ #define SPEC_FAIL_CALL_CFUNCTION_FLAG_VARARGS_KW 13
390+ #define SPEC_FAIL_CALL_FLAG_VARARGS 14
391+ #define SPEC_FAIL_CALL_FLAG_VARARGS_KW 15
392+ #define SPEC_FAIL_CALL_BAD_CALL_FLAGS 16
393+ /* callable type kind */
394+ #define SPEC_FAIL_CALL_INSTANCE_METHOD 17
395+ #define SPEC_FAIL_CALL_CMETHOD 18
396+ #define SPEC_FAIL_CALL_OPERATOR_WRAPPER 19
397+ #define SPEC_FAIL_CALL_METHOD_WRAPPER 20
398+ /* unsupported cases */
399+ #define SPEC_FAIL_CALL_PYTHON_CLASS 21
400+ #define SPEC_FAIL_CALL_BOUND_METHOD 22
401+ #define SPEC_FAIL_CALL_STR 23
402+ #define SPEC_FAIL_CALL_CLASS_NO_VECTORCALL 24
403+ #define SPEC_FAIL_CALL_CLASS_MUTABLE 25
404+ #define SPEC_FAIL_CALL_KWNAMES 26
405+ #define SPEC_FAIL_CALL_PEP_523 27
406406
407407/* COMPARE_OP */
408408#define SPEC_FAIL_COMPARE_OP_DIFFERENT_TYPES 12
@@ -1470,18 +1470,17 @@ specialize_class_call(PyObject *callable, _Py_CODEUNIT *instr, int nargs,
14701470
14711471#ifdef Py_STATS
14721472static int
1473- builtin_call_fail_kind (int ml_flags )
1473+ code_flag_fail_kind (int co_flags , bool is_cfunc )
14741474{
1475- switch (ml_flags & (METH_VARARGS | METH_FASTCALL | METH_NOARGS | METH_O |
1475+ switch (co_flags &
1476+ (METH_VARARGS | METH_FASTCALL | METH_NOARGS | METH_O |
14761477 METH_KEYWORDS | METH_METHOD )) {
1478+ case METH_NOARGS :
1479+ return is_cfunc ? SPEC_FAIL_CALL_CFUNCTION_FLAG_NOARGS : SPEC_FAIL_CALL_BAD_CALL_FLAGS ;
14771480 case METH_VARARGS :
1478- return SPEC_FAIL_CALL_PYCFUNCTION ;
1481+ return is_cfunc ? SPEC_FAIL_CALL_CFUNCTION_FLAG_VARARGS : SPEC_FAIL_CALL_FLAG_VARARGS ;
14791482 case METH_VARARGS | METH_KEYWORDS :
1480- return SPEC_FAIL_CALL_PYCFUNCTION_WITH_KEYWORDS ;
1481- case METH_FASTCALL | METH_KEYWORDS :
1482- return SPEC_FAIL_CALL_PYCFUNCTION_FAST_WITH_KEYWORDS ;
1483- case METH_NOARGS :
1484- return SPEC_FAIL_CALL_PYCFUNCTION_NOARGS ;
1483+ return is_cfunc ? SPEC_FAIL_CALL_CFUNCTION_FLAG_VARARGS_KW : SPEC_FAIL_CALL_FLAG_VARARGS_KW ;
14851484 /* This case should never happen with PyCFunctionObject -- only
14861485 PyMethodObject. See zlib.compressobj()'s methods for an example.
14871486 */
@@ -1538,7 +1537,7 @@ specialize_method_descriptor(PyMethodDescrObject *descr, _Py_CODEUNIT *instr,
15381537 return 0 ;
15391538 }
15401539 }
1541- SPECIALIZATION_FAIL (CALL , builtin_call_fail_kind (descr -> d_method -> ml_flags ));
1540+ SPECIALIZATION_FAIL (CALL , code_flag_fail_kind (descr -> d_method -> ml_flags , false ));
15421541 return -1 ;
15431542}
15441543
@@ -1646,8 +1645,7 @@ specialize_c_call(PyObject *callable, _Py_CODEUNIT *instr, int nargs,
16461645 return 0 ;
16471646 }
16481647 default :
1649- SPECIALIZATION_FAIL (CALL ,
1650- builtin_call_fail_kind (PyCFunction_GET_FLAGS (callable )));
1648+ SPECIALIZATION_FAIL (CALL , code_flag_fail_kind (PyCFunction_GET_FLAGS (callable ), true));
16511649 return 1 ;
16521650 }
16531651}
@@ -1656,37 +1654,17 @@ specialize_c_call(PyObject *callable, _Py_CODEUNIT *instr, int nargs,
16561654static int
16571655call_fail_kind (PyObject * callable )
16581656{
1659- if (PyCFunction_CheckExact (callable )) {
1660- return SPEC_FAIL_CALL_PYCFUNCTION ;
1661- }
1662- else if (PyFunction_Check (callable )) {
1663- return SPEC_FAIL_CALL_PYFUNCTION ;
1664- }
1665- else if (PyInstanceMethod_Check (callable )) {
1657+ if (PyInstanceMethod_Check (callable )) {
16661658 return SPEC_FAIL_CALL_INSTANCE_METHOD ;
16671659 }
1668- else if (PyMethod_Check (callable )) {
1669- return SPEC_FAIL_CALL_BOUND_METHOD ;
1670- }
16711660 // builtin method
16721661 else if (PyCMethod_Check (callable )) {
16731662 return SPEC_FAIL_CALL_CMETHOD ;
16741663 }
1675- else if (PyType_Check (callable )) {
1676- if (((PyTypeObject * )callable )-> tp_new == PyBaseObject_Type .tp_new ) {
1677- return SPEC_FAIL_CALL_PYTHON_CLASS ;
1678- }
1679- else {
1680- return SPEC_FAIL_CALL_CLASS ;
1681- }
1682- }
1683- else if (Py_IS_TYPE (callable , & PyMethodDescr_Type )) {
1684- return SPEC_FAIL_CALL_METHOD_DESCRIPTOR ;
1685- }
1686- else if (Py_TYPE (callable ) == & PyWrapperDescr_Type ) {
1664+ else if (Py_IS_TYPE (callable , & PyWrapperDescr_Type )) {
16871665 return SPEC_FAIL_CALL_OPERATOR_WRAPPER ;
16881666 }
1689- else if (Py_TYPE (callable ) == & _PyMethodWrapper_Type ) {
1667+ else if (Py_IS_TYPE (callable , & _PyMethodWrapper_Type ) ) {
16901668 return SPEC_FAIL_CALL_METHOD_WRAPPER ;
16911669 }
16921670 return SPEC_FAIL_OTHER ;
@@ -1718,7 +1696,7 @@ _Py_Specialize_Call(PyObject *callable, _Py_CODEUNIT *instr, int nargs,
17181696 fail = specialize_method_descriptor ((PyMethodDescrObject * )callable ,
17191697 instr , nargs , kwnames );
17201698 }
1721- else if (Py_TYPE (callable ) == & PyMethod_Type ) {
1699+ else if (Py_IS_TYPE (callable , & PyMethod_Type ) ) {
17221700 PyObject * func = ((PyMethodObject * )callable )-> im_func ;
17231701 if (PyFunction_Check (func )) {
17241702 fail = specialize_py_call ((PyFunctionObject * )func ,
0 commit comments