|
54 | 54 | #include "genhdr/mpversion.h"
|
55 | 55 | #include "input.h"
|
56 | 56 |
|
| 57 | +#if defined(MICROPY_UNIX_COVERAGE) // CIRCUITPY-CHANGE |
| 58 | +#include "py/objstr.h" |
| 59 | +typedef int os_getenv_err_t; |
| 60 | +mp_obj_t common_hal_os_getenv(const char *key, mp_obj_t default_); |
| 61 | +os_getenv_err_t common_hal_os_getenv_str(const char *key, char *value, size_t value_len); |
| 62 | +os_getenv_err_t common_hal_os_getenv_int(const char *key, mp_int_t *value); |
| 63 | + |
| 64 | +STATIC mp_obj_t mod_os_getenv_int(mp_obj_t var_in) { |
| 65 | + mp_int_t value; |
| 66 | + os_getenv_err_t result = common_hal_os_getenv_int(mp_obj_str_get_str(var_in), &value); |
| 67 | + if (result == 0) { |
| 68 | + return mp_obj_new_int(value); |
| 69 | + } |
| 70 | + return mp_const_none; |
| 71 | +} |
| 72 | +MP_DEFINE_CONST_FUN_OBJ_1(mod_os_getenv_int_obj, mod_os_getenv_int); |
| 73 | + |
| 74 | +STATIC mp_obj_t mod_os_getenv_str(mp_obj_t var_in) { |
| 75 | + char buf[4096]; |
| 76 | + os_getenv_err_t result = common_hal_os_getenv_str(mp_obj_str_get_str(var_in), buf, sizeof(buf)); |
| 77 | + if (result == 0) { |
| 78 | + return mp_obj_new_str_copy(&mp_type_str, (byte *)buf, strlen(buf)); |
| 79 | + } |
| 80 | + return mp_const_none; |
| 81 | +} |
| 82 | +MP_DEFINE_CONST_FUN_OBJ_1(mod_os_getenv_str_obj, mod_os_getenv_str); |
| 83 | +#endif |
| 84 | + |
57 | 85 | // Command line options, with their defaults
|
58 | 86 | STATIC bool compile_only = false;
|
59 | 87 | STATIC uint emit_opt = MP_EMIT_OPT_NONE;
|
@@ -596,6 +624,8 @@ MP_NOINLINE int main_(int argc, char **argv) {
|
596 | 624 | // CIRCUITPY-CHANGE: test native base classes work as needed by CircuitPython libraries.
|
597 | 625 | extern const mp_obj_type_t native_base_class_type;
|
598 | 626 | mp_store_global(MP_QSTR_NativeBaseClass, MP_OBJ_FROM_PTR(&native_base_class_type));
|
| 627 | + mp_store_global(MP_QSTR_getenv_int, MP_OBJ_FROM_PTR(&mod_os_getenv_int_obj)); |
| 628 | + mp_store_global(MP_QSTR_getenv_str, MP_OBJ_FROM_PTR(&mod_os_getenv_str_obj)); |
599 | 629 | }
|
600 | 630 | #endif
|
601 | 631 |
|
|
0 commit comments