[squeak-dev] Re: [Pharo-project] Alien FFI

Igor Stasenko siguctua at gmail.com
Mon Nov 24 21:29:44 UTC 2008


2008/11/24 Vassili Bykov <smalltalkbigot at gmail.com>:
> On Mon, Nov 24, 2008 at 11:37 AM, John M McIntosh
> <johnmci at smalltalkconsulting.com> wrote:
>> Ok, well asAlien seems to be used as conversion methods to ensure a passed
>> object is an alien.
>> What would you like to do instead?
>
> I'd like to remove String>>asAlien and have no #asAlien methods. C and
> Smalltalk worlds are too different, and poor man's marshalling with
> #asAlien only adds confusion. It works in a simple unambiguous way
> only for some objects like True and False. String>>asAlien is already
> not transparent because it allocates a static buffer that needs
> freeing. And then, how far do we take this? A ByteArray could
> conceivably have #asAlien, but should we also handle Arrays of
> Integers? What about Arrays of Strings?
>
> Apart from the C semantics, this is also a questionable style. The
> general rule for the choice between instance creation or conversion
> messages is that conversion messages make sense when the classes are
> sufficiently similar. An Alien is not an alternative form of a String,
> and "'foo' asAlien" is not a conversion of a String to an Alien. It's
> a creation of an Alien initialized in a particular way. There could be
> other equally meaningful ways of initializing it from the same data,
> so "Alien newCString: 'foo'" works because we could also have "Alien
> newUnicodeString: 'foo'", and "'foo' asAlien" is a convenience that
> doesn't scale (and also makes aliens appear less alien than they ought
> to).
>

how about
'foo' asAlien: #CString
'foo' asAlien: #UnicodeString

and generic form:
anyObject asAlien: #someAlienType

the key point is to let object itself decide how to convert to
appropriate alien object, because there is no other who knows better
how to perform a conversion.

A conversion requires a collaboration between object to be converted
and destination type.
There is no way to make ' Alien newCString: arbirtatyObject ' working
without putting/using special behavior into arbirtatyObject.

> --Vassili
>
>


-- 
Best regards,
Igor Stasenko AKA sig.



More information about the Squeak-dev mailing list