Skip to content

Commit a737ca5

Browse files
committed
fixup
1 parent 1480166 commit a737ca5

File tree

2 files changed

+80
-57
lines changed

2 files changed

+80
-57
lines changed

Modules/_testclinic.c

Lines changed: 51 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,15 +1446,39 @@ _testclinic_TestClass_defclass_posonly_varpos_impl(PyObject *self,
14461446
/*[clinic input]
14471447
@disable fastcall
14481448
@classmethod
1449-
_testclinic.TestClass.class_method as varpos_no_fastcall
1449+
_testclinic.TestClass.__new__ as varpos_no_fastcall
14501450
14511451
*args: tuple
14521452
1453+
# Do NOT use __new__ to generate this method. Compare:
1454+
#
1455+
# With __new__
1456+
#
1457+
# varpos_no_fastcall_1(PyTypeObject *type, PyObject *args, PyObject *kwargs)
1458+
# varpos_no_fastcall_impl_1(PyTypeObject *type, PyObject *args)
1459+
#
1460+
# Without __new__ and an explicit "@disable fastcall"
1461+
#
1462+
# varpos_no_fastcall_2(PyObject *type, PyObject *args)
1463+
# varpos_no_fastcall_impl_2(PyTypeObject *type, PyObject *args)
1464+
#
1465+
# We want to test a non-fastcall class method (i.e. something like __new__)
1466+
# but without triggering an undefined behaviour at runtime in cfunction_call().
1467+
#
1468+
# At runtime, a METH_VARARGS method called in cfunction_call() must be:
1469+
#
1470+
# (PyObject *, PyObject *) -> PyObject *
1471+
# (PyObject *, PyObject *, PyObject *) -> PyObject *
1472+
#
1473+
# depending on whether METH_KEYWORDS is present or not. Changin AC to make
1474+
# varpos_no_fastcall_1() compatible with cfunction_call() would also affect
1475+
# how the regular __new__ methods are generated (they ALWAYS support 'kwargs').
1476+
# Thus, for testing non-fastcall class methods, "@disable fastcall" is needed.
14531477
[clinic start generated code]*/
14541478

14551479
static PyObject *
14561480
varpos_no_fastcall_impl(PyTypeObject *type, PyObject *args)
1457-
/*[clinic end generated code: output=04e94f2898bb2dde input=10c2251e9ac6baf3]*/
1481+
/*[clinic end generated code: output=04e94f2898bb2dde input=df0b72d3e7784a18]*/
14581482
{
14591483
return Py_NewRef(args);
14601484
}
@@ -1463,7 +1487,7 @@ varpos_no_fastcall_impl(PyTypeObject *type, PyObject *args)
14631487
/*[clinic input]
14641488
@disable fastcall
14651489
@classmethod
1466-
_testclinic.TestClass.class_method as posonly_varpos_no_fastcall
1490+
_testclinic.TestClass.cm as posonly_varpos_no_fastcall
14671491
14681492
a: object
14691493
b: object
@@ -1475,7 +1499,7 @@ _testclinic.TestClass.class_method as posonly_varpos_no_fastcall
14751499
static PyObject *
14761500
posonly_varpos_no_fastcall_impl(PyTypeObject *type, PyObject *a, PyObject *b,
14771501
PyObject *args)
1478-
/*[clinic end generated code: output=b0a0425719f69f5a input=f7c75501a787c7af]*/
1502+
/*[clinic end generated code: output=b0a0425719f69f5a input=c8870f84456e68be]*/
14791503
{
14801504
return pack_arguments_newref(3, a, b, args);
14811505
}
@@ -1484,7 +1508,7 @@ posonly_varpos_no_fastcall_impl(PyTypeObject *type, PyObject *a, PyObject *b,
14841508
/*[clinic input]
14851509
@disable fastcall
14861510
@classmethod
1487-
_testclinic.TestClass.class_method as posonly_req_opt_varpos_no_fastcall
1511+
_testclinic.TestClass.cm as posonly_req_opt_varpos_no_fastcall
14881512
14891513
a: object
14901514
b: object = False
@@ -1496,7 +1520,7 @@ _testclinic.TestClass.class_method as posonly_req_opt_varpos_no_fastcall
14961520
static PyObject *
14971521
posonly_req_opt_varpos_no_fastcall_impl(PyTypeObject *type, PyObject *a,
14981522
PyObject *b, PyObject *args)
1499-
/*[clinic end generated code: output=3c44915b1a554e2d input=701bf93e7572e6b3]*/
1523+
/*[clinic end generated code: output=3c44915b1a554e2d input=9e29ef335e399e8e]*/
15001524
{
15011525
return pack_arguments_newref(3, a, b, args);
15021526
}
@@ -1505,7 +1529,7 @@ posonly_req_opt_varpos_no_fastcall_impl(PyTypeObject *type, PyObject *a,
15051529
/*[clinic input]
15061530
@disable fastcall
15071531
@classmethod
1508-
_testclinic.TestClass.class_method as posonly_poskw_varpos_no_fastcall
1532+
_testclinic.TestClass.cm as posonly_poskw_varpos_no_fastcall
15091533
15101534
a: object
15111535
/
@@ -1517,7 +1541,7 @@ _testclinic.TestClass.class_method as posonly_poskw_varpos_no_fastcall
15171541
static PyObject *
15181542
posonly_poskw_varpos_no_fastcall_impl(PyTypeObject *type, PyObject *a,
15191543
PyObject *b, PyObject *args)
1520-
/*[clinic end generated code: output=6ad74bed4bdc7f96 input=2bbbc74dc92ba7ba]*/
1544+
/*[clinic end generated code: output=6ad74bed4bdc7f96 input=66226ea6c3d38c36]*/
15211545
{
15221546
return pack_arguments_newref(3, a, b, args);
15231547
}
@@ -1526,7 +1550,7 @@ posonly_poskw_varpos_no_fastcall_impl(PyTypeObject *type, PyObject *a,
15261550
/*[clinic input]
15271551
@disable fastcall
15281552
@classmethod
1529-
_testclinic.TestClass.class_method as varpos_array_no_fastcall
1553+
_testclinic.TestClass.cm as varpos_array_no_fastcall
15301554
15311555
*args: array
15321556
@@ -1535,7 +1559,7 @@ _testclinic.TestClass.class_method as varpos_array_no_fastcall
15351559
static PyObject *
15361560
varpos_array_no_fastcall_impl(PyTypeObject *type, PyObject * const *args,
15371561
Py_ssize_t args_length)
1538-
/*[clinic end generated code: output=f99d984346c60d42 input=de625878254ecac0]*/
1562+
/*[clinic end generated code: output=f99d984346c60d42 input=52b2e8011dbee112]*/
15391563
{
15401564
return _PyTuple_FromArray(args, args_length);
15411565
}
@@ -1544,7 +1568,7 @@ varpos_array_no_fastcall_impl(PyTypeObject *type, PyObject * const *args,
15441568
/*[clinic input]
15451569
@disable fastcall
15461570
@classmethod
1547-
_testclinic.TestClass.class_method as posonly_varpos_array_no_fastcall
1571+
_testclinic.TestClass.cm as posonly_varpos_array_no_fastcall
15481572
15491573
a: object
15501574
b: object
@@ -1557,7 +1581,7 @@ static PyObject *
15571581
posonly_varpos_array_no_fastcall_impl(PyTypeObject *type, PyObject *a,
15581582
PyObject *b, PyObject * const *args,
15591583
Py_ssize_t args_length)
1560-
/*[clinic end generated code: output=1eec4da1fb5b5978 input=15adeb514423f485]*/
1584+
/*[clinic end generated code: output=1eec4da1fb5b5978 input=78fd1e9358b8987f]*/
15611585
{
15621586
return pack_arguments_2pos_varpos(a, b, args, args_length);
15631587
}
@@ -1566,7 +1590,7 @@ posonly_varpos_array_no_fastcall_impl(PyTypeObject *type, PyObject *a,
15661590
/*[clinic input]
15671591
@disable fastcall
15681592
@classmethod
1569-
_testclinic.TestClass.class_method as posonly_req_opt_varpos_array_no_fastcall
1593+
_testclinic.TestClass.cm as posonly_req_opt_varpos_array_no_fastcall
15701594
15711595
a: object
15721596
b: object = False
@@ -1580,7 +1604,7 @@ posonly_req_opt_varpos_array_no_fastcall_impl(PyTypeObject *type,
15801604
PyObject *a, PyObject *b,
15811605
PyObject * const *args,
15821606
Py_ssize_t args_length)
1583-
/*[clinic end generated code: output=88041c2176135218 input=445ff173a49709d5]*/
1607+
/*[clinic end generated code: output=88041c2176135218 input=f730318da80b94c1]*/
15841608
{
15851609
return pack_arguments_2pos_varpos(a, b, args, args_length);
15861610
}
@@ -1589,7 +1613,7 @@ posonly_req_opt_varpos_array_no_fastcall_impl(PyTypeObject *type,
15891613
/*[clinic input]
15901614
@disable fastcall
15911615
@classmethod
1592-
_testclinic.TestClass.class_method as posonly_poskw_varpos_array_no_fastcall
1616+
_testclinic.TestClass.cm as posonly_poskw_varpos_array_no_fastcall
15931617
15941618
a: object
15951619
/
@@ -1603,7 +1627,7 @@ posonly_poskw_varpos_array_no_fastcall_impl(PyTypeObject *type, PyObject *a,
16031627
PyObject *b,
16041628
PyObject * const *args,
16051629
Py_ssize_t args_length)
1606-
/*[clinic end generated code: output=70eda18c3667681e input=c0ac0f6b990f553c]*/
1630+
/*[clinic end generated code: output=70eda18c3667681e input=a98374a618ec8d36]*/
16071631
{
16081632
return pack_arguments_2pos_varpos(a, b, args, args_length);
16091633
}
@@ -1614,24 +1638,25 @@ static struct PyMethodDef test_class_methods[] = {
16141638
_TESTCLINIC_TESTCLASS_DEFCLASS_VARPOS_METHODDEF
16151639
_TESTCLINIC_TESTCLASS_DEFCLASS_POSONLY_VARPOS_METHODDEF
16161640

1617-
{"varpos_no_fastcall", _PyCFunction_CAST(varpos_no_fastcall),
1641+
{"varpos_no_fastcall", varpos_no_fastcall,
16181642
METH_VARARGS|METH_CLASS, ""},
1619-
{"posonly_varpos_no_fastcall", _PyCFunction_CAST(posonly_varpos_no_fastcall),
1643+
{"posonly_varpos_no_fastcall", posonly_varpos_no_fastcall,
16201644
METH_VARARGS|METH_CLASS, ""},
1621-
{"posonly_req_opt_varpos_no_fastcall", _PyCFunction_CAST(posonly_req_opt_varpos_no_fastcall),
1645+
{"posonly_req_opt_varpos_no_fastcall", posonly_req_opt_varpos_no_fastcall,
16221646
METH_VARARGS|METH_CLASS, ""},
1623-
{"posonly_poskw_varpos_no_fastcall", _PyCFunction_CAST(posonly_poskw_varpos_no_fastcall),
1647+
{"posonly_poskw_varpos_no_fastcall",
1648+
_PyCFunction_CAST(posonly_poskw_varpos_no_fastcall),
16241649
METH_VARARGS|METH_KEYWORDS|METH_CLASS, ""},
16251650

16261651
{"varpos_array_no_fastcall",
1627-
_PyCFunction_CAST(varpos_array_no_fastcall),
1628-
METH_VARARGS|METH_KEYWORDS|METH_CLASS, ""},
1652+
varpos_array_no_fastcall,
1653+
METH_VARARGS|METH_CLASS, ""},
16291654
{"posonly_varpos_array_no_fastcall",
1630-
_PyCFunction_CAST(posonly_varpos_array_no_fastcall),
1631-
METH_VARARGS|METH_KEYWORDS|METH_CLASS, ""},
1655+
posonly_varpos_array_no_fastcall,
1656+
METH_VARARGS|METH_CLASS, ""},
16321657
{"posonly_req_opt_varpos_array_no_fastcall",
1633-
_PyCFunction_CAST(posonly_req_opt_varpos_array_no_fastcall),
1634-
METH_VARARGS|METH_KEYWORDS|METH_CLASS, ""},
1658+
posonly_req_opt_varpos_array_no_fastcall,
1659+
METH_VARARGS|METH_CLASS, ""},
16351660
{"posonly_poskw_varpos_array_no_fastcall",
16361661
_PyCFunction_CAST(posonly_poskw_varpos_array_no_fastcall),
16371662
METH_VARARGS|METH_KEYWORDS|METH_CLASS, ""},

0 commit comments

Comments
 (0)