Skip to content

Commit f06d083

Browse files
tomlogicpfalcon
authored andcommitted
py/modsys: update conditionals for code referencing sys.stdout
Working on a build with PY_IO enabled (for PY_UJSON support) but PY_SYS_STDFILES disabled (no filesystem). There are multiple references to mp_sys_stdout_obj that should only be enabled if both PY_IO and PY_SYS_STDFILES are enabled.
1 parent 5549103 commit f06d083

3 files changed

Lines changed: 8 additions & 8 deletions

File tree

py/modbuiltins.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ STATIC mp_obj_t mp_builtin_print(size_t n_args, const mp_obj_t *args, mp_map_t *
406406
if (end_elem != NULL && end_elem->value != mp_const_none) {
407407
end_data = mp_obj_str_get_data(end_elem->value, &end_len);
408408
}
409-
#if MICROPY_PY_IO
409+
#if MICROPY_PY_IO && MICROPY_PY_SYS_STDFILES
410410
void *stream_obj = &mp_sys_stdout_obj;
411411
mp_map_elem_t *file_elem = mp_map_lookup(kwargs, MP_OBJ_NEW_QSTR(MP_QSTR_file), MP_MAP_LOOKUP);
412412
if (file_elem != NULL && file_elem->value != mp_const_none) {
@@ -417,19 +417,19 @@ STATIC mp_obj_t mp_builtin_print(size_t n_args, const mp_obj_t *args, mp_map_t *
417417
#endif
418418
for (mp_uint_t i = 0; i < n_args; i++) {
419419
if (i > 0) {
420-
#if MICROPY_PY_IO
420+
#if MICROPY_PY_IO && MICROPY_PY_SYS_STDFILES
421421
mp_stream_write_adaptor(stream_obj, sep_data, sep_len);
422422
#else
423423
mp_print_strn(&mp_plat_print, sep_data, sep_len, 0, 0, 0);
424424
#endif
425425
}
426-
#if MICROPY_PY_IO
426+
#if MICROPY_PY_IO && MICROPY_PY_SYS_STDFILES
427427
mp_obj_print_helper(&print, args[i], PRINT_STR);
428428
#else
429429
mp_obj_print_helper(&mp_plat_print, args[i], PRINT_STR);
430430
#endif
431431
}
432-
#if MICROPY_PY_IO
432+
#if MICROPY_PY_IO && MICROPY_PY_SYS_STDFILES
433433
mp_stream_write_adaptor(stream_obj, end_data, end_len);
434434
#else
435435
mp_print_strn(&mp_plat_print, end_data, end_len, 0, 0, 0);

py/modsys.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ extern struct _mp_dummy_t mp_sys_stdin_obj;
4545
extern struct _mp_dummy_t mp_sys_stdout_obj;
4646
extern struct _mp_dummy_t mp_sys_stderr_obj;
4747

48-
#if MICROPY_PY_IO
48+
#if MICROPY_PY_IO && MICROPY_PY_SYS_STDFILES
4949
const mp_print_t mp_sys_stdout_print = {&mp_sys_stdout_obj, mp_stream_write_adaptor};
5050
#endif
5151

@@ -106,7 +106,7 @@ STATIC mp_obj_t mp_sys_exit(size_t n_args, const mp_obj_t *args) {
106106
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_sys_exit_obj, 0, 1, mp_sys_exit);
107107

108108
STATIC mp_obj_t mp_sys_print_exception(size_t n_args, const mp_obj_t *args) {
109-
#if MICROPY_PY_IO
109+
#if MICROPY_PY_IO && MICROPY_PY_SYS_STDFILES
110110
void *stream_obj = &mp_sys_stdout_obj;
111111
if (n_args > 1) {
112112
stream_obj = MP_OBJ_TO_PTR(args[1]); // XXX may fail

py/mpprint.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#define PF_FLAG_ADD_PERCENT (0x100)
4040
#define PF_FLAG_SHOW_OCTAL_LETTER (0x200)
4141

42-
#if MICROPY_PY_IO
42+
#if MICROPY_PY_IO && MICROPY_PY_SYS_STDFILES
4343
# define MP_PYTHON_PRINTER &mp_sys_stdout_print
4444
#else
4545
# define MP_PYTHON_PRINTER &mp_plat_print
@@ -55,7 +55,7 @@ typedef struct _mp_print_t {
5555
// All (non-debug) prints go through one of the two interfaces below.
5656
// 1) Wrapper for platform print function, which wraps MP_PLAT_PRINT_STRN.
5757
extern const mp_print_t mp_plat_print;
58-
#if MICROPY_PY_IO
58+
#if MICROPY_PY_IO && MICROPY_PY_SYS_STDFILES
5959
// 2) Wrapper for printing to sys.stdout.
6060
extern const mp_print_t mp_sys_stdout_print;
6161
#endif

0 commit comments

Comments
 (0)