[Vm-dev] FFI Plugin | Auto-conversion of char* return value into String considered harmful

Eliot Miranda eliot.miranda at gmail.com
Fri Jun 12 02:51:43 UTC 2020

Hi Marcel,

On Wed, Jun 10, 2020 at 3:37 AM Marcel Taeumel <marcel.taeumel at hpi.de>

> Hi all!
> The FFI plugin automatically converts "char*" return values into a
> Smalltalk string when returning from the FFI call.
> I would rather leave this conversion to the image side because you have to
> do it anyway when interpreting external structures. See ExternalData >>
> #fromCString. And because it can be dangerous. Note that I do like
> automatic String-to-char* conversion when making an FFI call. Just not the
> other way around.
> See (Threaded)FFIPlugin >> #ffiReturnCStringFrom:.
> What are your thoughts on this matter?

Agreed.  One issue is how to make the behaviour optional to keep
backwards compatibility. Another is efficiency.  If it turn out that the
set of useful conversions is small we could parameterise the plugin wth
those conversions, still have it do the relevant conversion.

For example, the class of the container for the result could be somehow
encoded in the ExternalLibraryFunction's flags inst var.  That might also
give us backwards compatibility because very few bitsa of flags are used.
The flags var simply defines the relevant call type: C: (0) or apicall: (1)
in the least significant bit and whether the call is threaded or not in bit
8 (256).  So we could use, say, bits 16,17 or bits 6,7, to encode the
string class if the function returns a string. 0 -> ByteString, 1 ->
DoubleByteString (unused or undefined?), 2 -> WideString, 3 -> return

> Marcel

best, Eliot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20200611/f2942a65/attachment-0001.html>

More information about the Vm-dev mailing list