<div id="__MailbirdStyleContent" style="font-size: 10pt;font-family: Arial;color: #000000">
                                        
                                        
                                            
                                        
                                        
                                        Hi Fabio,<div><br></div><div>> <span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">I don't like the idea of adding a plugin-specific mechanism like this to </span><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">the VM.</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">Why is that? The implementation strategy would be very clear: like #doesNotUnderstand:. It's just a new entry on the special objects array.</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">> </span><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">There already is BAD_ARGUMENT, </span><span style="font-family: Arial, Helvetica, sans-serif;font-size: 13px">maybe there's a way to encode which argument is bad in the error code?</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 wouldn't be any better. We could not support on-the-fly packaging of arguments for FFI calls by relying on just the error code. Without on-the-fly packaging, the FFI call could likely be unsafe (e.g. everybody using 'int' instead of the enum type as proposed in the library) or awkward to program (e.g., Alien callbacks require Smalltalk blocks to be warpped into Callback objects).</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><div class="mb_sig"></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 20.06.2020 22:05:29 schrieb Fabio Niephaus <lists@fniephaus.com>:</p><div style="font-family:Arial,Helvetica,sans-serif"> Hi Marcel:
<br>
<br>On Fri, 19 Jun 2020 at 1:15 pm, Marcel Taeumel <marcel.taeumel@hpi.de>
<br>wrote:
<br>
<br>>
<br>> Hi all!
<br>>
<br>> We have #doesNotUnderstand:, which is sent to the receiver when a message
<br>> cannot be understood. Default reaction in Object is to raise
<br>> MessageNotUnderstood exception.
<br>>
<br>> What if we could have a similar mechanism for FFI calls:
<br>> #doesNotCoerce:for:. The receiver would be the one that made that call,
<br>> should be an instance of ExternalLibrary, but could be any object. The
<br>> arguments would be a pair of (argObject, argType) and the message (like the
<br>> argument for doesNotUnderstand:) that represents the FFI call.
<br>>
<br>
<br>I don't like the idea of adding a plugin-specific mechanism like this to
<br>the VM. I know it's not as convenient, but maybe something similar can be
<br>achieved with error codes in fallback code? There already is BAD_ARGUMENT,
<br>maybe there's a way to encode which argument is bad in the error code?
<br>
<br>Fabio
<br>
<br>
<br>> The pair of (argObject, argType) could be expressed as FFICallArgument:
<br>>
<br>> FFICallArgument
<br>>    argObject  ... <object>
<br>>    argType ... <externaltype>
<br>>
<br>> I suppose that such a new class would have to be reserved in the special
<br>> objects array. An alternative would be to just use Array. Keep it simple.
<br>> ;-)
<br>>
<br>> Default reaction could be to implement #doesNotCoerce:for: in Object (as
<br>> *FFI-Kernel extension) to raise FFICallArgumentNotCoerced exception (to be
<br>> implemented). Also, we could implement manual coercion in ExternaLibrary
<br>> to, for example, wrap atomics into their aliasing structures.
<br>>
<br>> ExternalLibrary >> #doesNotCoerce: callArg for: message
<br>>    | argObject argType argIndex wrappedArg |
<br>>    argObject := callArg first. "or argObject accessor"
<br>>    argType := callArg second. "or argType accessor"
<br>>    argIndex := message arguments indexOf: argObject.
<br>>    wrappedArg := argType referentClass fromHandle: argObject.
<br>>    message arguments beWritableObject. "Just in case ;-)"
<br>>    message at: argIndex put: wrappedArg.
<br>>    ^ message sendTo: self
<br>>
<br>> Please share your thoughts. :-)
<br>>
<br>> Best,
<br>> Marcel
<br>>
<br><div><div dir="auto">Hi Marcel:</div></div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, 19 Jun 2020 at 1:15 pm, 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;padding-left: 1ex;border-left-color: rgb(204,204,204);min-width: 500px"> <div id="m_4219620875839454893__MailbirdStyleContent" style="font-size: 10pt;font-family: Arial;color: rgb(0,0,0)">Hi all!<div style="font-family:Arial"></div><div style="font-family:Arial"><br></div><div style="font-family:Arial">We have #doesNotUnderstand:, which is sent to the receiver when a message cannot be understood. Default reaction in Object is to raise MessageNotUnderstood exception.</div><div style="font-family:Arial"><br></div><div style="font-family:Arial">What if we could have a similar mechanism for FFI calls: #doesNotCoerce:for:. The receiver would be the one that made that call, should be an instance of ExternalLibrary, but could be any object. The arguments would be a pair of (argObject, argType) and the message (like the argument for doesNotUnderstand:) that represents the FFI call.</div></div></blockquote><div dir="auto"><br></div><div dir="auto">I don't like the idea of adding a plugin-specific mechanism like this to the VM. I know it's not as convenient, but maybe something similar can be achieved with error codes in fallback code? There already is BAD_ARGUMENT, maybe there's a way to encode which argument is bad in the error code?</div><div dir="auto"><br></div><div dir="auto">Fabio</div><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex;border-left-width: 1px;border-left-style: solid;padding-left: 1ex;border-left-color: rgb(204,204,204);min-width: 500px"><div id="m_4219620875839454893__MailbirdStyleContent" style="font-size: 10pt;font-family: Arial;color: rgb(0,0,0)"><div style="font-family:Arial"></div><div style="font-family:Arial"><br></div><div style="font-family:Arial">The pair of (argObject, argType) could be expressed as FFICallArgument:</div><div style="font-family:Arial"><br></div><div style="font-family:Arial">FFICallArgument</div><div style="font-family:Arial">   argObject  ... <Object></div><div style="font-family:Arial">   argType ... <ExternalType></div><div style="font-family:Arial"><br></div><div style="font-family:Arial">I suppose that such a new class would have to be reserved in the special objects array. An alternative would be to just use Array. Keep it simple. ;-)</div><div style="font-family:Arial"><br></div><div style="font-family:Arial">Default reaction could be to implement #doesNotCoerce:for: in Object (as *FFI-Kernel extension) to raise FFICallArgumentNotCoerced exception (to be implemented). Also, we could implement manual coercion in ExternaLibrary to, for example, wrap atomics into their aliasing structures.</div><div style="font-family:Arial"><br></div><div style="font-family:Arial">ExternalLibrary >> #doesNotCoerce: callArg for: message</div><div style="font-family:Arial">   | argObject argType argIndex wrappedArg |</div><div style="font-family:Arial">   argObject := callArg first. "or argObject accessor"</div><div style="font-family:Arial">   argType := callArg second. "or argType accessor"</div><div style="font-family:Arial">   argIndex := message arguments indexOf: argObject.</div><div style="font-family:Arial">   wrappedArg := argType referentClass fromHandle: argObject.</div><div style="font-family:Arial">   message arguments beWritableObject. "Just in case ;-)"</div><div style="font-family:Arial">   message at: argIndex put: wrappedArg.</div><div style="font-family:Arial">   ^ message sendTo: self</div><div style="font-family:Arial"><br></div><div style="font-family:Arial">Please share your thoughts. :-)</div><div style="font-family:Arial"><br></div><div style="font-family:Arial">Best,</div><div style="font-family:Arial">Marcel</div></div></blockquote></div></div>
<br></externaltype></object></marcel.taeumel@hpi.de></div></blockquote></div>