Skip to content

Commit ff57cf7

Browse files
committed
More stylistic syncs with PYLONG_FROM_UINT
1 parent 98b3668 commit ff57cf7

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

Objects/longobject.c

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -336,30 +336,31 @@ _PyLong_Negate(PyLongObject **x_p)
336336
do { \
337337
/* Handle small and medium cases. */ \
338338
if (IS_SMALL_INT(ival)) { \
339-
return get_small_int((sdigit)ival); \
339+
return get_small_int((sdigit)(ival)); \
340340
} \
341-
if (-(INT_TYPE)PyLong_MASK <= ival && ival <= (INT_TYPE)PyLong_MASK) { \
342-
return _PyLong_FromMedium((sdigit)ival); \
341+
if (-(INT_TYPE)PyLong_MASK <= (ival) && (ival) <= (INT_TYPE)PyLong_MASK) { \
342+
return _PyLong_FromMedium((sdigit)(ival)); \
343343
} \
344-
/* Count digits (at least two - smaller cases were handled above). */ \
345-
UINT_TYPE abs_ival = ival < 0 ? 0U-(UINT_TYPE)ival : (UINT_TYPE)ival; \
344+
UINT_TYPE abs_ival = (ival) < 0 ? 0U-(UINT_TYPE)(ival) : (UINT_TYPE)(ival); \
346345
/* Do shift in two steps to avoid possible undefined behavior. */ \
347346
UINT_TYPE t = abs_ival >> PyLong_SHIFT >> PyLong_SHIFT; \
348-
int ndigits = 2; \
347+
/* Count digits (at least two - smaller cases were handled above). */ \
348+
Py_ssize_t ndigits = 2; \
349349
while (t) { \
350350
++ndigits; \
351351
t >>= PyLong_SHIFT; \
352352
} \
353353
/* Construct output value. */ \
354354
PyLongObject *v = long_alloc(ndigits); \
355-
if (v != NULL) { \
356-
digit *p = v->long_value.ob_digit; \
357-
_PyLong_SetSignAndDigitCount(v, ival < 0 ? -1 : 1, ndigits); \
358-
t = abs_ival; \
359-
while (t) { \
360-
*p++ = (digit)(t & PyLong_MASK); \
361-
t >>= PyLong_SHIFT; \
362-
} \
355+
if (v == NULL) { \
356+
return NULL; \
357+
} \
358+
digit *p = v->long_value.ob_digit; \
359+
_PyLong_SetSignAndDigitCount(v, (ival) < 0 ? -1 : 1, ndigits); \
360+
t = abs_ival; \
361+
while (t) { \
362+
*p++ = (digit)(t & PyLong_MASK); \
363+
t >>= PyLong_SHIFT; \
363364
} \
364365
return (PyObject *)v; \
365366
} while(0)
@@ -375,6 +376,7 @@ PyLong_FromLong(long ival)
375376

376377
#define PYLONG_FROM_UINT(INT_TYPE, ival) \
377378
do { \
379+
/* Handle small and medium cases. */ \
378380
if (IS_SMALL_UINT(ival)) { \
379381
return get_small_int((sdigit)(ival)); \
380382
} \
@@ -383,12 +385,13 @@ PyLong_FromLong(long ival)
383385
} \
384386
/* Do shift in two steps to avoid possible undefined behavior. */ \
385387
INT_TYPE t = (ival) >> PyLong_SHIFT >> PyLong_SHIFT; \
386-
/* Count the number of Python digits. */ \
388+
/* Count digits (at least two - smaller cases were handled above). */ \
387389
Py_ssize_t ndigits = 2; \
388390
while (t) { \
389391
++ndigits; \
390392
t >>= PyLong_SHIFT; \
391393
} \
394+
/* Construct output value. */ \
392395
PyLongObject *v = long_alloc(ndigits); \
393396
if (v == NULL) { \
394397
return NULL; \

0 commit comments

Comments
 (0)