I am trying to interface with C code. Everything seems to work more or less fine, until I have to deal with output parameters, that is, parameters in C functions which are meant to be passed buffers which are filled by the function.
I have made a very basic example which only copies a string and I have made a shared library called "libexample.so" which exports void example_cp(char *in, char *out); I have verified that I can call the shared library from C. Now in factor I have defined an interface like this USING: alien alien.c-types alien.syntax alien.libraries ; IN: example-alien << "libexample" "/home/papillon/esperimenti/ssl/libexample.so" cdecl add-library >> LIBRARY: libexample FUNCTION: void example_cp ( c-string in, c-string out ) ; In the listener I try to use example_cp, but I am not sure how to pass a preallocated char buffer. If I try { { c-string } } [ "hello world" swap example_cp ] with-out-parameters I get "index out of bounds: 0" which seems reasonable, since I pass an empty c-string. But if I try something like { { c-string initial: "hello earth" } } [ "hello world" swap example_cp ] with-out-parameters I get "local-allocation-error". What is the correct way to pass a preallocated buffer? ------------------------------------------------------------------------------ Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server from Actuate! Instantly Supercharge Your Business Reports and Dashboards with Interactivity, Sharing, Native Excel Exports, App Integration & more Get technology previously reserved for billion-dollar corporations, FREE http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk _______________________________________________ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk