This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients Eric Lippert, serhiy.storchaka, vstinner
Date 2018-08-31.08:26:09
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1535703969.53.0.56676864532.issue34551@psf.upfronthosting.co.za>
In-reply-to
Content
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.peters@gmail.com>
Date:   Thu Aug 2 04:15:00 2001 +0000

    Merge of descr-branch back into trunk.
History
Date User Action Args
2018-08-31 08:26:09vstinnersetrecipients: + vstinner, serhiy.storchaka, Eric Lippert
2018-08-31 08:26:09vstinnersetmessageid: <1535703969.53.0.56676864532.issue34551@psf.upfronthosting.co.za>
2018-08-31 08:26:09vstinnerlinkissue34551 messages
2018-08-31 08:26:09vstinnercreate