diff options
author | Alex Riesen <alexander.riesen@cetitec.com> | 2023-01-19 12:09:39 +0100 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2023-01-20 21:59:49 +1100 |
commit | abaa4abd2d5d43eb812301ab7f0fcaa9c93c18c2 (patch) | |
tree | 562f87bca01d81936c774ab863256bcc6bb2c8e7 /py | |
parent | 94ee1b629a18429a92fc0475e7318c6a48dabd2a (diff) |
py: Add parenthesis to default impl of MP_OBJ_TO_PTR, MP_OBJ_FROM_PTR.
Unless MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_D, these macros only work with
values and "->"/"." expressions as their sole argument. In other words,
the macros are broken with expressions which contain operations of lower
precedence than the cast operator.
Depending on situation, the old code either results in compiler error:
MP_OBJ_TO_PTR(flag ? o1 : o2) expands into "(void *)flag ? o1 : o2",
which some compiler configurations will reject (e.g. GCC -Wint-conversion
-Wint-to-pointer-cast -Werror)
Or in an incorrect address calculation:
For ptr declared as "uint8_t *" the MP_OBJ_FROM_PTR(ptr + off)
expands into ((mp_obj_t)ptr) + off, resulting in an obviously
wrong address.
Signed-off-by: Alex Riesen <alexander.riesen@cetitec.com>
Diffstat (limited to 'py')
-rw-r--r-- | py/obj.h | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -313,12 +313,12 @@ typedef union _mp_rom_obj_t { // Cast mp_obj_t to object pointer #ifndef MP_OBJ_TO_PTR -#define MP_OBJ_TO_PTR(o) ((void *)o) +#define MP_OBJ_TO_PTR(o) ((void *)(o)) #endif // Cast object pointer to mp_obj_t #ifndef MP_OBJ_FROM_PTR -#define MP_OBJ_FROM_PTR(p) ((mp_obj_t)p) +#define MP_OBJ_FROM_PTR(p) ((mp_obj_t)(p)) #endif // Macros to create objects that are stored in ROM. |