[squeak-dev] FFI calls to functions that expect pointers to write results into

Levente Uzonyi leves at elte.hu
Wed Feb 4 22:34:45 UTC 2015


For each variable allocate some bytes on the external heap using an 
ExternalAddress, and wrap into an ExternalData, then pass the ExternalData 
as the argument. Something like this:

| modelData modelValue ... |
modelData := ExternalData
 	fromHandle: (ExternalAddress gcallocate: 4)
 	type: ExternalType long asPointerType.
...
self piBoardId: modelData ...
modelValue := modelData getHandle signedLongAt: 1

Or you can create an ExternalStructure with a single field, and declare 
the arguments as pointers to that type instead of long.

Levente

On Wed, 4 Feb 2015, tim Rowledge wrote:

> I haven’t been able to uncover *any* decent doc for FFI calls, so any pointers would be nice.
>
> In particular, given a C function def
> void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted)
> What on earth do I do ?
>
> 	#<cdecl: void 'piBoardId' (long * long * long * long* long* ) module: 'wiringPi’>
> seems to be the basic incantation but so far I see nothing that might explain to me what would make it actually work.
>
> Really basic stuff like
> piBoardRev
> "Read the revision code of the Pi. ."
> "ScratchWiringPiInterface new piBoardRev"
> 	#<cdecl: long 'piBoardRev' (void ) module: 'wiringPi'>
> 	^self externalCallFailed
>
> seems fine, as does
> digitalRead: pin
> "Read the value of a given Pin, returning HIGH or LOW"
> "ScratchWiringPiInterface new digitalRead: 1"
> 	#<cdecl: long 'digitalRead' (long ) module: 'wiringPi'>
> 	^self externalCallFailed
>
> What has my assorted googling missed?
>
> tim
> --
> tim Rowledge; tim at rowledge.org; http://www.rowledge.org/tim
> Useful random insult:- Wasn't fully debugged before being released.
>
>
>
>


More information about the Squeak-dev mailing list