From 1b586f3a734c27c78080fb2173bbde17168cb9e4 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 11 Oct 2015 12:09:43 +0300 Subject: [PATCH] py: Rename MP_BOOL() to mp_obj_new_bool() for consistency in naming. --- cc3200/mods/modnetwork.c | 2 +- py/modbuiltins.c | 2 +- py/modgc.c | 2 +- py/modmath.c | 2 +- py/nativeglue.c | 2 +- py/obj.h | 6 +----- py/objarray.c | 4 ++-- py/objcomplex.c | 4 ++-- py/objdict.c | 4 ++-- py/objfloat.c | 12 ++++++------ py/objint_longlong.c | 12 ++++++------ py/objint_mpz.c | 12 ++++++------ py/objlist.c | 4 ++-- py/objrange.c | 2 +- py/objset.c | 6 +++--- py/objstr.c | 8 ++++---- py/objstrunicode.c | 2 +- py/objtuple.c | 4 ++-- py/runtime.c | 12 ++++++------ stmhal/irq.c | 2 +- stmhal/modnwcc3k.c | 2 +- stmhal/pin.c | 2 +- stmhal/sdcard.c | 4 ++-- stmhal/usb.c | 2 +- teensy/modpyb.c | 2 +- unix/modjni.c | 2 +- 26 files changed, 57 insertions(+), 61 deletions(-) diff --git a/cc3200/mods/modnetwork.c b/cc3200/mods/modnetwork.c index 8f9ee2c6c0..3031c5e790 100644 --- a/cc3200/mods/modnetwork.c +++ b/cc3200/mods/modnetwork.c @@ -54,7 +54,7 @@ STATIC mp_obj_t network_server_running(mp_uint_t n_args, const mp_obj_t *args) { return mp_const_none; } else { // get - return MP_BOOL(servers_are_enabled()); + return mp_obj_new_bool(servers_are_enabled()); } } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_server_running_obj, 0, 1, network_server_running); diff --git a/py/modbuiltins.c b/py/modbuiltins.c index 0767ab23b4..1f33ab75ec 100644 --- a/py/modbuiltins.c +++ b/py/modbuiltins.c @@ -534,7 +534,7 @@ STATIC mp_obj_t mp_builtin_hasattr(mp_obj_t object_in, mp_obj_t attr_in) { // in nlr_push and handle exception. mp_load_method_maybe(object_in, MP_OBJ_QSTR_VALUE(attr_in), dest); - return MP_BOOL(dest[0] != MP_OBJ_NULL); + return mp_obj_new_bool(dest[0] != MP_OBJ_NULL); } MP_DEFINE_CONST_FUN_OBJ_2(mp_builtin_hasattr_obj, mp_builtin_hasattr); diff --git a/py/modgc.c b/py/modgc.c index 47980decaf..007ea40a10 100644 --- a/py/modgc.c +++ b/py/modgc.c @@ -63,7 +63,7 @@ STATIC mp_obj_t gc_enable(void) { MP_DEFINE_CONST_FUN_OBJ_0(gc_enable_obj, gc_enable); STATIC mp_obj_t gc_isenabled(void) { - return MP_BOOL(MP_STATE_MEM(gc_auto_collect_enabled)); + return mp_obj_new_bool(MP_STATE_MEM(gc_auto_collect_enabled)); } MP_DEFINE_CONST_FUN_OBJ_0(gc_isenabled_obj, gc_isenabled); diff --git a/py/modmath.c b/py/modmath.c index 296d16be6f..e1f6b9ea08 100644 --- a/py/modmath.c +++ b/py/modmath.c @@ -45,7 +45,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mp_math_## py_name ## _obj, mp_math_ ## py_name); #define MATH_FUN_1_TO_BOOL(py_name, c_name) \ - STATIC mp_obj_t mp_math_ ## py_name(mp_obj_t x_obj) { return MP_BOOL(c_name(mp_obj_get_float(x_obj))); } \ + STATIC mp_obj_t mp_math_ ## py_name(mp_obj_t x_obj) { return mp_obj_new_bool(c_name(mp_obj_get_float(x_obj))); } \ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_## py_name ## _obj, mp_math_ ## py_name); #define MATH_FUN_1_TO_INT(py_name, c_name) \ diff --git a/py/nativeglue.c b/py/nativeglue.c index 87213710cf..9c939c7ea8 100644 --- a/py/nativeglue.c +++ b/py/nativeglue.c @@ -67,7 +67,7 @@ mp_obj_t mp_convert_native_to_obj(mp_uint_t val, mp_uint_t type) { DEBUG_printf("mp_convert_native_to_obj(" UINT_FMT ", " UINT_FMT ")\n", val, type); switch (type & 3) { case MP_NATIVE_TYPE_OBJ: return (mp_obj_t)val; - case MP_NATIVE_TYPE_BOOL: return MP_BOOL(val); + case MP_NATIVE_TYPE_BOOL: return mp_obj_new_bool(val); case MP_NATIVE_TYPE_INT: return mp_obj_new_int(val); case MP_NATIVE_TYPE_UINT: return mp_obj_new_int_from_uint(val); default: assert(0); return mp_const_none; diff --git a/py/obj.h b/py/obj.h index 08fc334c97..745186802c 100644 --- a/py/obj.h +++ b/py/obj.h @@ -459,7 +459,7 @@ extern const struct _mp_obj_exception_t mp_const_GeneratorExit_obj; mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict); mp_obj_t mp_obj_new_none(void); -mp_obj_t mp_obj_new_bool(bool value); +static inline mp_obj_t mp_obj_new_bool(mp_int_t x) { return x ? mp_const_true : mp_const_false; } mp_obj_t mp_obj_new_cell(mp_obj_t obj); mp_obj_t mp_obj_new_int(mp_int_t value); mp_obj_t mp_obj_new_int_from_uint(mp_uint_t value); @@ -528,10 +528,6 @@ mp_obj_t mp_obj_len_maybe(mp_obj_t o_in); // may return MP_OBJ_NULL mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t val); mp_obj_t mp_generic_unary_op(mp_uint_t op, mp_obj_t o_in); -// bool -// TODO make lower case when it has proven itself -static inline mp_obj_t MP_BOOL(mp_int_t x) { return x ? mp_const_true : mp_const_false; } - // cell mp_obj_t mp_obj_cell_get(mp_obj_t self_in); void mp_obj_cell_set(mp_obj_t self_in, mp_obj_t obj); diff --git a/py/objarray.c b/py/objarray.c index 3f432f00b9..67bb7931e9 100644 --- a/py/objarray.c +++ b/py/objarray.c @@ -246,7 +246,7 @@ STATIC mp_obj_t memoryview_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_ STATIC mp_obj_t array_unary_op(mp_uint_t op, mp_obj_t o_in) { mp_obj_array_t *o = o_in; switch (op) { - case MP_UNARY_OP_BOOL: return MP_BOOL(o->len != 0); + case MP_UNARY_OP_BOOL: return mp_obj_new_bool(o->len != 0); case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(o->len); default: return MP_OBJ_NULL; // op not supported } @@ -290,7 +290,7 @@ STATIC mp_obj_t array_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) if (!mp_get_buffer(rhs_in, &rhs_bufinfo, MP_BUFFER_READ)) { return mp_const_false; } - return MP_BOOL(mp_seq_cmp_bytes(op, lhs_bufinfo.buf, lhs_bufinfo.len, rhs_bufinfo.buf, rhs_bufinfo.len)); + return mp_obj_new_bool(mp_seq_cmp_bytes(op, lhs_bufinfo.buf, lhs_bufinfo.len, rhs_bufinfo.buf, rhs_bufinfo.len)); } default: diff --git a/py/objcomplex.c b/py/objcomplex.c index b790b05638..231ccf7689 100644 --- a/py/objcomplex.c +++ b/py/objcomplex.c @@ -116,7 +116,7 @@ STATIC mp_obj_t complex_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n STATIC mp_obj_t complex_unary_op(mp_uint_t op, mp_obj_t o_in) { mp_obj_complex_t *o = o_in; switch (op) { - case MP_UNARY_OP_BOOL: return MP_BOOL(o->real != 0 || o->imag != 0); + case MP_UNARY_OP_BOOL: return mp_obj_new_bool(o->real != 0 || o->imag != 0); case MP_UNARY_OP_POSITIVE: return o_in; case MP_UNARY_OP_NEGATIVE: return mp_obj_new_complex(-o->real, -o->imag); default: return MP_OBJ_NULL; // op not supported @@ -240,7 +240,7 @@ mp_obj_t mp_obj_complex_binary_op(mp_uint_t op, mp_float_t lhs_real, mp_float_t break; } - case MP_BINARY_OP_EQUAL: return MP_BOOL(lhs_real == rhs_real && lhs_imag == rhs_imag); + case MP_BINARY_OP_EQUAL: return mp_obj_new_bool(lhs_real == rhs_real && lhs_imag == rhs_imag); default: return MP_OBJ_NULL; // op not supported diff --git a/py/objdict.c b/py/objdict.c index c4725705d2..725c708c25 100644 --- a/py/objdict.c +++ b/py/objdict.c @@ -103,7 +103,7 @@ STATIC mp_obj_t dict_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw STATIC mp_obj_t dict_unary_op(mp_uint_t op, mp_obj_t self_in) { mp_obj_dict_t *self = MP_OBJ_CAST(self_in); switch (op) { - case MP_UNARY_OP_BOOL: return MP_BOOL(self->map.used != 0); + case MP_UNARY_OP_BOOL: return mp_obj_new_bool(self->map.used != 0); case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(self->map.used); default: return MP_OBJ_NULL; // op not supported } @@ -114,7 +114,7 @@ STATIC mp_obj_t dict_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { switch (op) { case MP_BINARY_OP_IN: { mp_map_elem_t *elem = mp_map_lookup(&o->map, rhs_in, MP_MAP_LOOKUP); - return MP_BOOL(elem != NULL); + return mp_obj_new_bool(elem != NULL); } case MP_BINARY_OP_EQUAL: { #if MICROPY_PY_COLLECTIONS_ORDEREDDICT diff --git a/py/objfloat.c b/py/objfloat.c index 0af41990ff..b8ab882b5c 100644 --- a/py/objfloat.c +++ b/py/objfloat.c @@ -85,7 +85,7 @@ STATIC mp_obj_t float_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_k STATIC mp_obj_t float_unary_op(mp_uint_t op, mp_obj_t o_in) { mp_obj_float_t *o = o_in; switch (op) { - case MP_UNARY_OP_BOOL: return MP_BOOL(o->value != 0); + case MP_UNARY_OP_BOOL: return mp_obj_new_bool(o->value != 0); case MP_UNARY_OP_POSITIVE: return o_in; case MP_UNARY_OP_NEGATIVE: return mp_obj_new_float(-o->value); default: return MP_OBJ_NULL; // op not supported @@ -216,11 +216,11 @@ mp_obj_t mp_obj_float_binary_op(mp_uint_t op, mp_float_t lhs_val, mp_obj_t rhs_i }; return mp_obj_new_tuple(2, tuple); } - case MP_BINARY_OP_LESS: return MP_BOOL(lhs_val < rhs_val); - case MP_BINARY_OP_MORE: return MP_BOOL(lhs_val > rhs_val); - case MP_BINARY_OP_EQUAL: return MP_BOOL(lhs_val == rhs_val); - case MP_BINARY_OP_LESS_EQUAL: return MP_BOOL(lhs_val <= rhs_val); - case MP_BINARY_OP_MORE_EQUAL: return MP_BOOL(lhs_val >= rhs_val); + case MP_BINARY_OP_LESS: return mp_obj_new_bool(lhs_val < rhs_val); + case MP_BINARY_OP_MORE: return mp_obj_new_bool(lhs_val > rhs_val); + case MP_BINARY_OP_EQUAL: return mp_obj_new_bool(lhs_val == rhs_val); + case MP_BINARY_OP_LESS_EQUAL: return mp_obj_new_bool(lhs_val <= rhs_val); + case MP_BINARY_OP_MORE_EQUAL: return mp_obj_new_bool(lhs_val >= rhs_val); default: return MP_OBJ_NULL; // op not supported diff --git a/py/objint_longlong.c b/py/objint_longlong.c index 075fabe49d..bceee095af 100644 --- a/py/objint_longlong.c +++ b/py/objint_longlong.c @@ -106,7 +106,7 @@ mp_obj_t mp_obj_int_abs(mp_obj_t self_in) { mp_obj_t mp_obj_int_unary_op(mp_uint_t op, mp_obj_t o_in) { mp_obj_int_t *o = o_in; switch (op) { - case MP_UNARY_OP_BOOL: return MP_BOOL(o->val != 0); + case MP_UNARY_OP_BOOL: return mp_obj_new_bool(o->val != 0); // truncate value to fit in mp_int_t, which gives the same hash as // small int if the value fits without truncation @@ -191,15 +191,15 @@ mp_obj_t mp_obj_int_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { } case MP_BINARY_OP_LESS: - return MP_BOOL(lhs_val < rhs_val); + return mp_obj_new_bool(lhs_val < rhs_val); case MP_BINARY_OP_MORE: - return MP_BOOL(lhs_val > rhs_val); + return mp_obj_new_bool(lhs_val > rhs_val); case MP_BINARY_OP_LESS_EQUAL: - return MP_BOOL(lhs_val <= rhs_val); + return mp_obj_new_bool(lhs_val <= rhs_val); case MP_BINARY_OP_MORE_EQUAL: - return MP_BOOL(lhs_val >= rhs_val); + return mp_obj_new_bool(lhs_val >= rhs_val); case MP_BINARY_OP_EQUAL: - return MP_BOOL(lhs_val == rhs_val); + return mp_obj_new_bool(lhs_val == rhs_val); default: return MP_OBJ_NULL; // op not supported diff --git a/py/objint_mpz.c b/py/objint_mpz.c index 73469f30d3..2255fd6525 100644 --- a/py/objint_mpz.c +++ b/py/objint_mpz.c @@ -145,7 +145,7 @@ mp_obj_t mp_obj_int_abs(mp_obj_t self_in) { mp_obj_t mp_obj_int_unary_op(mp_uint_t op, mp_obj_t o_in) { mp_obj_int_t *o = o_in; switch (op) { - case MP_UNARY_OP_BOOL: return MP_BOOL(!mpz_is_zero(&o->mpz)); + case MP_UNARY_OP_BOOL: return mp_obj_new_bool(!mpz_is_zero(&o->mpz)); case MP_UNARY_OP_HASH: return MP_OBJ_NEW_SMALL_INT(mpz_hash(&o->mpz)); case MP_UNARY_OP_POSITIVE: return o_in; case MP_UNARY_OP_NEGATIVE: { mp_obj_int_t *o2 = mp_obj_int_new_mpz(); mpz_neg_inpl(&o2->mpz, &o->mpz); return o2; } @@ -308,15 +308,15 @@ mp_obj_t mp_obj_int_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { int cmp = mpz_cmp(zlhs, zrhs); switch (op) { case MP_BINARY_OP_LESS: - return MP_BOOL(cmp < 0); + return mp_obj_new_bool(cmp < 0); case MP_BINARY_OP_MORE: - return MP_BOOL(cmp > 0); + return mp_obj_new_bool(cmp > 0); case MP_BINARY_OP_LESS_EQUAL: - return MP_BOOL(cmp <= 0); + return mp_obj_new_bool(cmp <= 0); case MP_BINARY_OP_MORE_EQUAL: - return MP_BOOL(cmp >= 0); + return mp_obj_new_bool(cmp >= 0); case MP_BINARY_OP_EQUAL: - return MP_BOOL(cmp == 0); + return mp_obj_new_bool(cmp == 0); default: return MP_OBJ_NULL; // op not supported diff --git a/py/objlist.c b/py/objlist.c index 21220441b5..5a90719a5e 100644 --- a/py/objlist.c +++ b/py/objlist.c @@ -102,7 +102,7 @@ STATIC bool list_cmp_helper(mp_uint_t op, mp_obj_t self_in, mp_obj_t another_in) STATIC mp_obj_t list_unary_op(mp_uint_t op, mp_obj_t self_in) { mp_obj_list_t *self = MP_OBJ_CAST(self_in); switch (op) { - case MP_UNARY_OP_BOOL: return MP_BOOL(self->len != 0); + case MP_UNARY_OP_BOOL: return mp_obj_new_bool(self->len != 0); case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(self->len); default: return MP_OBJ_NULL; // op not supported } @@ -141,7 +141,7 @@ STATIC mp_obj_t list_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) { case MP_BINARY_OP_LESS_EQUAL: case MP_BINARY_OP_MORE: case MP_BINARY_OP_MORE_EQUAL: - return MP_BOOL(list_cmp_helper(op, lhs, rhs)); + return mp_obj_new_bool(list_cmp_helper(op, lhs, rhs)); default: return MP_OBJ_NULL; // op not supported diff --git a/py/objrange.c b/py/objrange.c index 9d0ca37a74..f703f2fb0f 100644 --- a/py/objrange.c +++ b/py/objrange.c @@ -131,7 +131,7 @@ STATIC mp_obj_t range_unary_op(mp_uint_t op, mp_obj_t self_in) { mp_obj_range_t *self = self_in; mp_int_t len = range_len(self); switch (op) { - case MP_UNARY_OP_BOOL: return MP_BOOL(len > 0); + case MP_UNARY_OP_BOOL: return mp_obj_new_bool(len > 0); case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(len); default: return MP_OBJ_NULL; // op not supported } diff --git a/py/objset.c b/py/objset.c index 9b70ce6289..55aedde3eb 100644 --- a/py/objset.c +++ b/py/objset.c @@ -366,7 +366,7 @@ STATIC mp_obj_t set_issubset_internal(mp_obj_t self_in, mp_obj_t other_in, bool if (cleanup_other) { set_clear(other); } - return MP_BOOL(out); + return mp_obj_new_bool(out); } STATIC mp_obj_t set_issubset(mp_obj_t self_in, mp_obj_t other_in) { return set_issubset_internal(self_in, other_in, false); @@ -471,7 +471,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(set_union_obj, set_union); STATIC mp_obj_t set_unary_op(mp_uint_t op, mp_obj_t self_in) { mp_obj_set_t *self = self_in; switch (op) { - case MP_UNARY_OP_BOOL: return MP_BOOL(self->set.used != 0); + case MP_UNARY_OP_BOOL: return mp_obj_new_bool(self->set.used != 0); case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(self->set.used); #if MICROPY_PY_BUILTINS_FROZENSET case MP_UNARY_OP_HASH: @@ -525,7 +525,7 @@ STATIC mp_obj_t set_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) { case MP_BINARY_OP_IN: { mp_obj_set_t *o = lhs; mp_obj_t elem = mp_set_lookup(&o->set, rhs, MP_MAP_LOOKUP); - return MP_BOOL(elem != NULL); + return mp_obj_new_bool(elem != NULL); } default: return MP_OBJ_NULL; // op not supported diff --git a/py/objstr.c b/py/objstr.c index 9982322490..f94744af7f 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -360,7 +360,7 @@ mp_obj_t mp_obj_str_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { case MP_BINARY_OP_IN: /* NOTE `a in b` is `b.__contains__(a)` */ - return MP_BOOL(find_subbytes(lhs_data, lhs_len, rhs_data, rhs_len, 1) != NULL); + return mp_obj_new_bool(find_subbytes(lhs_data, lhs_len, rhs_data, rhs_len, 1) != NULL); //case MP_BINARY_OP_NOT_EQUAL: // This is never passed here case MP_BINARY_OP_EQUAL: // This will be passed only for bytes, str is dealt with in mp_obj_equal() @@ -368,7 +368,7 @@ mp_obj_t mp_obj_str_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { case MP_BINARY_OP_LESS_EQUAL: case MP_BINARY_OP_MORE: case MP_BINARY_OP_MORE_EQUAL: - return MP_BOOL(mp_seq_cmp_bytes(op, lhs_data, lhs_len, rhs_data, rhs_len)); + return mp_obj_new_bool(mp_seq_cmp_bytes(op, lhs_data, lhs_len, rhs_data, rhs_len)); } return MP_OBJ_NULL; // op not supported @@ -695,7 +695,7 @@ STATIC mp_obj_t str_startswith(mp_uint_t n_args, const mp_obj_t *args) { if (prefix_len + (start - str) > str_len) { return mp_const_false; } - return MP_BOOL(memcmp(start, prefix, prefix_len) == 0); + return mp_obj_new_bool(memcmp(start, prefix, prefix_len) == 0); } STATIC mp_obj_t str_endswith(mp_uint_t n_args, const mp_obj_t *args) { @@ -708,7 +708,7 @@ STATIC mp_obj_t str_endswith(mp_uint_t n_args, const mp_obj_t *args) { if (suffix_len > str_len) { return mp_const_false; } - return MP_BOOL(memcmp(str + (str_len - suffix_len), suffix, suffix_len) == 0); + return mp_obj_new_bool(memcmp(str + (str_len - suffix_len), suffix, suffix_len) == 0); } enum { LSTRIP, RSTRIP, STRIP }; diff --git a/py/objstrunicode.c b/py/objstrunicode.c index 1744925142..803b8014df 100644 --- a/py/objstrunicode.c +++ b/py/objstrunicode.c @@ -104,7 +104,7 @@ STATIC mp_obj_t uni_unary_op(mp_uint_t op, mp_obj_t self_in) { GET_STR_DATA_LEN(self_in, str_data, str_len); switch (op) { case MP_UNARY_OP_BOOL: - return MP_BOOL(str_len != 0); + return mp_obj_new_bool(str_len != 0); case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(unichar_charlen((const char *)str_data, str_len)); default: diff --git a/py/objtuple.c b/py/objtuple.c index 9aac1ce4d6..305f273c6f 100644 --- a/py/objtuple.c +++ b/py/objtuple.c @@ -125,7 +125,7 @@ STATIC bool tuple_cmp_helper(mp_uint_t op, mp_obj_t self_in, mp_obj_t another_in mp_obj_t mp_obj_tuple_unary_op(mp_uint_t op, mp_obj_t self_in) { mp_obj_tuple_t *self = self_in; switch (op) { - case MP_UNARY_OP_BOOL: return MP_BOOL(self->len != 0); + case MP_UNARY_OP_BOOL: return mp_obj_new_bool(self->len != 0); case MP_UNARY_OP_HASH: { // start hash with pointer to empty tuple, to make it fairly unique mp_int_t hash = (mp_int_t)mp_const_empty_tuple; @@ -168,7 +168,7 @@ mp_obj_t mp_obj_tuple_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) { case MP_BINARY_OP_LESS_EQUAL: case MP_BINARY_OP_MORE: case MP_BINARY_OP_MORE_EQUAL: - return MP_BOOL(tuple_cmp_helper(op, lhs, rhs)); + return mp_obj_new_bool(tuple_cmp_helper(op, lhs, rhs)); default: return MP_OBJ_NULL; // op not supported diff --git a/py/runtime.c b/py/runtime.c index 9c4fe7c723..4e055776b0 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -188,7 +188,7 @@ mp_obj_t mp_unary_op(mp_uint_t op, mp_obj_t arg) { mp_int_t val = MP_OBJ_SMALL_INT_VALUE(arg); switch (op) { case MP_UNARY_OP_BOOL: - return MP_BOOL(val != 0); + return mp_obj_new_bool(val != 0); case MP_UNARY_OP_HASH: return arg; case MP_UNARY_OP_POSITIVE: @@ -243,7 +243,7 @@ mp_obj_t mp_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) { // deal with is if (op == MP_BINARY_OP_IS) { - return MP_BOOL(lhs == rhs); + return mp_obj_new_bool(lhs == rhs); } // deal with == and != for all types @@ -443,10 +443,10 @@ mp_obj_t mp_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) { return tuple; } - case MP_BINARY_OP_LESS: return MP_BOOL(lhs_val < rhs_val); break; - case MP_BINARY_OP_MORE: return MP_BOOL(lhs_val > rhs_val); break; - case MP_BINARY_OP_LESS_EQUAL: return MP_BOOL(lhs_val <= rhs_val); break; - case MP_BINARY_OP_MORE_EQUAL: return MP_BOOL(lhs_val >= rhs_val); break; + case MP_BINARY_OP_LESS: return mp_obj_new_bool(lhs_val < rhs_val); break; + case MP_BINARY_OP_MORE: return mp_obj_new_bool(lhs_val > rhs_val); break; + case MP_BINARY_OP_LESS_EQUAL: return mp_obj_new_bool(lhs_val <= rhs_val); break; + case MP_BINARY_OP_MORE_EQUAL: return mp_obj_new_bool(lhs_val >= rhs_val); break; default: goto unsupported_op; diff --git a/stmhal/irq.c b/stmhal/irq.c index d0d89b394f..7a265a52b9 100644 --- a/stmhal/irq.c +++ b/stmhal/irq.c @@ -48,7 +48,7 @@ MP_DEFINE_CONST_FUN_OBJ_0(pyb_wfi_obj, pyb_wfi); /// respectively. This return value can be passed to enable_irq to restore /// the IRQ to its original state. STATIC mp_obj_t pyb_disable_irq(void) { - return MP_BOOL(disable_irq() == IRQ_STATE_ENABLED); + return mp_obj_new_bool(disable_irq() == IRQ_STATE_ENABLED); } MP_DEFINE_CONST_FUN_OBJ_0(pyb_disable_irq_obj, pyb_disable_irq); diff --git a/stmhal/modnwcc3k.c b/stmhal/modnwcc3k.c index 7dd5fb2cdf..20e7035e5b 100644 --- a/stmhal/modnwcc3k.c +++ b/stmhal/modnwcc3k.c @@ -512,7 +512,7 @@ STATIC mp_obj_t cc3k_disconnect(mp_obj_t self_in) { STATIC MP_DEFINE_CONST_FUN_OBJ_1(cc3k_disconnect_obj, cc3k_disconnect); STATIC mp_obj_t cc3k_isconnected(mp_obj_t self_in) { - return MP_BOOL(wlan_connected && ip_obtained); + return mp_obj_new_bool(wlan_connected && ip_obtained); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(cc3k_isconnected_obj, cc3k_isconnected); diff --git a/stmhal/pin.c b/stmhal/pin.c index 8ba6cce8ea..9f40b11d67 100644 --- a/stmhal/pin.c +++ b/stmhal/pin.c @@ -305,7 +305,7 @@ STATIC mp_obj_t pin_debug(mp_uint_t n_args, const mp_obj_t *args) { pin_class_debug = mp_obj_is_true(args[1]); return mp_const_none; } - return MP_BOOL(pin_class_debug); + return mp_obj_new_bool(pin_class_debug); } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_debug_fun_obj, 1, 2, pin_debug); STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(pin_debug_obj, (mp_obj_t)&pin_debug_fun_obj); diff --git a/stmhal/sdcard.c b/stmhal/sdcard.c index 2e98f73c15..5d86ba5e6a 100644 --- a/stmhal/sdcard.c +++ b/stmhal/sdcard.c @@ -244,7 +244,7 @@ bool sdcard_write_blocks_dma(const uint8_t *src, uint32_t block_num, uint32_t nu // consistent interface and methods to mount/unmount it. STATIC mp_obj_t sd_present(mp_obj_t self) { - return MP_BOOL(sdcard_is_present()); + return mp_obj_new_bool(sdcard_is_present()); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(sd_present_obj, sd_present); @@ -256,7 +256,7 @@ STATIC mp_obj_t sd_power(mp_obj_t self, mp_obj_t state) { sdcard_power_off(); result = true; } - return MP_BOOL(result); + return mp_obj_new_bool(result); } STATIC MP_DEFINE_CONST_FUN_OBJ_2(sd_power_obj, sd_power); diff --git a/stmhal/usb.c b/stmhal/usb.c index cedd3525c7..ebd2433d26 100644 --- a/stmhal/usb.c +++ b/stmhal/usb.c @@ -363,7 +363,7 @@ STATIC mp_obj_t pyb_usb_vcp_setinterrupt(mp_obj_t self_in, mp_obj_t int_chr_in) STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_usb_vcp_setinterrupt_obj, pyb_usb_vcp_setinterrupt); STATIC mp_obj_t pyb_usb_vcp_isconnected(mp_obj_t self_in) { - return MP_BOOL(USBD_CDC_IsConnected()); + return mp_obj_new_bool(USBD_CDC_IsConnected()); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_usb_vcp_isconnected_obj, pyb_usb_vcp_isconnected); diff --git a/teensy/modpyb.c b/teensy/modpyb.c index a59e3b4f57..7a40580ed1 100644 --- a/teensy/modpyb.c +++ b/teensy/modpyb.c @@ -248,7 +248,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_standby_obj, pyb_standby); /// \function have_cdc() /// Return True if USB is connected as a serial device, False otherwise. STATIC mp_obj_t pyb_have_cdc(void ) { - return MP_BOOL(usb_vcp_is_connected()); + return mp_obj_new_bool(usb_vcp_is_connected()); } STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_have_cdc_obj, pyb_have_cdc); diff --git a/unix/modjni.c b/unix/modjni.c index 0ffcb9969a..3946232615 100644 --- a/unix/modjni.c +++ b/unix/modjni.c @@ -265,7 +265,7 @@ STATIC mp_obj_t jobject_unary_op(mp_uint_t op, mp_obj_t self_in) { case MP_UNARY_OP_LEN: { jint len = JJ(CallIntMethod, self->obj, List_size_mid); if (op == MP_UNARY_OP_BOOL) { - return MP_BOOL(len != 0); + return mp_obj_new_bool(len != 0); } return MP_OBJ_NEW_SMALL_INT(len); }