returning a list from C module

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
vtu93
Posts: 1
Joined: Wed Dec 19, 2018 6:52 am

returning a list from C module

Post by vtu93 » Wed Dec 19, 2018 6:59 am

I am trying to convert an array of floats(fft_test->output) into a list that I can return on a C module.
I had a look through obj.h and mp_obj_new_bytearray seemed like the best choice.

void *fft_output = fft_test->output;
mp_obj_t fft_list = mp_obj_new_bytearray(sizeof(fft_output), fft_output);
return fft_list;

This will return "segmentation fault (core dump)"

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: returning a list from C module

Post by dhylands » Thu Dec 20, 2018 3:35 am

sizeof(fft_output) will be the sizeof the pointer which will be 4 or 8 bytes depending in the CPU you're targeting.

The fact that it segfaults probably points to fft_output not being valid.

Post Reply