@@ -383,26 +383,26 @@ _PyCode_Quicken(PyCodeObject *code)
383
383
#define SPEC_FAIL_CALL_COMPLEX_PARAMETERS 9
384
384
#define SPEC_FAIL_CALL_CO_NOT_OPTIMIZED 10
385
385
/* 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
406
406
407
407
/* COMPARE_OP */
408
408
#define SPEC_FAIL_COMPARE_OP_DIFFERENT_TYPES 12
@@ -1470,18 +1470,17 @@ specialize_class_call(PyObject *callable, _Py_CODEUNIT *instr, int nargs,
1470
1470
1471
1471
#ifdef Py_STATS
1472
1472
static int
1473
- builtin_call_fail_kind (int ml_flags )
1473
+ code_flag_fail_kind (int co_flags , bool is_cfunc )
1474
1474
{
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 |
1476
1477
METH_KEYWORDS | METH_METHOD )) {
1478
+ case METH_NOARGS :
1479
+ return is_cfunc ? SPEC_FAIL_CALL_CFUNCTION_FLAG_NOARGS : SPEC_FAIL_CALL_BAD_CALL_FLAGS ;
1477
1480
case METH_VARARGS :
1478
- return SPEC_FAIL_CALL_PYCFUNCTION ;
1481
+ return is_cfunc ? SPEC_FAIL_CALL_CFUNCTION_FLAG_VARARGS : SPEC_FAIL_CALL_FLAG_VARARGS ;
1479
1482
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 ;
1485
1484
/* This case should never happen with PyCFunctionObject -- only
1486
1485
PyMethodObject. See zlib.compressobj()'s methods for an example.
1487
1486
*/
@@ -1538,7 +1537,7 @@ specialize_method_descriptor(PyMethodDescrObject *descr, _Py_CODEUNIT *instr,
1538
1537
return 0 ;
1539
1538
}
1540
1539
}
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 ));
1542
1541
return -1 ;
1543
1542
}
1544
1543
@@ -1646,8 +1645,7 @@ specialize_c_call(PyObject *callable, _Py_CODEUNIT *instr, int nargs,
1646
1645
return 0 ;
1647
1646
}
1648
1647
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));
1651
1649
return 1 ;
1652
1650
}
1653
1651
}
@@ -1656,37 +1654,17 @@ specialize_c_call(PyObject *callable, _Py_CODEUNIT *instr, int nargs,
1656
1654
static int
1657
1655
call_fail_kind (PyObject * callable )
1658
1656
{
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 )) {
1666
1658
return SPEC_FAIL_CALL_INSTANCE_METHOD ;
1667
1659
}
1668
- else if (PyMethod_Check (callable )) {
1669
- return SPEC_FAIL_CALL_BOUND_METHOD ;
1670
- }
1671
1660
// builtin method
1672
1661
else if (PyCMethod_Check (callable )) {
1673
1662
return SPEC_FAIL_CALL_CMETHOD ;
1674
1663
}
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 )) {
1687
1665
return SPEC_FAIL_CALL_OPERATOR_WRAPPER ;
1688
1666
}
1689
- else if (Py_TYPE (callable ) == & _PyMethodWrapper_Type ) {
1667
+ else if (Py_IS_TYPE (callable , & _PyMethodWrapper_Type ) ) {
1690
1668
return SPEC_FAIL_CALL_METHOD_WRAPPER ;
1691
1669
}
1692
1670
return SPEC_FAIL_OTHER ;
@@ -1718,7 +1696,7 @@ _Py_Specialize_Call(PyObject *callable, _Py_CODEUNIT *instr, int nargs,
1718
1696
fail = specialize_method_descriptor ((PyMethodDescrObject * )callable ,
1719
1697
instr , nargs , kwnames );
1720
1698
}
1721
- else if (Py_TYPE (callable ) == & PyMethod_Type ) {
1699
+ else if (Py_IS_TYPE (callable , & PyMethod_Type ) ) {
1722
1700
PyObject * func = ((PyMethodObject * )callable )-> im_func ;
1723
1701
if (PyFunction_Check (func )) {
1724
1702
fail = specialize_py_call ((PyFunctionObject * )func ,
0 commit comments