From b9b9354e6c0cefff071be0bc4e195eb80f1f1d96 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 7 Jun 2014 23:40:04 +0300 Subject: [PATCH] modsys: Add optional support for sys.platform. Ports which wants to have it, should define MICROPY_PY_SYS_PLATFORM to a string value they need. --- py/modsys.c | 6 ++++++ py/qstrdefs.h | 3 +++ unix/mpconfigport.h | 1 + 3 files changed, 10 insertions(+) diff --git a/py/modsys.c b/py/modsys.c index 738758bdf4..a99db1b7f8 100644 --- a/py/modsys.c +++ b/py/modsys.c @@ -51,6 +51,9 @@ mp_obj_list_t mp_sys_argv_obj; STATIC const mp_obj_tuple_t mp_sys_version_info_obj = {{&mp_type_tuple}, 3, {I(3), I(4), I(0)}}; #undef I STATIC const MP_DEFINE_STR_OBJ(version_obj, "3.4.0"); +#ifdef MICROPY_PY_SYS_PLATFORM +STATIC const MP_DEFINE_STR_OBJ(platform_obj, MICROPY_PY_SYS_PLATFORM); +#endif STATIC const mp_map_elem_t mp_module_sys_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_sys) }, @@ -59,6 +62,9 @@ STATIC const mp_map_elem_t mp_module_sys_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_argv), (mp_obj_t)&mp_sys_argv_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_version), (mp_obj_t)&version_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_version_info), (mp_obj_t)&mp_sys_version_info_obj }, +#ifdef MICROPY_PY_SYS_PLATFORM + { MP_OBJ_NEW_QSTR(MP_QSTR_platform), (mp_obj_t)&platform_obj }, +#endif #if MP_ENDIANNESS_LITTLE { MP_OBJ_NEW_QSTR(MP_QSTR_byteorder), MP_OBJ_NEW_QSTR(MP_QSTR_little) }, #else diff --git a/py/qstrdefs.h b/py/qstrdefs.h index 69182f2809..ae358b99af 100644 --- a/py/qstrdefs.h +++ b/py/qstrdefs.h @@ -343,6 +343,9 @@ Q(byteorder) Q(big) Q(exit) Q(little) +#ifdef MICROPY_PY_SYS_PLATFORM +Q(platform) +#endif Q(stdin) Q(stdout) Q(stderr) diff --git a/unix/mpconfigport.h b/unix/mpconfigport.h index ace7a419b4..bf2cf73efd 100644 --- a/unix/mpconfigport.h +++ b/unix/mpconfigport.h @@ -43,6 +43,7 @@ #define MICROPY_OPT_COMPUTED_GOTO (1) #define MICROPY_PY_BUILTINS_FROZENSET (1) #define MICROPY_PY_SYS_EXIT (1) +#define MICROPY_PY_SYS_PLATFORM "linux" #define MICROPY_PY_SYS_STDFILES (1) #define MICROPY_PY_CMATH (1) #define MICROPY_PY_IO_FILEIO (1)