Skip to content

Commit a8d78cc

Browse files
Jongydpgeorge
authored andcommitted
py/obj: Add debug-only runtime checks to mp_obj_is_type().
Zero effect on non debug builds, and also usually optimized out even in debug builds as mp_obj_is_type() is called with a compile-time known type. I'm not sure we even have dynamic uses of mp_obj_is_type() at the moment, but if we ever will they will be protected from now on. Signed-off-by: Yonatan Goldschmidt <[email protected]>
1 parent 2a6ba47 commit a8d78cc

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

py/obj.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -750,12 +750,12 @@ void *mp_obj_malloc_helper(size_t num_bytes, const mp_obj_type_t *type);
750750
// Type checks are split to a separate, constant result macro. This is so it doesn't hinder the compilers's
751751
// optimizations (other tricks like using ({ expr; exper; }) or (exp, expr, expr) in mp_obj_is_type() result
752752
// in missed optimizations)
753-
#define mp_type_assert_not_bool_int_str_nonetype(t) ( \
754-
MP_STATIC_ASSERT_NOT_MSC((t) != &mp_type_bool), \
755-
MP_STATIC_ASSERT_NOT_MSC((t) != &mp_type_int), \
756-
MP_STATIC_ASSERT_NOT_MSC((t) != &mp_type_str), \
757-
MP_STATIC_ASSERT_NOT_MSC((t) != &mp_type_NoneType), \
758-
1)
753+
#define mp_type_assert_not_bool_int_str_nonetype(t) ( \
754+
MP_STATIC_ASSERT_NOT_MSC((t) != &mp_type_bool), assert((t) != &mp_type_bool), \
755+
MP_STATIC_ASSERT_NOT_MSC((t) != &mp_type_int), assert((t) != &mp_type_int), \
756+
MP_STATIC_ASSERT_NOT_MSC((t) != &mp_type_str), assert((t) != &mp_type_str), \
757+
MP_STATIC_ASSERT_NOT_MSC((t) != &mp_type_NoneType), assert((t) != &mp_type_NoneType), \
758+
1)
759759

760760
#define mp_obj_is_type(o, t) (mp_type_assert_not_bool_int_str_nonetype(t) && mp_obj_is_exact_type(o, t))
761761
#if MICROPY_OBJ_IMMEDIATE_OBJS

0 commit comments

Comments
 (0)