Skip to content

Commit 9a97397

Browse files
committed
py/objstr: Use MICROPY_FULL_CHECKS for range checking when constructing bytes.
Split this setting from MICROPY_CPYTHON_COMPAT. The idea is to be able to keep MICROPY_CPYTHON_COMPAT disabled, but still pass more of regression testsuite. In particular, this fixes last failing test in basics/ for Zephyr port.
1 parent 5b2db4b commit 9a97397

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

py/mpconfig.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,15 @@ typedef double mp_float_t;
556556
#define MICROPY_CPYTHON_COMPAT (1)
557557
#endif
558558

559+
// Perform full checks as done by CPython. Disabling this
560+
// may produce incorrect results, if incorrect data is fed,
561+
// but should not lead to MicroPython crashes or similar
562+
// grave issues (in other words, only user app should be,
563+
// affected, not system).
564+
#ifndef MICROPY_FULL_CHECKS
565+
#define MICROPY_FULL_CHECKS (1)
566+
#endif
567+
559568
// Whether POSIX-semantics non-blocking streams are supported
560569
#ifndef MICROPY_STREAMS_NON_BLOCK
561570
#define MICROPY_STREAMS_NON_BLOCK (0)

py/objstr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ STATIC mp_obj_t bytes_make_new(const mp_obj_type_t *type_in, size_t n_args, size
236236
mp_obj_t item;
237237
while ((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) {
238238
mp_int_t val = mp_obj_get_int(item);
239-
#if MICROPY_CPYTHON_COMPAT
239+
#if MICROPY_FULL_CHECKS
240240
if (val < 0 || val > 255) {
241241
mp_raise_ValueError("bytes value out of range");
242242
}

0 commit comments

Comments
 (0)