There was an error while loading. Please reload this page.
1 parent 3d19683 commit 04ff762Copy full SHA for 04ff762
1 file changed
Modules/_operator.c
@@ -1576,7 +1576,7 @@ methodcaller_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
1576
{
1577
methodcallerobject *mc;
1578
PyObject *name, *key, *value;
1579
- Py_ssize_t nargs, i, ppos;
+ Py_ssize_t nargs;
1580
1581
if (PyTuple_GET_SIZE(args) < 1) {
1582
PyErr_SetString(PyExc_TypeError, "methodcaller needs at least "
@@ -1622,13 +1622,16 @@ methodcaller_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
1622
memcpy(mc->vectorcall_args + 1, PySequence_Fast_ITEMS(mc->args),
1623
nargs * sizeof(PyObject *));
1624
if (kwds) {
1625
- mc->vectorcall_kwnames = PySequence_Tuple(kwds);
+ const Py_ssize_t nkwds = PyDict_Size(kwds);
1626
+
1627
+ mc->vectorcall_kwnames = PyTuple_New(nkwds);
1628
if (!mc->vectorcall_kwnames) {
1629
return NULL;
1630
}
- i = ppos = 0;
1631
+ Py_ssize_t i = 0, ppos = 0;
1632
while (PyDict_Next(kwds, &ppos, &key, &value)) {
- mc->vectorcall_args[1 + nargs + i] = value;
1633
+ PyTuple_SET_ITEM(mc->vectorcall_kwnames, i, Py_NewRef(key));
1634
+ mc->vectorcall_args[1 + nargs + i] = value; // borrowed reference
1635
++i;
1636
1637
0 commit comments