summaryrefslogtreecommitdiff
path: root/py/modsys.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/modsys.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/modsys.c')
-rw-r--r--py/modsys.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/py/modsys.c b/py/modsys.c
index 1e7f7eff7..d21584676 100644
--- a/py/modsys.c
+++ b/py/modsys.c
@@ -24,6 +24,8 @@
* THE SOFTWARE.
*/
+#include <stdint.h>
+#include <limits.h>
#include "mpconfig.h"
#include "misc.h"
#include "qstr.h"
@@ -33,6 +35,8 @@
#include "objlist.h"
#include "objtuple.h"
#include "objstr.h"
+#include "mpz.h"
+#include "objint.h"
#if MICROPY_PY_SYS
@@ -44,6 +48,8 @@ extern struct _dummy_t mp_sys_stdin_obj;
extern struct _dummy_t mp_sys_stdout_obj;
extern struct _dummy_t mp_sys_stderr_obj;
+extern mp_obj_int_t mp_maxsize_obj;
+
mp_obj_list_t mp_sys_path_obj;
mp_obj_list_t mp_sys_argv_obj;
#define I(n) MP_OBJ_NEW_SMALL_INT(n)
@@ -70,6 +76,19 @@ STATIC const mp_map_elem_t mp_module_sys_globals_table[] = {
#else
{ MP_OBJ_NEW_QSTR(MP_QSTR_byteorder), MP_OBJ_NEW_QSTR(MP_QSTR_big) },
#endif
+#if MICROPY_PY_SYS_MAXSIZE
+ #if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_NONE
+ // INT_MAX is not representable as small int, as we know that small int
+ // takes one bit for tag. So, we have little choice but to provide this
+ // value. Apps also should be careful to not try to compare sys.maxsize
+ // with some number (which may not fit in available int size), but instead
+ // count number of significant bits in sys.maxsize.
+ { MP_OBJ_NEW_QSTR(MP_QSTR_maxsize), MP_OBJ_NEW_SMALL_INT(INT_MAX >> 1) },
+ #else
+ { MP_OBJ_NEW_QSTR(MP_QSTR_maxsize), (mp_obj_t)&mp_maxsize_obj },
+ #endif
+#endif
+
#if MICROPY_PY_SYS_EXIT
{ MP_OBJ_NEW_QSTR(MP_QSTR_exit), (mp_obj_t)&mp_sys_exit_obj },