@@ -1443,51 +1443,54 @@ _testclinic_TestClass_defclass_posonly_varpos_impl(PyObject *self,
14431443}
14441444
14451445
1446+ /*
1447+ * # Do NOT use __new__ to generate this method. Compare:
1448+ *
1449+ * [1] With __new__ (METH_KEYWORDS must be added even if we don't want to)
1450+ *
1451+ * varpos_no_fastcall(PyTypeObject *type, PyObject *args, PyObject *kwargs)
1452+ * varpos_no_fastcall_impl(PyTypeObject *type, PyObject *args)
1453+ * no auto-generated METHODDEF macro
1454+ *
1455+ * [2] Without __new__ (automatically METH_FASTCALL, not good for this test)
1456+ *
1457+ * varpos_no_fastcall_impl(PyObject *type, PyObject *args)
1458+ * varpos_no_fastcall(PyObject *type, PyObject *const *args, Py_ssize_t nargs)
1459+ * flags = METH_FASTCALL|METH_CLASS
1460+ *
1461+ * [3] Without __new__ + "@disable fastcall" (what we want)
1462+ *
1463+ * varpos_no_fastcall(PyObject *type, PyObject *args)
1464+ * varpos_no_fastcall_impl(PyTypeObject *type, PyObject *args)
1465+ * flags = METH_VARARGS|METH_CLASS
1466+ *
1467+ * We want to test a non-fastcall class method but without triggering an
1468+ * undefined behaviour at runtime in cfunction_call().
1469+ *
1470+ * At runtime, a METH_VARARGS method called in cfunction_call() must be:
1471+ *
1472+ * (PyObject *, PyObject *) -> PyObject *
1473+ * (PyObject *, PyObject *, PyObject *) -> PyObject *
1474+ *
1475+ * depending on whether METH_KEYWORDS is present or not.
1476+ *
1477+ * AC determines whether a method is a __new__-like method solely bsaed
1478+ * on the method name, and not on its usage or its c_basename, and those
1479+ * methods must always be used with METH_VARARGS|METH_KEYWORDS|METH_CLASS.
1480+ *
1481+ * In particular, using [1] forces us to add METH_KEYWORDS even though
1482+ * the test shouldn't be expecting keyword arguments. Using [2] is also
1483+ * not possible since we want to test non-fastcalls. This is the reason
1484+ * why we need to be able to disable the METH_FASTCALL flag.
1485+ */
1486+
14461487/*[clinic input]
14471488@disable fastcall
14481489@classmethod
14491490_testclinic.TestClass.varpos_no_fastcall
14501491
14511492 *args: tuple
14521493
1453- # Do NOT use __new__ to generate this method. Compare:
1454- #
1455- # [1] With __new__ (METH_KEYWORDS must be added even if we don't want to)
1456- #
1457- # varpos_no_fastcall(PyTypeObject *type, PyObject *args, PyObject *kwargs)
1458- # varpos_no_fastcall_impl(PyTypeObject *type, PyObject *args)
1459- # no auto-generated METHODDEF macro
1460- #
1461- # [2] Without __new__ (automatically METH_FASTCALL, not good for this test)
1462- #
1463- # varpos_no_fastcall_impl(PyObject *type, PyObject *args)
1464- # varpos_no_fastcall(PyObject *type, PyObject *const *args, Py_ssize_t nargs)
1465- # flags = METH_FASTCALL|METH_CLASS
1466- #
1467- # [3] Without __new__ + "@disable fastcall" (what we want)
1468- #
1469- # varpos_no_fastcall(PyObject *type, PyObject *args)
1470- # varpos_no_fastcall_impl(PyTypeObject *type, PyObject *args)
1471- # flags = METH_VARARGS|METH_CLASS
1472- #
1473- # We want to test a non-fastcall class method but without triggering an
1474- # undefined behaviour at runtime in cfunction_call().
1475- #
1476- # At runtime, a METH_VARARGS method called in cfunction_call() must be:
1477- #
1478- # (PyObject *, PyObject *) -> PyObject *
1479- # (PyObject *, PyObject *, PyObject *) -> PyObject *
1480- #
1481- # depending on whether METH_KEYWORDS is present or not.
1482- #
1483- # AC determines whether a method is a __new__-like method solely bsaed
1484- # on the method name, and not on its usage or its c_basename, and those
1485- # methods must always be used with METH_VARARGS|METH_KEYWORDS|METH_CLASS.
1486- #
1487- # In particular, using [1] forces us to add METH_KEYWORDS even though
1488- # the test shouldn't be expecting keyword arguments. Using [2] is also
1489- # not possible since we want to test non-fastcalls. This is the reason
1490- # why we need to be able to disable the METH_FASTCALL flag.
14911494[clinic start generated code]*/
14921495
14931496static PyObject *
0 commit comments