[squeak-dev] Re: Send NULL to a C function trough FFI
Mariano Martinez Peck
marianopeck at gmail.com
Fri Sep 19 04:47:57 UTC 2008
On Wed, Sep 17, 2008 at 2:26 AM, Andreas Raab <andreas.raab at gmx.de> wrote:
> 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.
>
Andreas: You were right. It was that. I changed to DBXTimeSpec* and now I
can send nil.
Many thanks,
mariano
>
> Cheers,
> - Andreas
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20080919/36094bdc/attachment.htm
More information about the Squeak-dev
mailing list
|