@@ -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 */
0 commit comments