FFI / Primitive question

Joshua Gargus schwa at fastmail.us
Mon Jun 11 02:43:14 UTC 2007

I think that I was a bit confused.  If I now understand correctly,  
the second argument to #primitive:parameters: doesn't do anything  
special for FFI types (i.e. subclasses of ExternalObject); it is just  
a dynamic type test that can be applied to any type of Squeak object.

Is it true that the slang code must explicitly handle the two cases  
where the 'handle' iVar of an ExternalObject refers to:
	- the binary data for the object (when the handle is a ByteArray)
	- a pointer to data on the C-heap (when the handle is an  
ExternalAddress)   ?
Or, is there some feature of Slang, FFI, etc. to make it easier to  
work with ExternalObjects?  I suspect that there isn't.


On Jun 10, 2007, at 5:14 PM, Joshua Gargus wrote:

> Hi all,
> I have a question about mixing FFI types with primitive  
> invocations.  For my example, let's say that I want to pass a  
> MacRect as a primitive argument.  The Slang method looks like:
> primitiveFrobulate: macRect
> 	| rectPtr |
> 	self primitive: 'primitiveFrobulate' parameters: #(MacRect).
> 	rectPtr := interpreterProxy firstIndexableField: macRect.
> 	self stFrobMacRect: rectPtr
> The function stFrobMacRect() is hand-written C-code that looks  
> something like:
> void stFrobMacRect(int ptr)
> {
> 	Rect* rectPtr = (Rect*) ptr;
> 	/* now, frobulate the rect */
> }
> This doesn't work (I don't see the expected values while  
> frobulating).  What would be the right expression to write in the  
> Slang code to get a pointer to the Rect to pass to stFrobMacRect()?
> Thanks,
> Josh

More information about the Squeak-dev mailing list