[squeak-dev] FFI problem: "could not coerce arguments"

Bert Freudenberg bert at freudenbergs.de
Mon Aug 18 19:33:28 UTC 2008


Am 18.08.2008 um 21:29 schrieb Bert Freudenberg:

> Am 18.08.2008 um 20:44 schrieb Mariano Martinez Peck:
>
>>
>>
>> On Mon, May 26, 2008 at 10:44 AM, Mariano Martinez Peck <marianopeck at gmail.com 
>> > wrote:
>>
>>
>> On Mon, May 26, 2008 at 10:36 AM, Bert Freudenberg <bert at freudenbergs.de 
>> > wrote:
>>
>> On 26.05.2008, at 15:21, Mariano Martinez Peck wrote:
>>
>> "could not coerce arguments"
>>
>> int odbx_set_option(
>>   odbx_t* handle,
>>   unsigned int option,
>>   void* value )
>> apiSetOption: handle option: anOption value: aValue
>>   "int odbx_unbind(odbx_t*)"
>>   <cdecl: long 'odbx_set_option' (ulong ulong void*) module:  
>> 'opendbx' >
>>   ^self externalCallFailed
>>
>> err := OpenDBX apiSetOption: self option:32  value:1.
>>
>>
>> The first argument appears to be a pointer to a handle object. You  
>> probably should not declare that as ulong if you then pass  
>> "self" (which I assume is a ExternalStructure subclass). But that  
>> depends on how you acquire the handle, and how you represent it in  
>> the image.
>>
>> Yes you are right, sorry. It was not self, but a attribute called  
>> handle. My mistake.
>>
>>
>> The argument to void* should be a ByteArray or WordArray, methinks,  
>> I'd try "WordArray with: 1" if you want to pass a pointer to the  
>> Integer 1.
>>
>> - Bert -
>>
>> Sounds interesting. I will test it and then I tell you.
>>
>>
>>
>> Bert: I test this using WordArray and I work perfect in all the  
>> cases the value was a number. But the type in the function  
>> definition is void*. So, now, I need to send not only a 1 or 0, but  
>> a String. In this case, I cannot do WordArray with: 'aStringValue'   
>> neither ByteArray with: 'aStringValue' . What can I do in this  
>> case? Do you have any idea?
>>
>> I mean, I need to use the same parametrer void*, sending it a  
>> number or a string.
>
>
> Declare the method again like
>
> apiSetOption: handle option: anOption string: aString
>   <cdecl: long 'odbx_set_option' (ulong ulong char*) module:  
> 'opendbx' >
>   ^self externalCallFailed
>
> and use that by simply passing a String (don't even bother to  
> convert to ByteArray [but watch out for the terminating 0]).
>
> - Bert -



... that is, unless this works with the original method (I'm not sure):

self apiSetOption: handle option: bla value: 'aStringValue' asByteArray.


- Bert -





More information about the Squeak-dev mailing list