-
Notifications
You must be signed in to change notification settings - Fork 514
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
.NET: Use UnmanagedCallersOnlyAttribute instead of (or in addition to) MonoPInvokeCallbackAttribute #10470
Comments
I'd rather have it instead of (than in addition to) so we're sure we're testing the new attribute and behaviour. |
The old/existing attribute won't be in CoreCLR, which is |
The MonoPInvokeCallbackAttribute is only required on platforms where we run the AOT compiler. |
I don't recall if all those existing attributes are under |
…n unmanaged function pointer instead of delegate. Very partial fix for xamarin#10470. In .NET 6 we can use the [UnmanagedCallersOnly] attribute to mark functions that are called from native code (instead of the [MonoPInvokeCallback] attribute). It turns out this is a rather major refactoring (in particular for blocks), so start by doing it for just a single function, to make sure using [UnmanagedCallersOnly] at least works somewhere. Ref: xamarin#10470
It turns out this is a rather involved task, in particular when it comes to blocks:
In the normal case (where the callback is supposed to be just a plain C function), things are a bit simpler, in that we can port our manual binding code incrementally. I've ported a single callback (which at least makes sure that using function pointers work): #12920 Since the work for blocks is not trivial, and requires some design and thought, it can be postponed until .NET 7. |
…n unmanaged function pointer instead of delegate. Very partial fix for #10470. (#12920) In .NET 6 we can use the [UnmanagedCallersOnly] attribute to mark functions that are called from native code (instead of the [MonoPInvokeCallback] attribute). It turns out this is a rather major refactoring (in particular for blocks), so start by doing it for just a single function, to make sure using [UnmanagedCallersOnly] at least works somewhere. Ref: #10470
…llback] for the ScheduledAudioFileRegionCallback function. Ref xamarin#10470.
…okeCallback] for the CGPDFDictionaryApplyFunction function. I had to change the first argument from 'string' to 'IntPtr', because 'string' isn't blittable. In order to diverge the code paths as little as possible, I also made this change for the legacy Xamarin version. Ref xamarin#10470.
…eCallback] for the managed callbacks called from native code. Ref xamarin#10470.
…llback] Partial Fix for xamarin#10470
Adding to keep track of incomplete work for using |
…eCallback] Partial Fix for #10470 (#15906) Completed the work for CoreGraphics. One exception is PDFArray.cs which uses `SetupBlockUnsafe` (noted in the issue) Co-authored-by: Manuel de la Pena <[email protected]>
The following packages use SetupBlock or SetupBlockUnsafe: ImageIO - mixed usage of callback as delegate and an unmanaged delegate. This is |
@stephen-hawley is this all done now? |
The generator needs to be updated too: #18685 |
I believe this is complete now, we're only missing manual P/Invokes (neither the generator nor blocks), which is handled in #15684. |
.NET 5/C# 9 has a new UnmanagedCallersOnlyAttribute, which we should start using instead of the MonoPInvokeCallbackAttribute (the main advantage is that the compiler will tell you if you use it wrong, as opposed to the MonoPInvokeCallbackAttribute, where the AOT compiler will crash and not tell you why if you use it wrong).
Ref: dotnet/runtime#47177
Using UnmanagedCallersOnlyAttribute for block callbacks is rather complex, and has been moved to a separate issue: #15783 (see #10470 (comment)).
The text was updated successfully, but these errors were encountered: