[CoreGraphics] Adjust CGPDFOperatorTable to not use a generic Action delegate. - #11560
Merged
rolfbjarne merged 1 commit intoMay 17, 2021
Merged
Conversation
…delegate.
* CoreCLR doesn't support generic Action delegates in reverse (P/Invokes), so
we need to find a different solution.
* The native CGPDFOperatorTable callback API is not very friendly to us,
because we can't pass it callback-specific data, which means that the
managed caller must conform to the FullAOT requirement of the managed
callback (must be a static function; must have a MonoPInvokeCallback
attribute).
* We can leverage the new function pointer syntax in C# 9 to make these
requirements enforced by the C# compiler (unmanaged function pointer +
UnmanagedCallersOnly attribute). The resulting API is still clunky to use,
but I don't see any way around that.
Fixes this monotouch-test failure with CoreCLR:
[FAIL] Tamarin : System.Runtime.InteropServices.MarshalDirectiveException : Cannot marshal 'parameter #3': Non-blittable generic types cannot be marshaled.
at CoreGraphics.CGPDFOperatorTable.CGPDFOperatorTableSetCallback(IntPtr table, String name, Action`2 callback)
at CoreGraphics.CGPDFOperatorTable.SetCallback(String name, Action`2 callback)
at MonoTouchFixtures.CoreGraphics.PDFScannerTest.Tamarin() in xamarin-macios/tests/monotouch-test/CoreGraphics/PDFScannerTest.cs:line 102
Ref: dotnet/runtime#32963
tj-devel709
reviewed
May 14, 2021
|
|
||
| if (callback == null) | ||
| CGPDFOperatorTableSetCallback (Handle, name, null); | ||
| CGPDFOperatorTableSetCallback (Handle, name, (CGPDFOperatorCallback) null); |
Member
There was a problem hiding this comment.
Woah I don't recall seeing this before haha. A type cast for null! What does this do?
Contributor
There was a problem hiding this comment.
@tj-devel709 imaging you are a compiler and you see:
public void CGPDFOperatorTableSetCallback (IntPtr handel, String name, CGPDFOperatorCallback callback) {...}
public void CGPDFOperatorTableSetCallback (IntPtr handel, String name, OtherObject obj) {..}
Later in the code I have:
CGPDFOperatorTableSetCallback (Handle, name, null);Which of the above overloads do you call??
And if you see:
CGPDFOperatorTableSetCallback (Handle, name, (CGPDFOperatorCallback) null);AFAIK you can also do:
CGPDFOperatorTableSetCallback (Handle, name, default(CGPDFOperatorCallback));which helps the compiler too without a cast.
Member
There was a problem hiding this comment.
Ah thank you for explaining!
Collaborator
✅ [PR Build] Tests passed on Build. ✅Tests passed on Build. API diff✅ API Diff from stable View API diffAPI & Generator diff✅ API Diff (from PR only) (no change) 🎉 All 82 tests passed 🎉Pipeline on Agent XAMBOT-1104.BigSur' |
mandel-macaque
approved these changes
May 14, 2021
dalexsoto
approved these changes
May 14, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
we need to find a different solution.
because we can't pass it callback-specific data, which means that the
managed caller must conform to the FullAOT requirement of the managed
callback (must be a static function; must have a MonoPInvokeCallback
attribute).
requirements enforced by the C# compiler (unmanaged function pointer +
UnmanagedCallersOnly attribute). The resulting API is still clunky to use,
but I don't see any way around that.
Fixes this monotouch-test failure with CoreCLR:
Ref: dotnet/runtime#32963