Before it's too late: delegate calling convention
Gregor Richards
Richards at codu.org
Wed Nov 1 15:40:01 PST 2006
Burton Radons wrote:
> Gregor Richards wrote:
>
>> It's also DMD-with-D-calling-convention-specific X_X
>>
>> (eg: won't work with GDC, won't work with C functions)
>
>
> It could easily be done, just have the thunks bounce into a function the
> Thunk template builds that reorder the arguments (this function can
> gratefully be written in D), and add a post-call patch to fix the stack.
>
> I'm not trying to argue that this is the way it should be, obviously the
> compiler should be handling this magic. But while I've never heard
> Walter say anything about thunking, I can predict with great accuracy
> that he'll be against it because it's a hidden allocation [of great
> utility]. It seems like it would be better to have SOMETHING to do the
> task than to keep crashing against the barricade and getting more and
> more frustrated.
>
> Anyway, thunking D to C would generally be pretty hazardous because as
> soon as you pass it to the C library it'll be collectable, and since the
> allocation IS hidden it would be easy to miss. Manually thunking C
> function pointers isn't difficult with any correctly-written C library
> and doesn't happen often enough in my experience (once per wrapper, to
> be exact) to bother with.
>
> What happens more often is the need to cast from function pointers to
> delegates (or SOME common function pointer), constrained to the D
> calling convention. Since that can be done without allocations, I think
> that and only that should be made part of the language. The rest can
> follow with time, or not.
If I recall properly, DMC uses thunktions for C++'s lame pseudodelegates :)
- Gregor Richards
More information about the Digitalmars-d
mailing list