[squeak-dev] Re: Send NULL to a C function trough FFI

Andreas Raab andreas.raab at gmx.de
Wed Sep 17 05:26:47 UTC 2008


Mariano Martinez Peck wrote:
> Igor: I tried what you said but I get the same error. Here is more information:
> 
> The C function is like this:
>  
> int *odbx_result*(
>     odbx_t* /*handle*/,
>     odbx_result_t** /*result*/,
> 
>     struct timeval* /*timeout*/,
>     unsigned long /*chunk*/ )
> 
> 
> My method with FFI is this:
> 
> apiQueryResult: connectionHandle handle: handle timeout: timeout chunk: 
> chunk
>     <cdecl: long 'odbx_result' (ulong ulong* DBXTimeSpec ulong) module: 
> 'opendbx'>
>     ^self externalCallFailed

The reason it doesn't work is that the FFI spec doesn't match the C 
function declaration. Both the first and third argument are declared 
pointers in C, and not declared pointers in the FFI. This is 
particularly problematic with the struct timeval since the FFI now 
expects you to pass the struct timeval by value (since you haven't 
declared it as being a pointer) and will not accept nil as argument 
(since it would have to dereference the pointer and consequently crash). 
Try the following declaration instead:

<cdecl: long 'odbx_result' (ulong* ulong* DBXTimeSpec* ulong) module: 
'opendbx'>

This will accept nil as the parameter for the timeout value.

Cheers,
   - Andreas



More information about the Squeak-dev mailing list