<div id="__MailbirdStyleContent" style="font-size: 10pt;font-family: Arial;color: #000000">Hi Eliot.<div><br></div><div>> <span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">For example, the class of the container for the result could be somehow</span></div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">encoded in the ExternalLibraryFunction's flags inst var.</span><div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px"><br></span></div><div><span style="font-family: Arial, Helvetica, sans-serif"><span style="font-size: 13px">Since FFICallTypesMask is 2r11111111, I suggest bits > 8. Bits 16 and 17 sound good to leave room for other call flags. Or is the encoding of the return format part of the "call type"? I wouldn't think so...</span></span></div><div><span style="font-family: Arial, Helvetica, sans-serif"><span style="font-size: 13px"><br></span></span></div><div><span style="font-family: Arial, Helvetica, sans-serif"><span style="font-size: 13px">Let's say...</span></span></div><div><span style="font-family: Arial, Helvetica, sans-serif"><span style="font-size: 13px"><br></span></span></div><div><span style="font-family: Arial, Helvetica, sans-serif"><span style="font-size: 13px">FFICallTypesMask := 2r11111111.</span></span></div><div><span style="font-family: Arial, Helvetica, sans-serif"><span style="font-size: 13px">FFICallTypeCDecl := 0.</span><br></span></div><div><span style="font-family: Arial, Helvetica, sans-serif"><span style="font-size: 13px">FFICallTypeApi := 1.</span><br></span></div><div><span style="font-family: Arial, Helvetica, sans-serif"><span style="font-size: 13px"><br></span></span></div><div><span style="font-family: Arial, Helvetica, sans-serif"><span style="font-size: 13px">FFICallFlagMask := </span></span><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">2r11111111 << 8</span><span style="font-size: 13px;font-family: Arial, Helvetica, sans-serif">.</span></div><div><span style="font-family: Arial, Helvetica, sans-serif"><span style="font-size: 13px">FFICallFlagThreaded := 1 << 8.</span></span></div><div><span style="font-family: Arial, Helvetica, sans-serif"><span style="font-size: 13px"><br></span></span></div><div><span style="font-family: Arial, Helvetica, sans-serif"><span style="font-size: 13px">FFICallReturnTypeMask := 2</span></span><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">r11111111 << 16</span><span style="font-size: 13px;font-family: Arial, Helvetica, sans-serif">.</span></div><div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">FFICallReturnByteString := 0.</span><span style="font-size: 13px;font-family: Arial, Helvetica, sans-serif"><br></span></div><div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">FFICallReturnDoubleByteString := 1 << 16.</span></div><div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">FFICallReturnWideString := 2 << 16.</span></div><div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">FFICallReturnExternalData := 3 << 16. "Even if return type is not char* ... for later override?"</span></div><div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px"><br></span></div><div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">And may this, too:</span></div><div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px"><br></span></div><div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">FFICallReturnExternalDataArray := 7 << 16. "Assume char** or int** etc."</span></div><div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px"><br></span></div><div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">What do you think? I plan to add the in-image part for ExternalDataArray soon. I found a simple way to manage pointer-to-pointer types with little adjustment in FFI-Kernel. :-)</span></div><div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px"><br></span></div><div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">Hmmm... not sure about </span><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">FFICallReturnExternalData, though. Seems to be the most generic case where interpretation is completely in the image. Even a possible lift to </span><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">ExternalDataArray for pointer arrays. Maybe...</span></div><div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px"><br></span></div><div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">FFICallReturnExternalData := 255 << 16. "= </span><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">FFICallReturnTypeMask"</span><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px"><br></span></div><div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">FFICallReturnExternalDataArray := 128 << 16. "= highest bit in mask"</span><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px"><br></span></div><div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px"><br></span></div><div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">That would leave either room for "UTF-64" encoding :-D as 3 << 16.</span></div><div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px"><br></span></div><div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">Best,</span></div><div><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">Marcel</span></div><blockquote class="history_container" type="cite" style="border-left-style: solid;border-width: 1px;margin-top: 20px;margin-left: 0px;padding-left: 10px;min-width: 500px">
                        <p style="color: #AAAAAA; margin-top: 10px;">Am 12.06.2020 04:52:06 schrieb Eliot Miranda <eliot.miranda@gmail.com>:</p><div style="font-family:Arial,Helvetica,sans-serif"> Hi Marcel,
<br>
<br>On Wed, Jun 10, 2020 at 3:37 AM Marcel Taeumel <marcel.taeumel@hpi.de>
<br>wrote:
<br>
<br>>
<br>> Hi all!
<br>>
<br>> The FFI plugin automatically converts "char*" return values into a
<br>> Smalltalk string when returning from the FFI call.
<br>>
<br>> I would rather leave this conversion to the image side because you have to
<br>> do it anyway when interpreting external structures. See ExternalData >>
<br>> #fromCString. And because it can be dangerous. Note that I do like
<br>> automatic String-to-char* conversion when making an FFI call. Just not the
<br>> other way around.
<br>>
<br>> See (Threaded)FFIPlugin >> #ffiReturnCStringFrom:.
<br>>
<br>> What are your thoughts on this matter?
<br>>
<br>
<br>Agreed.  One issue is how to make the behaviour optional to keep
<br>backwards compatibility. Another is efficiency.  If it turn out that the
<br>set of useful conversions is small we could parameterise the plugin wth
<br>those conversions, still have it do the relevant conversion.
<br>
<br>For example, the class of the container for the result could be somehow
<br>encoded in the ExternalLibraryFunction's flags inst var.  That might also
<br>give us backwards compatibility because very few bitsa of flags are used.
<br>The flags var simply defines the relevant call type: C: (0) or apicall: (1)
<br>in the least significant bit and whether the call is threaded or not in bit
<br>8 (256).  So we could use, say, bits 16,17 or bits 6,7, to encode the
<br>string class if the function returns a string. 0 -> ByteString, 1 ->
<br>DoubleByteString (unused or undefined?), 2 -> WideString, 3 -> return
<br>pointer.
<br>
<br>Best,
<br>> Marcel
<br>>
<br>
<br>
<br>-- 
<br>_,,,^..^,,,_
<br>best, Eliot
<br><div dir="ltr"><div dir="ltr">Hi Marcel,<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jun 10, 2020 at 3:37 AM Marcel Taeumel <<a href="mailto:marcel.taeumel@hpi.de">marcel.taeumel@hpi.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex;border-left-width: 1px;border-left-style: solid;border-left-color: rgb(204,204,204);padding-left: 1ex;min-width: 500px"> <div id="gmail-m_-2805817654826232059__MailbirdStyleContent" style="font-size: 10pt;font-family: Arial;color: rgb(0,0,0)">Hi all!<div></div><div><br></div><div>The FFI plugin automatically converts "char*" return values into a Smalltalk string when returning from the FFI call.</div><div><br></div><div>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.</div><div><br></div><div>See (Threaded)FFIPlugin >> #ffiReturnCStringFrom:.</div><div><br></div><div>What are your thoughts on this matter?</div></div></blockquote><div><br></div><div>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.</div><div><br></div><div>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 pointer.</div><div><br></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex;border-left-width: 1px;border-left-style: solid;border-left-color: rgb(204,204,204);padding-left: 1ex;min-width: 500px"><div id="gmail-m_-2805817654826232059__MailbirdStyleContent" style="font-size: 10pt;font-family: Arial;color: rgb(0,0,0)"><div><span style="font-size: 10pt">Best,</span><br></div><div>Marcel</div></div></blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><span style="font-size: 10pt;border-collapse: separate"><div>_,,,^..^,,,_<br></div><div>best, Eliot</div></span></div></div></div></div>
<br></marcel.taeumel@hpi.de></div></blockquote></div>