You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Some enums have different values between x64 and arm64 on macOS and Mac Catalyst #12111
which means TARGET_ABI_USES_IOS_VALUES is true on:
iOS, tvOS, watchOS (all abis): because TARGET_OS_IPHONE is 1 on these platforms
Mac Catalyst: arm64 (because !TARGET_CPU_X86_64)
macOS: arm64 (because !TARGET_CPU_X86_64)
and TARGET_ABI_USES_IOS_VALUES is false on:
Mac Catalyst: x64
macOS: x64
Searching Apple's headers, this shows up for the following enums:
typedefNS_ENUM(NSInteger, NSTextAlignment) {
NSTextAlignmentLeft=0, // Visually left aligned#ifTARGET_ABI_USES_IOS_VALUESNSTextAlignmentCenter=1, // Visually centeredNSTextAlignmentRight=2, // Visually right aligned#else/* !TARGET_ABI_USES_IOS_VALUES */NSTextAlignmentRight=1, // Visually right alignedNSTextAlignmentCenter=2, // Visually centered#endifNSTextAlignmentJustified=3, // Fully-justified. The last line in a paragraph is natural-aligned.NSTextAlignmentNatural=4// Indicates the default alignment for script
} API_AVAILABLE(macos(10.0), ios(6.0), watchos(2.0), tvos(9.0));
It is a similar issue. The difference with SSLCipherSuite is that it's a deprecated API and thus not very performance sensitive. Some of the same constraints apply though:
Existing code and libraries embed the (managed) enum values and thus it's less likely to break existing code if the old values are kept
For macOS the ARM64 is new platform so there's no existing code for it and the "reference" values are the x64 ones
Mac Catalyst is technically also new platform on the managed side but there's compatibility story with iOS and thus the enums would have to follow the iOS numbers
changed the title [-]Some enums have different values between x64 and arm64 on macOS[/-][+]Some enums have different values between x64 and arm64 on macOS and Mac Catalyst[/+]on Jul 14, 2021
It's a breaking change to modify the values - and they differ between Xamarin.[iOS|tvOS|watchOS].dll and Xamarin.Mac.dll assemblies.
Xamarin.MacCatalyst.dll could be set to anything (not a breaking change yet) but it makes sense to keep it like Xamarin.iOS.dll. However the values needs to differ by architecture :-(
The values are also baked directly into (3rd parties) assemblies that refers to them... so that limit what we can do to fix this.
Proposal
I suggest adding extension methods, on all affected enum types, that gives the correct value. They can be optimized/removed later (e.g. by the linker) so they won't represent a large runtime cost.
The generator will also need to be aware of those types, i.e. to use the extension methods, not the enum values, e.g.
We already have some code to convert values for these enums, because they're [Native] enums. We could augment that code so that we can do something like this:
We'd have a managed enum that would define the values for managed code, and then we convert to the corresponding value whenever we enter/exit native code (exactly like we already do for the existing [Native] support).
The advantage would be that we'd not have to remember to use the extension functions, it would all be automatic (the only manual code would be the extension methods themselves).
It would likely be a bit more work to implement though.
Love it! The only downside is that [Native] already has some semantics wrt [u]int-[u]long and would not work for SslCipherSuite enum (or similar cases). Hopefully the list is complete and this is not something that should happen anymore...
Activity
akoeplinger commentedon Jul 14, 2021
I assume this is a variation of #11498 ?
filipnavara commentedon Jul 14, 2021
It is a similar issue. The difference with
SSLCipherSuiteis that it's a deprecated API and thus not very performance sensitive. Some of the same constraints apply though:[-]Some enums have different values between x64 and arm64 on macOS[/-][+]Some enums have different values between x64 and arm64 on macOS and Mac Catalyst[/+]spouliot commentedon Jul 20, 2021
It's a breaking change to modify the values - and they differ between
Xamarin.[iOS|tvOS|watchOS].dllandXamarin.Mac.dllassemblies.Xamarin.MacCatalyst.dllcould be set to anything (not a breaking change yet) but it makes sense to keep it likeXamarin.iOS.dll. However the values needs to differ by architecture :-(The values are also baked directly into (3rd parties) assemblies that refers to them... so that limit what we can do to fix this.
Proposal
I suggest adding extension methods, on all affected enum types, that gives the correct value. They can be optimized/removed later (e.g. by the linker) so they won't represent a large runtime cost.
The generator will also need to be aware of those types, i.e. to use the extension methods, not the enum values, e.g.
Also manual p/invokes will need to use the (public) extensions methods to work properly. That will need to be documented.
Adding a new analyzer could also help in spotting incorrect usage inside user projects.
rolfbjarne commentedon Jul 20, 2021
I have a slightly different proposal :)
Proposal #2
We already have some code to convert values for these enums, because they're [Native] enums. We could augment that code so that we can do something like this:
We'd have a managed enum that would define the values for managed code, and then we convert to the corresponding value whenever we enter/exit native code (exactly like we already do for the existing [Native] support).
The advantage would be that we'd not have to remember to use the extension functions, it would all be automatic (the only manual code would be the extension methods themselves).
It would likely be a bit more work to implement though.
spouliot commentedon Jul 20, 2021
Love it! The only downside is that
[Native]already has some semantics wrt[u]int-[u]longand would not work forSslCipherSuiteenum (or similar cases). Hopefully the list is complete and this is not something that should happen anymore...[src] Augment the Native attribute to support custom conversion funct…
[src] Augment the Native attribute to support custom conversion funct…