FFI Callbacks

Alejandro F. Reimondo aleReimondo at smalltalking.net
Fri Sep 1 20:54:56 UTC 2006


Hi Andreas,
Using the option (2) will activate the method context for Foo>>callSomething
 (a context with a block context....)
The option (1) will execute the primitive WITHOUT method activation.
I think that perfomance of option (1) will be similar to primitives/plugIn
calls
Also the indirection to the global association (CallSomething function)
 must be added; in option (1) the method serve as reference to the function.
Without an optimized VM the penalty of method activation
 and indirection can make a diference.
cheers,
Ale.


----- Original Message ----- 
From: "Andreas Raab" <andreas.raab at gmx.de>
To: "The general-purpose Squeak developers list"
<squeak-dev at lists.squeakfoundation.org>
Sent: Friday, September 01, 2006 5:26 PM
Subject: Re: FFI Callbacks


> Diego Fernandez wrote:
> > I know that <> is used in primitives, but in calls to external
> > libraries there is a performance reason for this kind of notation?
> > Have this kind of methods different bycodes (like in primitives) or
> > it's only a shorthand for the longer expression?
>
> It's both a shorthand and a "statically compiled version" of the longer
> expression. Here is something that is essentially equivalent:
>
> 1. Using <> syntax:
>
> Foo>>callSomething
>       <cdecl: void 'callSomething' () module: 'Foo'>
>       Transcript cr; show: 'Failed to call function'.
>
> 2. Using the (mostly) equivalent explicit version:
>
> Object subclass: #Foo
>      instanceVariableNames: ''
>      classVariableNames: 'CallSomething'
>      poolDictionaries: ''
>      category: 'Croquet-Harness'
>
> Foo class>>initialize
>      "Construct the FFI call for callSomething"
>      CallSomething := ExternalLibraryFunction
>          name:'callSomething'
>          module: 'Foo'
>          callType: ExternalFunction callTypeCDecl
>          returnType: ExternalType void
>          argumentTypes: #()
>
> Foo>>callSomething
>      ^[CallSomething invoke] on: PrimitiveFailed do:[
>          Transcript cr; show: 'Failed to call function'.
>       ].
>
> The reason this is only "mostly" equivalent is that there isn't a
> PrimitiveFailed exception (but there should be ;-)
>
> Cheers,
>    - Andreas
>




More information about the Squeak-dev mailing list