[issue46361] Small ints aren't always cached properly

Mark Dickinson report at bugs.python.org
Thu Jan 13 03:43:53 EST 2022


Mark Dickinson <dickinsm at gmail.com> added the comment:

Hmm. This sort of thing is a little dodgy, though (despite the comment that it's "okay"): 

https://github.com/python/cpython/blob/1de60155d5d01be2924e72fb68dd13d4fd00acd7/Modules/mathmodule.c#L939

    PyObject *zero = _PyLong_GetZero();  // borrowed ref
    for (i = 1; i < nargs; i++) {
        /* --- 8< --- snipped code */
        if (res == zero) {
            /* Fast path: just check arguments.
               It is okay to use identity comparison here. */
            Py_DECREF(x);
            continue;
        }
        /* --- 8< --- snipped code*/
    }

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46361>
_______________________________________


More information about the Python-bugs-list mailing list