xamarin / xamarin-macios

.NET for iOS, Mac Catalyst, macOS, and tvOS provide open-source bindings of the Apple SDKs for use with .NET managed languages such as C#
Other
2.45k stars 511 forks source link

[generator] Remove 32bits code in the #else part of ARCH_32 #9351

Open spouliot opened 4 years ago

spouliot commented 4 years ago

Steps to Reproduce

  1. Build xamain-macios
  2. Look at generated code

Expected Behavior

    public static bool SupportsFrameSemantics (ARFrameSemantics frameSemantics)
        {
#if ARCH_32
                throw new PlatformNotSupportedException ("This API is not supported on this version of iOS");
#else
                return global::ObjCRuntime.Messaging.bool_objc_msgSend_Int64 (klass, Selector.GetHandle ("supportsFrameSemantics:"), (Int64)frameSemantics);
#endif
        }

64 bits code should not have checks for IntPtr.Size == 8 nor any code for 32 bits execution.

It's not a bug issue as the linker will remove it - unless it's disabled.

Actual Behavior

    public static bool SupportsFrameSemantics (ARFrameSemantics frameSemantics)
        {
#if ARCH_32
                throw new PlatformNotSupportedException ("This API is not supported on this version of iOS");
#else
                if (IntPtr.Size == 8) {
                                return global::ObjCRuntime.Messaging.bool_objc_msgSend_Int64 (klass, Selector.GetHandle ("supportsFrameSemantics:"), (Int64)frameSemantics);
                        } else {
                                return global::ObjCRuntime.Messaging.bool_objc_msgSend_int (klass, Selector.GetHandle ("supportsFrameSemantics:"), (int)frameSemantics);
                        }
#endif
                }
        }

Environment

main

rolfbjarne commented 4 years ago

The ARCH_32 part could also be extended to where it's not currently used:

public static bool SomeOtherFunction (ARFrameSemantics frameSemantics)
{
#if ARCH_32
        return global::ObjCRuntime.Messaging.bool_objc_msgSend_int (klass, Selector.GetHandle ("supportsFrameSemantics:"), (int)frameSemantics);
#else
        return global::ObjCRuntime.Messaging.bool_objc_msgSend_Int64 (klass, Selector.GetHandle ("supportsFrameSemantics:"), (Int64)frameSemantics);
#endif
}
wjk commented 4 years ago

@rolfbjarne Shouldn’t these just be deleted instead? Are there even any supported 32-bit iOS-family platforms anymore?

rolfbjarne commented 4 years ago

@wjk:

Shouldn’t these just be deleted instead? Are there even any supported 32-bit iOS-family platforms anymore?

Yes, there are, we support building for iOS 7+, and 32-bit iOS wasn't removed until iOS 11.