I need to pass a C struct (below) from MicroPython to an external C module.
Code: Select all
typedef struct {
struct myS *stptr;
uint32_t i;
uint32_t *jptr;
} myT;
in my C function to retrieve the struct?
Thanks very much!
PP
Code: Select all
typedef struct {
struct myS *stptr;
uint32_t i;
uint32_t *jptr;
} myT;
Code: Select all
STATIC mp_obj_t mp_my_c_wrapper (mp_obj_t oa, mp_obj_t oi) {
const char *a = mp_obj_str_get_str(oa);
int i = mp_obj_get_int(oi);
char *val = malloc(2000);
val = my_c_wrapper (a, i);
return val; // FIXME: How do I return a string?
}
Yup, but you might be better off with mp_obj_str_get_dataProudPagan wrote: ↑Wed Jun 12, 2019 7:59 amIs mp_obj_str_get_str() the right function to use to convert the mp_obj_t passed to mp_my_c_wrapper() to a char * ?
Code: Select all
qstr mp_obj_str_get_qstr(mp_obj_t self_in); // use this if you will anyway convert the string to a qstr
const char *mp_obj_str_get_str(mp_obj_t self_in); // use this only if you need the string to be null terminated
const char *mp_obj_str_get_data(mp_obj_t self_in, size_t *len);
ProudPagan wrote: ↑Wed Jun 12, 2019 7:59 amMy C wrapper needs to return a string back to Python, How do I accomplish this?
Code: Select all
mp_obj_t mp_obj_new_str(const char* data, size_t len);