Access ptr8 from viper inside user C module? #18318
-
|
Hi, I'm working on improving the speed of some functions and have a mix of viper code and C code in my project. Long story short I'm not sure how to access a ptr8 from my C module, when I try and edit values it doesn't seem to change. in my viper function we have and perform_test is in a c module and it simply And the buf remains unchanged. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
|
I would expect that |
Beta Was this translation helpful? Give feedback.
-
|
There's a bit more to look for. STATIC mp_obj_t someclass_staticmethod1(mp_obj_t var1) {
if (mp_obj_is_obj(var1)) {
if (mp_obj_is_type(var1, &mp_type_bytearray)) {
mp_buffer_info_t bufinfo;
if (mp_get_buffer(var1, &bufinfo, 0)) {
uint8_t * address8 = bufinfo.buf;
uint32_t len = bufinfo.len;
printf(" is bytearray @%p size=%d\n", address8, (int)len);
}
}
}
return mp_const_none;
} |
Beta Was this translation helpful? Give feedback.
I would expect that
bufwould be passed in the same way that Micropython passes integers. So in your C code you will have to extract the integer and cast it to a pointer first. The way to do this is using the macros inpy/obj.h: