summaryrefslogtreecommitdiff
path: root/py/objint_mpz.c
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-07-03 16:50:11 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-07-03 18:09:36 +0300
commit4e0eeebdc2b452277c24f554c444f0cc0de9e4ea (patch)
tree6cda2dd6ff6fe129338c8980b045dbde1ba16645 /py/objint_mpz.c
parent381618269a9eb3e49d0e42d389d2dec312907577 (diff)
py: Implement sys.maxsize, standard way to check platform "bitness".
Implementing it as a static constant is a bit peculiar and require cooperation from long int implementation.
Diffstat (limited to 'py/objint_mpz.c')
-rw-r--r--py/objint_mpz.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/py/objint_mpz.c b/py/objint_mpz.c
index da02b1ea9..6e1c3c5a8 100644
--- a/py/objint_mpz.c
+++ b/py/objint_mpz.c
@@ -43,6 +43,26 @@
#if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_MPZ
+#if MICROPY_PY_SYS_MAXSIZE
+// Export value for sys.maxsize
+#define DIG_MASK ((1 << MPZ_DIG_SIZE) - 1)
+STATIC const mpz_dig_t maxsize_dig[MPZ_NUM_DIG_FOR_INT] = {
+ (INT_MAX >> MPZ_DIG_SIZE * 0) & DIG_MASK,
+ (INT_MAX >> MPZ_DIG_SIZE * 1) & DIG_MASK,
+ (INT_MAX >> MPZ_DIG_SIZE * 2) & DIG_MASK,
+ #if (INT_MAX >> MPZ_DIG_SIZE * 2) > DIG_MASK
+ (INT_MAX >> MPZ_DIG_SIZE * 3) & DIG_MASK,
+ (INT_MAX >> MPZ_DIG_SIZE * 4) & DIG_MASK,
+// (INT_MAX >> MPZ_DIG_SIZE * 5) & DIG_MASK,
+ #endif
+};
+const mp_obj_int_t mp_maxsize_obj = {
+ {&mp_type_int},
+ {.fixed_dig = 1, .len = MPZ_NUM_DIG_FOR_INT, .alloc = MPZ_NUM_DIG_FOR_INT, .dig = (mpz_dig_t*)maxsize_dig}
+};
+#undef DIG_MASK
+#endif
+
STATIC mp_obj_int_t *mp_obj_int_new_mpz(void) {
mp_obj_int_t *o = m_new_obj(mp_obj_int_t);
o->base.type = &mp_type_int;