<div id="__MailbirdStyleContent" style="font-size: 10pt;font-family: Arial;color: #000000">Hi all!<div class="mb_sig"></div><div><br></div><div>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><br></div><div>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><br></div><div>The pair of (argObject, argType) could be expressed as FFICallArgument:</div><div><br></div><div>FFICallArgument</div><div>   argObject  ... <Object></div><div>   argType ... <ExternalType></div><div><br></div><div>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><br></div><div>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><br></div><div>ExternalLibrary >> #doesNotCoerce: callArg for: message</div><div>   | argObject argType argIndex wrappedArg |</div><div>   argObject := callArg first. "or argObject accessor"</div><div>   argType := callArg second. "or argType accessor"</div><div>   argIndex := message arguments indexOf: argObject.</div><div>   wrappedArg := argType referentClass fromHandle: argObject.</div><div>   message arguments beWritableObject. "Just in case ;-)"</div><div>   message at: argIndex put: wrappedArg.</div><div>   ^ message sendTo: self</div><div><br></div><div>Please share your thoughts. :-)</div><div><br></div><div>Best,</div><div>Marcel</div></div>