Skip to content

[Generator] Generator does not create BlittablePInvokes when a boolean is present in a parameter #18685

Closed

Description

@mandel-macaque

When we did not need to worry about NativeAOT we could write a binding in the following way:

[Mac (14,0)]
[Export ("presentViewController:asPopoverRelativeToRect:ofView:preferredEdge:behavior:hasFullSizeContent:")]
void Present (NSViewController viewController, CGRect positioningRect, NSView positioningView, NSRectEdge preferredEdge, NSPopoverBehavior behavior, byte hasFullSizeContent);

Yet, now the above code will result in the following cecil test failure:

Cecil.Tests.BlittablePInvokes.CheckForNonBlittablePInvokes: Failures: In the file tests/cecil-tests/BlittablePInvokes.cs, read the guide carefully.
Expected: <empty>
But was: < ("ObjCRuntime.NativeHandle ObjCRuntime.Messaging::NativeHandle_objc_msgSend_nfloat_bool(System.IntPtr,System.IntPtr,System.Runtime.InteropServices.NFloat,System.Boolean)", <string.Empty>), ("ObjCRuntime.NativeHandle ObjCRuntime.Messaging::NativeHandle_objc_msgSendSuper_nfloat_bool(System.IntPtr,System.IntPtr,System.Runtime.InteropServices.NFloat,System.Boolean)", <string.Empty>), ("System.Void ObjCRuntime.Messaging::void_objc_msgSend_NativeHandle_CGRect_NativeHandle_UIntPtr_IntPtr_bool(System.IntPtr,System.IntPtr,ObjCRuntime.NativeHandle,CoreGraphics.CGRect,ObjCRuntime.NativeHandle,System.UIntPtr,System.IntPtr,System.Boolean)", <string.Empty>), ("System.Void ObjCRuntime.Messaging::void_objc_msgSendSuper_NativeHandle_CGRect_NativeHandle_UIntPtr_IntPtr_bool(System.IntPtr,System.IntPtr,ObjCRuntime.NativeHandle,CoreGraphics.CGRect,ObjCRuntime.NativeHandle,System.UIntPtr,System.IntPtr,System.Boolean)", <string.Empty>) **>**

You can see that one of the offending methods is:

ObjCRuntime.Messaging::void_objc_msgSend_NativeHandle_CGRect_NativeHandle_UIntPtr_IntPtr_bool(System.IntPtr,System.IntPtr,ObjCRuntime.NativeHandle,CoreGraphics.CGRect,ObjCRuntime.NativeHandle,System.UIntPtr,System.IntPtr,System.Boolean)"

A workaround to the issue is to change the binding to the following:

[Internal]
[Mac (14,0)]
[Export ("presentViewController:asPopoverRelativeToRect:ofView:preferredEdge:behavior:hasFullSizeContent:")]
void _Present (NSViewController viewController, CGRect positioningRect, NSView positioningView, NSRectEdge preferredEdge, NSPopoverBehavior behavior, byte hasFullSizeContent);

[Mac (14,0)]
[Wrap ("_Present (viewController, positioningRect, positioningView, preferredEdge, behavior, hasFullSizeContent ? (byte) 1 : (byte) 0)")]
void Present (NSViewController viewController, CGRect positioningRect, NSView positioningView, NSRectEdge preferredEdge, NSPopoverBehavior behavior, bool hasFullSizeContent);

NONE of or users expect to have to change all their bindings that take a boolean to take a byte and do a wrap with hasFullSizeContent ? (byte) 1 : (byte) 0.

Either the test is wrong or the generator needs to be able to deal with the boolean parameter without asking the user to do the conversion to a byte.

Activity

  1. added
    generator
    on Aug 10, 2023
  2. rolfbjarne commented on Aug 10, 2023

    @rolfbjarne
    Member

    We have a rather long list of known failures:

    https://github.com/xamarin/xamarin-macios/blob/571cd456275909f6f87d132b45bd4e55ecec3e0f/tests/cecil-tests/BlittablePInvokes.KnownFailures.cs#L19

    Most of these are due to limitations in the generator that needs to be fixed, so just add the new signature there.

    Keeping this bug open to fix the generator (and the corresponding known failures).

  3. added this to the .NET 8 milestone on Aug 10, 2023
  4. added 2 commits that reference this issue on Sep 15, 2023
    1c74cb7
    98d8d45
  5. added a commit that references this issue on Sep 19, 2023
    5f3c312
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    generator

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions