8000
Incorrect setting of class.base.type in some examples #17327
Labels
Port, board and/or hardware
unix/standard port, PiZero2 board, but irrelevant to this issue
MicroPython version
MicroPython v1.25.0 on 2025-04-30; linux [GCC 14.2.0] version
Reproduction
Here are some lines from native module example code.
examples/natmod/btree/btree_c.c
has:examples/natmod/re/re.c
has:examples/natmod/deflate/deflate.c
has:examples/natmod/framebuf/framebuf.c
has:The last is a bit confusing. Because all of these files
#include "py/dynruntime.h"
, it gets macro-expanded to:And so patterns the same as the third option. That struct field holds a pointer to the variable that in the interpreter is called
mp_type_type
, but which is not directly visible to the dynamic native modules.So cases 3 and 4 are setting the
base.type
to a(const mp_obj_type_t *)
, whose value is&mp_type_type
(this is the const type object defined inpy/objtype.c
, not the macro defined inpy/dynruntime.h
).Whereas cases 1 and 2 are setting the
base.type
to a pointer to a struct field that holds such a(const mp_obj_type_t *)
. They're one pointer level further removed. This is just not noticed because they are cast to(void *)
.I believe that cases 1 and 2 are mistakes, and that they should be following the pattern in case 3 or case 4. Am I right?
Expected behaviour
No response
Observed behaviour
See code analysis above. Examples as-is compile and run without issue; but I think this is just because the type is being treated as opaque and not being dereferenced.
Additional Information
No, I've provided everything above.
Code of Conduct
Yes, I agree
The text was updated successfully, but these errors were encountered: