@@ -394,23 +394,21 @@ _PyCode_Quicken(PyCodeObject *code)
394
394
395
395
#define SPEC_FAIL_CALL_INSTANCE_METHOD 11
396
396
#define SPEC_FAIL_CALL_CMETHOD 12
397
- #define SPEC_FAIL_CALL_PYCFUNCTION 13
398
- #define SPEC_FAIL_CALL_PYCFUNCTION_WITH_KEYWORDS 14
399
- #define SPEC_FAIL_CALL_PYCFUNCTION_FAST_WITH_KEYWORDS 15
400
- #define SPEC_FAIL_CALL_PYCFUNCTION_NOARGS 16
397
+ #define SPEC_FAIL_CALL_CFUNC_VARARGS 13
398
+ #define SPEC_FAIL_CALL_CFUNC_VARARGS_KEYWORDS 14
399
+ #define SPEC_FAIL_CALL_CFUNC_FASTCALL_KEYWORDS 15
400
+ #define SPEC_FAIL_CALL_CFUNC_NOARGS 16
401
401
#define SPEC_FAIL_CALL_BAD_CALL_FLAGS 17
402
- #define SPEC_FAIL_CALL_CLASS 18
402
+ #define SPEC_FAIL_CALL_CFUNC_METHOD_FASTCALL_KEYWORDS 18
403
403
#define SPEC_FAIL_CALL_PYTHON_CLASS 19
404
- #define SPEC_FAIL_CALL_METHOD_DESCRIPTOR 20
404
+ #define SPEC_FAIL_CALL_PEP_523 20
405
405
#define SPEC_FAIL_CALL_BOUND_METHOD 21
406
406
#define SPEC_FAIL_CALL_STR 22
407
407
#define SPEC_FAIL_CALL_CLASS_NO_VECTORCALL 23
408
408
#define SPEC_FAIL_CALL_CLASS_MUTABLE 24
409
409
#define SPEC_FAIL_CALL_KWNAMES 25
410
410
#define SPEC_FAIL_CALL_METHOD_WRAPPER 26
411
411
#define SPEC_FAIL_CALL_OPERATOR_WRAPPER 27
412
- #define SPEC_FAIL_CALL_PYFUNCTION 28
413
- #define SPEC_FAIL_CALL_PEP_523 29
414
412
415
413
/* COMPARE_OP */
416
414
#define SPEC_FAIL_COMPARE_OP_DIFFERENT_TYPES 12
@@ -1517,17 +1515,19 @@ builtin_call_fail_kind(int ml_flags)
1517
1515
switch (ml_flags & (METH_VARARGS | METH_FASTCALL | METH_NOARGS | METH_O |
1518
1516
METH_KEYWORDS | METH_METHOD )) {
1519
1517
case METH_VARARGS :
1520
- return SPEC_FAIL_CALL_PYCFUNCTION ;
1518
+ return SPEC_FAIL_CALL_CFUNC_VARARGS ;
1521
1519
case METH_VARARGS | METH_KEYWORDS :
1522
- return SPEC_FAIL_CALL_PYCFUNCTION_WITH_KEYWORDS ;
1520
+ return SPEC_FAIL_CALL_CFUNC_VARARGS_KEYWORDS ;
1523
1521
case METH_FASTCALL | METH_KEYWORDS :
1524
- return SPEC_FAIL_CALL_PYCFUNCTION_FAST_WITH_KEYWORDS ;
1522
+ return SPEC_FAIL_CALL_CFUNC_FASTCALL_KEYWORDS ;
1525
1523
case METH_NOARGS :
1526
- return SPEC_FAIL_CALL_PYCFUNCTION_NOARGS ;
1527
- /* This case should never happen with PyCFunctionObject -- only
1528
- PyMethodObject. See zlib.compressobj()'s methods for an example.
1529
- */
1524
+ return SPEC_FAIL_CALL_CFUNC_NOARGS ;
1530
1525
case METH_METHOD | METH_FASTCALL | METH_KEYWORDS :
1526
+ return SPEC_FAIL_CALL_CFUNC_METHOD_FASTCALL_KEYWORDS ;
1527
+ /* These cases should be optimized, but return "other" just in case */
1528
+ case METH_O :
1529
+ case METH_FASTCALL :
1530
+ return SPEC_FAIL_OTHER ;
1531
1531
default :
1532
1532
return SPEC_FAIL_CALL_BAD_CALL_FLAGS ;
1533
1533
}
@@ -1698,33 +1698,18 @@ specialize_c_call(PyObject *callable, _Py_CODEUNIT *instr, int nargs,
1698
1698
static int
1699
1699
call_fail_kind (PyObject * callable )
1700
1700
{
1701
- if (PyCFunction_CheckExact (callable )) {
1702
- return SPEC_FAIL_CALL_PYCFUNCTION ;
1703
- }
1704
- else if (PyFunction_Check (callable )) {
1705
- return SPEC_FAIL_CALL_PYFUNCTION ;
1706
- }
1707
- else if (PyInstanceMethod_Check (callable )) {
1701
+ assert (!PyCFunction_CheckExact (callable ));
1702
+ assert (!PyFunction_Check (callable ));
1703
+ assert (!PyType_Check (callable ));
1704
+ assert (!Py_IS_TYPE (callable , & PyMethodDescr_Type ));
1705
+ assert (!PyMethod_Check (callable ));
1706
+ if (PyInstanceMethod_Check (callable )) {
1708
1707
return SPEC_FAIL_CALL_INSTANCE_METHOD ;
1709
1708
}
1710
- else if (PyMethod_Check (callable )) {
1711
- return SPEC_FAIL_CALL_BOUND_METHOD ;
1712
- }
1713
1709
// builtin method
1714
1710
else if (PyCMethod_Check (callable )) {
1715
1711
return SPEC_FAIL_CALL_CMETHOD ;
1716
1712
}
1717
- else if (PyType_Check (callable )) {
1718
- if (((PyTypeObject * )callable )-> tp_new == PyBaseObject_Type .tp_new ) {
1719
- return SPEC_FAIL_CALL_PYTHON_CLASS ;
1720
- }
1721
- else {
1722
- return SPEC_FAIL_CALL_CLASS ;
1723
- }
1724
- }
1725
- else if (Py_IS_TYPE (callable , & PyMethodDescr_Type )) {
1726
- return SPEC_FAIL_CALL_METHOD_DESCRIPTOR ;
1727
- }
1728
1713
else if (Py_TYPE (callable ) == & PyWrapperDescr_Type ) {
1729
1714
return SPEC_FAIL_CALL_OPERATOR_WRAPPER ;
1730
1715
}
@@ -1760,7 +1745,7 @@ _Py_Specialize_Call(PyObject *callable, _Py_CODEUNIT *instr, int nargs,
1760
1745
fail = specialize_method_descriptor ((PyMethodDescrObject * )callable ,
1761
1746
instr , nargs , kwnames );
1762
1747
}
1763
- else if (Py_TYPE (callable ) == & PyMethod_Type ) {
1748
+ else if (PyMethod_Check (callable )) {
1764
1749
PyObject * func = ((PyMethodObject * )callable )-> im_func ;
1765
1750
if (PyFunction_Check (func )) {
1766
1751
fail = specialize_py_call ((PyFunctionObject * )func ,
0 commit comments