New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix Issue 7925 - extern(C++) delegates #13217
Conversation
Thanks for your pull request and interest in making D better, @tim-dlang! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla references
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#13217" |
The linkage is already part of the type for delegates. Member functions for extern(C++) on Win32 use a different calling convention than other functions. This commit changes the calling convention of extern(C++) delegates for Win32 to match member functions. The calling convention for nested functions is also changed, because they can become delegates, too.
if (tf.linkage == LINK.cpp && !target.is64bit && target.os == Target.OS.Windows) | ||
tym = (tf.parameterList.varargs == VarArg.variadic) ? TYnfunc : TYmfunc; | ||
else | ||
tym = totym(tf); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks to me like totym() is in the wrong here, not the caller.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks to me like totym() is in the wrong here, not the caller.
totym() does not know, that the function is used in a delegate, because the argument tf contains the type of funcptr and not the whole delegate. TypeFunction does not seem to have information about the hidden this pointer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An alternative implementation would be to add a flag to TypeFunction, which marks functions with hidden this pointer. Function tytym could then choose the calling convention based on that flag. The flag could also be used to fix https://issues.dlang.org/show_bug.cgi?id=3720 and https://issues.dlang.org/show_bug.cgi?id=17080, but it would be a bigger change and affect more code. You would probably also need a new syntax for function types with hidden this pointer and a trait for getting the flag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. cc @WalterBright
This reverts commit 10134cf.
The linkage is already part of the type for delegates. Member functions
for extern(C++) on Win32 use a different calling convention than other
functions. This commit changes the calling convention of extern(C++)
delegates for Win32 to match member functions. The calling convention
for nested functions is also changed, because they can become delegates,
too.