hx-ffi icon indicating copy to clipboard operation
hx-ffi copied to clipboard

Passing structs results in corrupted data in the c (neko atleast)

Open MetaChrome opened this issue 10 years ago • 1 comments

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
    int i;
} St_n;
char* test(St_n st) {
    char res[1024];
    sprintf(res,"st %d",st.i);
    return res;
}

package ;
import ffi.lib.EasyLibrary;
@:struct(St_n=>{
    var i:Int;
})
@:lib("libntv.so")
class Ntv extends EasyLibrary {
    public static function main():Void {
        var lib:Ntv=new Ntv();
        trace(lib.test(new St_n(100)));
    }
    public function test(st:St_n):String;
}

Results in: Ntv.hx:10: st 32735

Please please specify how to fix this.

MetaChrome avatar Apr 14 '14 06:04 MetaChrome

It is returning the incremented pointer instead of the malloc location. In addition, char*/std.String are causing segmentation fault. I don't know why yet.

MetaChrome avatar Apr 14 '14 09:04 MetaChrome