STINNER Victor <vstin...@redhat.com> added the comment:

Technically it's possible that the dictionary mutates itself during iterating 
and so that it's size change, so "nk = i / 2;" make sure that we pass the 
proper length to the function call.

Maybe I'm wrong, but we would need an unit test for that.

While I reworked a lot of code in call.c (and I moved code to call.c ;-)), this 
specific statement already existed before my work. I moved it from somewhere 
else. Extract of Objects/funcobject.c:

static PyObject *
function_call(PyObject *func, PyObject *arg, PyObject *kw)
{
    ...
    if (kw != NULL && PyDict_Check(kw)) {
        ...
        while (PyDict_Next(kw, &pos, &k[i], &k[i+1])) {
            Py_INCREF(k[i]);
            Py_INCREF(k[i+1]);
            i += 2;
        }
        nk = i/2;
    }
    ...
}

It seems like the code is quite old :-)

commit 6d6c1a35e08b95a83dbe47dbd9e6474daff00354
Author: Tim Peters <tim.pet...@gmail.com>
Date:   Thu Aug 2 04:15:00 2001 +0000

    Merge of descr-branch back into trunk.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue34551>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to