Return custom struct from c issue [ffi]

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
lapsule
Posts: 3
Joined: Thu Jan 07, 2016 2:09 am

Return custom struct from c issue [ffi]

Post by lapsule » Fri Jun 17, 2016 11:09 am

Here is a c demo lib:

Code: Select all

#include <stdio.h>

struct s {
        int a;
};

struct s getss(void)
{
        struct s ss;
        ss.a = 1;

        printf("return ss.\n");
        return ss;
}
involve in micropython:

Code: Select all

import uctypes,ffi
l = ffi.open('./liba.so')
gs = l.func('p', 'getss', 'v')
gs(None)
got Segmentation fault:

Code: Select all

return ss.
[ 3442.782855] do_page_fault() #2: sending SIGSEGV to micropython for invalid write access to
[ 3442.782873] 00000000 (epc == 2b0ce720, ra == 2b0ce714)

Post Reply