[Q] primtives versus apicall

Andreas Raab andreas.raab at gmx.de
Fri Mar 12 16:11:09 UTC 2004


> 1) am i correct in assuming that i can directly call any c function
> that resides in a dll or framework from squeak by simply doing
> <apicall: module:> without having to recompile any part of the vm?

You are correct. But if you compile your plugin as external plugin you don't
have to recompile any part of the VM either.

> 2)how are datatypes mapped to each other from smalltalk to c in the
> apicall method? pointers, structures, a two dimensional array ( int**
> myIntPointers)? and then how are they returned where squeak knows what
> they are? i know the primtive method uses the interpreterProxy.

The basic data types (essentially numbers) are mapped just as one would
expect. Strings (declared via char*) are copied to a C string and passed
along. More complex structures can be represented by subclasses of
ExternalStructure. For ugly stuff like pointers to pointers you have to do
your own "extract the right thing magic".

> 3)other than not having to write the primitive wrappers, are there any
> other advantages to using apicall over named primitives? is it faster?

Hell, no! It's a *lot* slower than executing a plugin. What the FFI does is
implementing the generic "coerce from everything to everything, check all
the argument types, make sure nothing's wrong with pointer, see if you're
trying to do something stupid, setup the call stack, yaddaya" stuff. It does
everything at runtime that your compiler does at compile time. It makes no
of the optimizing assumptions you do in a plugin, it blindly coerces
anything to anything you can imagine.

Generally, the rules are: If you need quick and dirty results, use FFI. If
you want to make something that lasts, use a plugin.

> ps: i do not want to touch or recompile anything that has to do
> with the vm. what i have done so far with named primitives has
> prevented me from having to recompile anything else but the code
> for plugin, which is what i want.

I don't understand what you're trying to say with the above. If you build an
external plugin you don't have to recompile or touch anything inside the VM,
right. So... what's your point?

Cheers,
  - Andreas




More information about the Squeak-dev mailing list