Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6646cd4

Browse files
committed
Issue #10325: Fix two issues in the fallback definitions of PY_LLONG_MAX and
PY_ULLONG_MAX in pyport.h. Thanks Hallvard B Furuseth for the patch.
1 parent ec0d355 commit 6646cd4

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

Include/pyport.h

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,20 @@ Used in: PY_LONG_LONG
6262
#define PY_LLONG_MAX LLONG_MAX
6363
#define PY_ULLONG_MAX ULLONG_MAX
6464
#elif defined(__LONG_LONG_MAX__)
65-
/* Otherwise, if GCC has a builtin define, use that. */
65+
/* Otherwise, if GCC has a builtin define, use that. (Definition of
66+
* PY_LLONG_MIN assumes two's complement with no trap representation.) */
6667
#define PY_LLONG_MAX __LONG_LONG_MAX__
67-
#define PY_LLONG_MIN (-PY_LLONG_MAX-1)
68-
#define PY_ULLONG_MAX (__LONG_LONG_MAX__*2ULL + 1ULL)
69-
#else
70-
/* Otherwise, rely on two's complement. */
71-
#define PY_ULLONG_MAX (~0ULL)
72-
#define PY_LLONG_MAX ((long long)(PY_ULLONG_MAX>>1))
73-
#define PY_LLONG_MIN (-PY_LLONG_MAX-1)
68+
#define PY_LLONG_MIN (-PY_LLONG_MAX - 1)
69+
#define PY_ULLONG_MAX (PY_LLONG_MAX * Py_ULL(2) + 1)
70+
#elif defined(SIZEOF_LONG_LONG)
71+
/* Otherwise compute from SIZEOF_LONG_LONG, assuming two's complement, no
72+
padding bits, and no trap representation. Note: PY_ULLONG_MAX was
73+
previously #defined as (~0ULL) here; but that'll give the wrong value in a
74+
preprocessor expression on systems where long long != intmax_t. */
75+
#define PY_LLONG_MAX \
76+
(1 + 2 * ((Py_LL(1) << (CHAR_BIT * SIZEOF_LONG_LONG - 2)) - 1))
77+
#define PY_LLONG_MIN (-PY_LLONG_MAX - 1)
78+
#define PY_ULLONG_MAX (PY_LLONG_MAX * Py_ULL(2) + 1)
7479
#endif /* LLONG_MAX */
7580
#endif
7681
#endif /* HAVE_LONG_LONG */

Misc/NEWS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ Tests
4545
- Issue #8886: Use context managers throughout test_zipfile. Patch by
4646
Eric Carstensen.
4747

48+
Build
49+
-----
50+
51+
- Issue #10325: Fix two issues in the fallback definitions for PY_ULLONG_MAX and
52+
PY_LLONG_MAX that made them unsuitable for use in preprocessor conditionals.
53+
4854

4955
What's New in Python 3.2 Alpha 4?
5056
=================================

0 commit comments

Comments
 (0)