Message349359
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. |
|
Date |
User |
Action |
Args |
2019-08-10 21:07:30 | Greg Price | set | recipients:
+ Greg Price |
2019-08-10 21:07:30 | Greg Price | set | messageid: <1565471250.77.0.491506074373.issue37812@roundup.psfhosted.org> |
2019-08-10 21:07:30 | Greg Price | link | issue37812 messages |
2019-08-10 21:07:30 | Greg Price | create | |
|