FFI Callbacks
Andreas Raab
andreas.raab at gmx.de
Fri Sep 1 20:26:30 UTC 2006
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
|