Skip to content

Commit 722e562

Browse files
committed
py: Correctly set sys.maxsize value for 64-bit.
Type representing signed size doesn't have to be int, so use special value which defaults to SSIZE_MAX, but as it's not defined by C standard (but rather by POSIX), allow ports to set it.
1 parent 17598d4 commit 722e562

3 files changed

Lines changed: 13 additions & 9 deletions

File tree

py/mpconfig.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,10 @@ typedef double mp_float_t;
448448
#define MP_PLAT_FREE_EXEC(ptr, size) m_del(byte, ptr, size)
449449
#endif
450450

451+
#ifndef MP_SSIZE_MAX
452+
#define MP_SSIZE_MAX SSIZE_MAX
453+
#endif
454+
451455
// printf format spec to use for mp_int_t and friends
452456
#ifndef INT_FMT
453457
#ifdef __LP64__

py/objint_longlong.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
#if MICROPY_PY_SYS_MAXSIZE
5454
// Export value for sys.maxsize
55-
const mp_obj_int_t mp_maxsize_obj = {{&mp_type_int}, INT_MAX};
55+
const mp_obj_int_t mp_maxsize_obj = {{&mp_type_int}, MP_SSIZE_MAX};
5656
#endif
5757

5858
mp_int_t mp_obj_int_hash(mp_obj_t self_in) {

py/objint_mpz.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@
4747
// Export value for sys.maxsize
4848
#define DIG_MASK ((1L << MPZ_DIG_SIZE) - 1)
4949
STATIC const mpz_dig_t maxsize_dig[MPZ_NUM_DIG_FOR_INT] = {
50-
(INT_MAX >> MPZ_DIG_SIZE * 0) & DIG_MASK,
51-
#if (INT_MAX >> MPZ_DIG_SIZE * 0) > DIG_MASK
52-
(INT_MAX >> MPZ_DIG_SIZE * 1) & DIG_MASK,
53-
#if (INT_MAX >> MPZ_DIG_SIZE * 1) > DIG_MASK
54-
(INT_MAX >> MPZ_DIG_SIZE * 2) & DIG_MASK,
55-
(INT_MAX >> MPZ_DIG_SIZE * 3) & DIG_MASK,
56-
(INT_MAX >> MPZ_DIG_SIZE * 4) & DIG_MASK,
57-
// (INT_MAX >> MPZ_DIG_SIZE * 5) & DIG_MASK,
50+
(MP_SSIZE_MAX >> MPZ_DIG_SIZE * 0) & DIG_MASK,
51+
#if (MP_SSIZE_MAX >> MPZ_DIG_SIZE * 0) > DIG_MASK
52+
(MP_SSIZE_MAX >> MPZ_DIG_SIZE * 1) & DIG_MASK,
53+
#if (MP_SSIZE_MAX >> MPZ_DIG_SIZE * 1) > DIG_MASK
54+
(MP_SSIZE_MAX >> MPZ_DIG_SIZE * 2) & DIG_MASK,
55+
(MP_SSIZE_MAX >> MPZ_DIG_SIZE * 3) & DIG_MASK,
56+
(MP_SSIZE_MAX >> MPZ_DIG_SIZE * 4) & DIG_MASK,
57+
// (MP_SSIZE_MAX >> MPZ_DIG_SIZE * 5) & DIG_MASK,
5858
#endif
5959
#endif
6060
};

0 commit comments

Comments
 (0)