Skip to content

Commit

Permalink
[ImageIO] Refactor block code to use blittable callbacks.
Browse files Browse the repository at this point in the history
This is necessary in order to convert all block callbacks to use
UnmanagedCallersOnly function pointers (which can't have non-blittable types
in their signature).

Contributes towards xamarin#15783.
  • Loading branch information
rolfbjarne committed Mar 1, 2023
1 parent ac1dad4 commit acf158d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/ImageIO/CGImageMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ public CGImageMetadata (NSData data)
extern unsafe static void CGImageMetadataEnumerateTagsUsingBlock (/* CGImageMetadataRef __nonnull */ IntPtr metadata,
/* CFStringRef __nullable */ IntPtr rootPath, /* CFDictionaryRef __nullable */ IntPtr options, BlockLiteral* block);

delegate bool TrampolineCallback (IntPtr blockPtr, NativeHandle key, NativeHandle value);
delegate byte TrampolineCallback (IntPtr blockPtr, NativeHandle key, NativeHandle value);

[MonoPInvokeCallback (typeof (TrampolineCallback))]
static bool TagEnumerator (IntPtr block, NativeHandle key, NativeHandle value)
static byte TagEnumerator (IntPtr block, NativeHandle key, NativeHandle value)
{
var nsKey = Runtime.GetNSObject<NSString> (key, false)!;
var nsValue = Runtime.GetINativeObject<CGImageMetadataTag> (value, false)!;
var del = BlockLiteral.GetTarget<CGImageMetadataTagBlock> (block);
return del (nsKey, nsValue);
return del (nsKey, nsValue) ? (byte) 1 : (byte) 0;
}

static unsafe readonly TrampolineCallback static_action = TagEnumerator;
Expand Down

0 comments on commit acf158d

Please sign in to comment.