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

Marcel Taeumel marcel.taeumel at hpi.de
Wed Jun 10 15:47:54 UTC 2020


Hi Nicolas.

> The convention would be char* <=> Null terminated string, byte* <=> uninterpreted bytes

Ah! Good to know. So, for byte* there would be an additional field (in a struct) for the size?

Best,
Marcel
Am 10.06.2020 17:41:33 schrieb Nicolas Cellier <nicolas.cellier.aka.nice at gmail.com>:
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 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 :
> 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
>
>

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 [mailto: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 [mailto: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/a237b141/attachment-0001.html>


More information about the Vm-dev mailing list