FYI: I fixed the #numArgs bug in http://code.google.com/p/pharo/issues/detail?id=2844. Lukas On 22 August 2010 16:37, Nicolas Cellier <nicolas.cellier.aka.nice@gmail.com> wrote:
Repeat after me: the Debugger is your friend. You just have to write something like
Object compile: 'a_piInitialize: handle backend: backend host: host port: port   "long odbx_init(odbx_t**, char*, char*, char*)"   <cdecl: long ''odbx_init'' (ulong* char* char* char*) module: ''opendbx''>   ^self externalCallFailed'
in a workspace and select 'debug it' menu item.
Since I'm in a good mood, I tell you the result:
In Parser>>externalFunctionDeclaration you can see this sentence:
    (args position = self properties selector numArgs) ifFalse: [         ^self expected: 'Matching number of arguments'].
What if you put an underscore in the selector ?
   #a_piInitialize:backend:host:port: numArgs -> -1
This means this selector is not recognized as a valid selector... So you have to fix String>>numArgs, then you'll be able to compile a selector with underscores.
Repeat after me: the Debugger is your friend.
Nicolas
2010/8/22 Schwab,Wilhelm K <bschwab@anest.ufl.edu>:
See 2842.
Thanks for confirming it!
Bill
________________________________________ From: pharo-project-bounces@lists.gforge.inria.fr [pharo-project-bounces@lists.gforge.inria.fr] On Behalf Of Mariano Martinez Peck [marianopeck@gmail.com] Sent: Sunday, August 22, 2010 5:41 AM To: Pharo-project@lists.gforge.inria.fr Subject: Re: [Pharo-project] FFI and underscores in 1.1 (RC2)
I can reproduce the problem. I have this method that works:
apiInitialize: handle backend: backend host: host port: port   "long odbx_init(odbx_t**, char*, char*, char*)"   <cdecl: long 'odbx_init' (ulong* char* char* char*) module: 'opendbx'>   ^self externalCallFailed
But not this one:
apiInitialize: handle backend: backend host: host port: port   "long odbx_init(odbx_t**, char*, char*, char*)"   <cdecl: long 'odbx_init' (ulong* char* char* char*) module: 'opendbx'>   ^self externalCallFailed
a_piInitialize: handle backend: backend host: host port: port   "long odbx_init(odbx_t**, char*, char*, char*)"   <cdecl: long 'odbx_init' (ulong* char* char* char* Matching number of arguments expected ->) module: 'opendbx'>   ^self externalCallFailed
Please, open a ticket. Maybe Lukas can help us.
Cheers
Mariano
On Sat, Aug 21, 2010 at 9:47 PM, Schwab,Wilhelm K <bschwab@anest.ufl.edu<mailto:bschwab@anest.ufl.edu>> wrote: I just had an underwhelming response to my latest adventure into FFI, specifically wrapping the Acces IO USB API. Â Specifically, very few functions survived from description to actually being compiled. Â AFAICT, the compiler does not like underscores in method names for external functions.
I'm not even sure how to describe it other than to give an example. Â This works:
dIOWrite8:deviceIndex byteIndex:byteIndex data:data    "unsigned long DIO_Write8(unsigned long DeviceIndex, unsigned long ByteIndex, unsigned char Data)"
   < cdecl: ulong 'DIO_Write8' (  ulong ulong byte ) >    ^self invalidCall.
This should compile, but it complains about a mismatch in the number of arguments:
DIO_Write8:deviceIndex byteIndex:byteIndex data:data    "unsigned long DIO_Write8(unsigned long DeviceIndex, unsigned long ByteIndex, unsigned char Data)"
   < cdecl: ulong 'DIO_Write8' (  ulong ulong byte ) >    ^self invalidCall.
The less Pharo forces us to change names as given from the outside, the better off we will be. Â I am using a 1.1 RC2 image, just in case this has been fixed since then?? Â I really need to build a new image soon.
Bill
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr<mailto:Pharo-project@lists.gforge.inria.fr> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
-- Lukas Renggli www.lukas-renggli.ch