Re: Cannot coerce a BlockCallback to ExternalCallback*
Posted by
Blair McGlashan-4 on
Apr 16, 2006; 2:37pm
URL: https://forum.world.st/Cannot-coerce-a-BlockCallback-to-ExternalCallback-tp3378227p3378235.html
"Chris Uppal" <
[hidden email]> wrote in message
news:4440e67f$0$662$
[hidden email]...
>I think the following shows a problem in Dolphin, but I doubt if there's
>any
> way to fix it, so this post is more of a warning for the records than a
> bug
> report.
> ...
> I've just worked out what the problem is. My ExternalLibrary's methods
> are of
> the form:
>
> enumerateSuggestions: aHunspell word: aString callback:
> anExternalCallback
> <stdcall: sdword enumerateSuggestions void* char*
> ExternalCallback*>
> ^ self invalidCall.
>
> That will only work if #asParameter has /already/ been sent to the
> ExternalCallback in question, since it's only then that it (re-)generates
> its
> #thunk. If that hasn't been sent then the VM reports (correctly) that the
> call
> failed, and #invalidCall reports (misleadingly) that it was a coercion
> failure.
>
This is "by design". It was never intended that ExternalCallbacks should be
directly passable as interop parameters, nor that they could be used as the
parameter type either. If you look in the base image you'll find callbacks
are always declared as lpvoid. It just so happens that because
ExternalCallback has the same initial shape as an ExternalStructure (first
inst var is a byte object), that it is possible to get away with it if the
callback object has been initialised to contain the thunk - i.e. by sending
#asParameter.
I agree the error reporting could be better, and probably the compiler
should not permit ExternalCallback as a parameter type.
Regards
Blair