-
Notifications
You must be signed in to change notification settings - Fork 61
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
Added "delayed" generation of delegate signatures (follow-up) #81
base: main
Are you sure you want to change the base?
Conversation
sorry for delayed response and thank you for clarification. |
With this patch if a delegate is found during the construction of a method, its declaration is still emitted, after all the other types have been. This is implemented through an HashSet of forward declarations that is used as now for delegates, but can be expanded to include other item types in the future.
5475a75
to
9cafa3d
Compare
Rebased, should have no conflicts. |
Hmm, I tried it with the current main branch, but type MyCallback = extern "C" fn(size: usize, data: *const u16) -> *mut u8;
#[no_mangle]
pub extern "C" fn set_callback(alloc_callback: MyCallback) {
println!("Your callback is {alloc_callback:p}");
} This seems to be expanded to: [DllImport(__DllName, EntryPoint = "set_callback", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
internal static extern void set_callback(delegate* unmanaged[Cdecl]<nuint, ushort*, byte*> alloc_callback); |
That's not how it expanded in my tests. I will recheck, but I'm currently away from "decent computing devices" for a couple of weeks. |
It is configuration. Namely, it works with |
This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
This is a reopening of #53, rebased on top of the latest
main
branch.I apologize for not replying to the request of an example, sorry.
I'll show an example in this PR; I'm not 100% sure this is the best way to fix the issue, but we can start from this for a discussion.
Description
Just as before, with this patch if a delegate is found during the construction of a method, its declaration is still emitted, after all the other types have been.
This is implemented through an HashSet of forward declarations that is used as now for delegates, but can be expanded to include other item types in the future.
Example
Take this example Rust source:
This CORRECTLY generates the following C# code:
So far so good. Now, that Rust declaration is nasty and would probably get refactored as:
which produces
which is obviously bad because
set_callback_alloc_callback_delegate
's definition is nowhere to be found.The proposed fix produces this version instead:
Differences from the version in PR #53
The code is verbatim the same with these small differences:
public
visibility modifier, given that the declaration is now inside the class and would default toprivate
instead ofinternal
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
boilerplate