Skip to content

Commit 1f9f69d

Browse files
sir-sigurdvstinner
authored andcommitted
bpo-27961: Replace PY_LLONG_MAX, PY_LLONG_MIN and PY_ULLONG_MAX with standard macros (GH-15385)
Use standard constants LLONG_MIN, LLONG_MAX and ULLONG_MAX.
1 parent 99eb70a commit 1f9f69d

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

Doc/c-api/long.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
195195
:meth:`__int__` method (if present) to convert it to a
196196
:c:type:`PyLongObject`.
197197
198-
If the value of *obj* is greater than :const:`PY_LLONG_MAX` or less than
199-
:const:`PY_LLONG_MIN`, set *\*overflow* to ``1`` or ``-1``, respectively,
198+
If the value of *obj* is greater than :const:`LLONG_MAX` or less than
199+
:const:`LLONG_MIN`, set *\*overflow* to ``1`` or ``-1``, respectively,
200200
and return ``-1``; otherwise, set *\*overflow* to ``0``. If any other
201201
exception occurs set *\*overflow* to ``0`` and return ``-1`` as usual.
202202

Include/pythread.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,16 @@ PyAPI_FUNC(int) PyThread_acquire_lock(PyThread_type_lock, int);
5151
#if defined(_POSIX_THREADS)
5252
/* PyThread_acquire_lock_timed() uses _PyTime_FromNanoseconds(us * 1000),
5353
convert microseconds to nanoseconds. */
54-
# define PY_TIMEOUT_MAX (PY_LLONG_MAX / 1000)
54+
# define PY_TIMEOUT_MAX (LLONG_MAX / 1000)
5555
#elif defined (NT_THREADS)
5656
/* In the NT API, the timeout is a DWORD and is expressed in milliseconds */
57-
# if 0xFFFFFFFFLL * 1000 < PY_LLONG_MAX
57+
# if 0xFFFFFFFFLL * 1000 < LLONG_MAX
5858
# define PY_TIMEOUT_MAX (0xFFFFFFFFLL * 1000)
5959
# else
60-
# define PY_TIMEOUT_MAX PY_LLONG_MAX
60+
# define PY_TIMEOUT_MAX LLONG_MAX
6161
# endif
6262
#else
63-
# define PY_TIMEOUT_MAX PY_LLONG_MAX
63+
# define PY_TIMEOUT_MAX LLONG_MAX
6464
#endif
6565

6666

Modules/_testcapimodule.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ test_long_long_and_overflow(PyObject *self, PyObject *Py_UNUSED(ignored))
639639
int overflow;
640640

641641
/* Test that overflow is set properly for a large value. */
642-
/* num is a number larger than PY_LLONG_MAX on a typical machine. */
642+
/* num is a number larger than LLONG_MAX on a typical machine. */
643643
num = PyLong_FromString("FFFFFFFFFFFFFFFFFFFFFFFF", NULL, 16);
644644
if (num == NULL)
645645
return NULL;
@@ -655,8 +655,8 @@ test_long_long_and_overflow(PyObject *self, PyObject *Py_UNUSED(ignored))
655655
return raiseTestError("test_long_long_and_overflow",
656656
"overflow was not set to 1");
657657

658-
/* Same again, with num = PY_LLONG_MAX + 1 */
659-
num = PyLong_FromLongLong(PY_LLONG_MAX);
658+
/* Same again, with num = LLONG_MAX + 1 */
659+
num = PyLong_FromLongLong(LLONG_MAX);
660660
if (num == NULL)
661661
return NULL;
662662
one = PyLong_FromLong(1L);
@@ -683,7 +683,7 @@ test_long_long_and_overflow(PyObject *self, PyObject *Py_UNUSED(ignored))
683683
"overflow was not set to 1");
684684

685685
/* Test that overflow is set properly for a large negative value. */
686-
/* num is a number smaller than PY_LLONG_MIN on a typical platform */
686+
/* num is a number smaller than LLONG_MIN on a typical platform */
687687
num = PyLong_FromString("-FFFFFFFFFFFFFFFFFFFFFFFF", NULL, 16);
688688
if (num == NULL)
689689
return NULL;
@@ -699,8 +699,8 @@ test_long_long_and_overflow(PyObject *self, PyObject *Py_UNUSED(ignored))
699699
return raiseTestError("test_long_long_and_overflow",
700700
"overflow was not set to -1");
701701

702-
/* Same again, with num = PY_LLONG_MIN - 1 */
703-
num = PyLong_FromLongLong(PY_LLONG_MIN);
702+
/* Same again, with num = LLONG_MIN - 1 */
703+
num = PyLong_FromLongLong(LLONG_MIN);
704704
if (num == NULL)
705705
return NULL;
706706
one = PyLong_FromLong(1L);
@@ -757,32 +757,32 @@ test_long_long_and_overflow(PyObject *self, PyObject *Py_UNUSED(ignored))
757757
return raiseTestError("test_long_long_and_overflow",
758758
"overflow was set incorrectly");
759759

760-
num = PyLong_FromLongLong(PY_LLONG_MAX);
760+
num = PyLong_FromLongLong(LLONG_MAX);
761761
if (num == NULL)
762762
return NULL;
763763
overflow = 1234;
764764
value = PyLong_AsLongLongAndOverflow(num, &overflow);
765765
Py_DECREF(num);
766766
if (value == -1 && PyErr_Occurred())
767767
return NULL;
768-
if (value != PY_LLONG_MAX)
768+
if (value != LLONG_MAX)
769769
return raiseTestError("test_long_long_and_overflow",
770-
"expected return value PY_LLONG_MAX");
770+
"expected return value LLONG_MAX");
771771
if (overflow != 0)
772772
return raiseTestError("test_long_long_and_overflow",
773773
"overflow was not cleared");
774774

775-
num = PyLong_FromLongLong(PY_LLONG_MIN);
775+
num = PyLong_FromLongLong(LLONG_MIN);
776776
if (num == NULL)
777777
return NULL;
778778
overflow = 0;
779779
value = PyLong_AsLongLongAndOverflow(num, &overflow);
780780
Py_DECREF(num);
781781
if (value == -1 && PyErr_Occurred())
782782
return NULL;
783-
if (value != PY_LLONG_MIN)
783+
if (value != LLONG_MIN)
784784
return raiseTestError("test_long_long_and_overflow",
785-
"expected return value PY_LLONG_MIN");
785+
"expected return value LLONG_MIN");
786786
if (overflow != 0)
787787
return raiseTestError("test_long_long_and_overflow",
788788
"overflow was not cleared");
@@ -6710,9 +6710,9 @@ PyInit__testcapi(void)
67106710
PyModule_AddObject(m, "FLT_MIN", PyFloat_FromDouble(FLT_MIN));
67116711
PyModule_AddObject(m, "DBL_MAX", PyFloat_FromDouble(DBL_MAX));
67126712
PyModule_AddObject(m, "DBL_MIN", PyFloat_FromDouble(DBL_MIN));
6713-
PyModule_AddObject(m, "LLONG_MAX", PyLong_FromLongLong(PY_LLONG_MAX));
6714-
PyModule_AddObject(m, "LLONG_MIN", PyLong_FromLongLong(PY_LLONG_MIN));
6715-
PyModule_AddObject(m, "ULLONG_MAX", PyLong_FromUnsignedLongLong(PY_ULLONG_MAX));
6713+
PyModule_AddObject(m, "LLONG_MAX", PyLong_FromLongLong(LLONG_MAX));
6714+
PyModule_AddObject(m, "LLONG_MIN", PyLong_FromLongLong(LLONG_MIN));
6715+
PyModule_AddObject(m, "ULLONG_MAX", PyLong_FromUnsignedLongLong(ULLONG_MAX));
67166716
PyModule_AddObject(m, "PY_SSIZE_T_MAX", PyLong_FromSsize_t(PY_SSIZE_T_MAX));
67176717
PyModule_AddObject(m, "PY_SSIZE_T_MIN", PyLong_FromSsize_t(PY_SSIZE_T_MIN));
67186718
PyModule_AddObject(m, "SIZEOF_PYGC_HEAD", PyLong_FromSsize_t(sizeof(PyGC_Head)));

Objects/longobject.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ PyLong_AsVoidPtr(PyObject *vv)
11581158
* rewritten to use the newer PyLong_{As,From}ByteArray API.
11591159
*/
11601160

1161-
#define PY_ABS_LLONG_MIN (0-(unsigned long long)PY_LLONG_MIN)
1161+
#define PY_ABS_LLONG_MIN (0-(unsigned long long)LLONG_MIN)
11621162

11631163
/* Create a new int object from a C long long int. */
11641164

@@ -1462,11 +1462,11 @@ PyLong_AsLongLongAndOverflow(PyObject *vv, int *overflow)
14621462
/* Haven't lost any bits, but casting to long requires extra
14631463
* care (see comment above).
14641464
*/
1465-
if (x <= (unsigned long long)PY_LLONG_MAX) {
1465+
if (x <= (unsigned long long)LLONG_MAX) {
14661466
res = (long long)x * sign;
14671467
}
14681468
else if (sign < 0 && x == PY_ABS_LLONG_MIN) {
1469-
res = PY_LLONG_MIN;
1469+
res = LLONG_MIN;
14701470
}
14711471
else {
14721472
*overflow = sign;
@@ -5020,7 +5020,7 @@ _PyLong_GCD(PyObject *aarg, PyObject *barg)
50205020
/* a fits into a long, so b must too */
50215021
x = PyLong_AsLong((PyObject *)a);
50225022
y = PyLong_AsLong((PyObject *)b);
5023-
#elif PY_LLONG_MAX >> PyLong_SHIFT >> PyLong_SHIFT
5023+
#elif LLONG_MAX >> PyLong_SHIFT >> PyLong_SHIFT
50245024
x = PyLong_AsLongLong((PyObject *)a);
50255025
y = PyLong_AsLongLong((PyObject *)b);
50265026
#else
@@ -5039,7 +5039,7 @@ _PyLong_GCD(PyObject *aarg, PyObject *barg)
50395039
}
50405040
#if LONG_MAX >> PyLong_SHIFT >> PyLong_SHIFT
50415041
return PyLong_FromLong(x);
5042-
#elif PY_LLONG_MAX >> PyLong_SHIFT >> PyLong_SHIFT
5042+
#elif LLONG_MAX >> PyLong_SHIFT >> PyLong_SHIFT
50435043
return PyLong_FromLongLong(x);
50445044
#else
50455045
# error "_PyLong_GCD"

0 commit comments

Comments
 (0)