-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Return iOS version in Environment.OSVersion on Mac Catalyst #50990
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Implement OperatingSystem.IsMacCatalyst and OperatingSystem.IsMacCatalystVersionAtLeast.
|
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
src/libraries/Common/src/Interop/OSX/System.Native/Interop.iOSVersion.cs
Show resolved
Hide resolved
|
|
||
| const char* SystemNative_iOSSupportVersion() | ||
| { | ||
| @autoreleasepool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need an autoreleasepool here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not necessarily sure whether it's needed or not but LLVM code has it there (https://github.com/llvm/llvm-project/blob/62ec4ac90738a5f2d209ed28c822223e58aaaeb7/lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm#L83-L90).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I saw that, I was mostly wondering because we have some custom code in pal_autoreleasepool.m that does thread initialization stuff used by ThreadPool code in managed and I don't know if we need that here too:
runtime/src/libraries/Native/Unix/System.Native/pal_autoreleasepool.m
Lines 18 to 35 in 5b683e2
| void* SystemNative_CreateAutoreleasePool(void) | |
| { | |
| if (![NSThread isMultiThreaded]) | |
| { | |
| // Start another no-op thread with the NSThread APIs to get NSThread into multithreaded mode. | |
| // The NSAutoReleasePool APIs can't be used on secondary threads until NSThread is in multithreaded mode. | |
| // See https://developer.apple.com/documentation/foundation/nsautoreleasepool for more information. | |
| PlaceholderObject* placeholderObject = [[PlaceholderObject alloc] init]; | |
| // We need to use detachNewThreadSelector to put NSThread into multithreaded mode. | |
| // We can't use detachNewThreadWithBlock since it doesn't change NSThread into multithreaded mode for some reason. | |
| // See https://developer.apple.com/documentation/foundation/nswillbecomemultithreadednotification for more information. | |
| [NSThread detachNewThreadSelector:@selector(noop:) toTarget:placeholderObject withObject:nil]; | |
| } | |
| assert([NSThread isMultiThreaded]); | |
| return [[NSAutoreleasePool alloc] init]; | |
| } |
@rolfbjarne do you know the implications?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I'm no expert on that but the documentation really suggests that it may be necessary... 🤷🏻♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fine [1] if the new API are called from user+managed code.
If the dotnet runtime(s) calls (independently or before xamarin's runtime completed it's initialization) SystemNative_iOSSupportVersion then SystemNative_CreateAutoreleasePool should be called first (or to create the instance).
[1] if not it means we need to fix it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll modify it to call SystemNative_CreateAutoreleasePool instead of @autoreleasepool which should be safe. The code should not depend on Xamarin runtime being used/initialized (even if in most cases it will be).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Apple documentation says that using NSAutoreleasePool manually would trip the ARC analyzer so I just extracted the code into helper method and kept using @autoreleasepool.
22bfbb5 to
40b91bc
Compare
0ab51c0 to
911d385
Compare
akoeplinger
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Implement OperatingSystem.IsMacCatalyst and OperatingSystem.IsMacCatalystVersionAtLeast
Fixes #47768