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

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Wed Jun 10 15:41:12 UTC 2020


Maybe there is also the option of declaring it byte *?
The convention would be char* <=> Null terminated string, byte* <=>
uninterpreted bytes

Le mer. 10 juin 2020 à 15:14, Marcel Taeumel <marcel.taeumel at hpi.de> a
écrit :

>
> Hi all,
>
> I just found out that you can avoid this automatic interpretation as C
> string if you use a type alias to char*. This could at least help if an
> external library forgets the NULL character for that returned char* and
> makes your VM crash. :-)
>
> Best,
> Marcel
>
> Am 10.06.2020 12:35:27 schrieb 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?
>
> Best,
> Marcel
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20200610/2d95d165/attachment.html>


More information about the Vm-dev mailing list