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 Greg Price
Recipients Greg Price
Date 2019-08-10.21:07:30
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1565471250.77.0.491506074373.issue37812@roundup.psfhosted.org>
In-reply-to
Content
In longobject.c we have the following usage a few times:

PyObject *
PyLong_FromLong(long ival)
{
    PyLongObject *v;
    // ... more locals ...

    CHECK_SMALL_INT(ival);

    if (ival < 0) {
        /* negate: can't write this as abs_ival = -ival since that
           invokes undefined behaviour when ival is LONG_MIN */
        abs_ival = 0U-(unsigned long)ival;
        sign = -1;
    }
    else {
    // ... etc. etc.

The CHECK_SMALL_INT macro contains a `return`, so the function can actually return before it reaches any of the other code.

#define CHECK_SMALL_INT(ival) \
    do if (-NSMALLNEGINTS <= ival && ival < NSMALLPOSINTS) { \
        return get_small_int((sdigit)ival); \
    } while(0)

That's not even an error condition -- in fact it's the fast, hopefully reasonably-common, path.

An implicit return like this is pretty surprising for the reader. And it only takes one more line (plus a close-brace) to make it explicit:

    if (IS_SMALL_INT(ival)) {
        return get_small_int((sdigit)ival);
    }

so that seems like a much better trade.

Patch written, will post shortly.
History
Date User Action Args
2019-08-10 21:07:30Greg Pricesetrecipients: + Greg Price
2019-08-10 21:07:30Greg Pricesetmessageid: <1565471250.77.0.491506074373.issue37812@roundup.psfhosted.org>
2019-08-10 21:07:30Greg Pricelinkissue37812 messages
2019-08-10 21:07:30Greg Pricecreate