hx-ffi
hx-ffi copied to clipboard
Passing structs results in corrupted data in the c (neko atleast)
#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.
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.