Access ptr8 from viper inside user C module? #18318
Answered
by
bikeNomad
GanerCodes
asked this question in
Using MicroPython
|
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. |
Answered by
bikeNomad
Oct 23, 2025
Replies: 2 comments 3 replies
|
I would expect that |
2 replies
Answer selected by
GanerCodes
|
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;
} |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: