Skip to content
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

[runtime] Allow IntPtr for native objects in the dynamic registrar. Fixes #15708 #15712

Merged
merged 5 commits into from
Aug 23, 2022

Conversation

spouliot
Copy link
Contributor

Allow code like this

[DllImport(Constants.ObjectiveCLibrary, EntryPoint = "objc_msgSendSuper")
static extern IntPtr IntPtr_objc_msgSendSuper(IntPtr receiver, IntPtr selector);

[DllImport(Constants.ObjectiveCLibrary, EntryPoint = "objc_msgSendSuper")]
static extern void void_objc_msgSendSuper(IntPtr receiver, IntPtr selector, IntPtr arg);

[Export("selectedTextRange")]
public new IntPtr SelectedTextRange
{
    get { return IntPtr_objc_msgSendSuper(SuperHandle, Selector.GetHandle("selectedTextRange")); }
    set => void_objc_msgSendSuper(SuperHandle, Selector.GetHandle("setSelectedTextRange:"), value);
}

to work on the dynamic registrar since it already work with the static one.
This allows the simulators (which defaults to dynamic) to share the same code which is useful for implementing a workaround for related issue #15677.

…ixes xamarin#15708

Allow code like this

```csharp
[DllImport(Constants.ObjectiveCLibrary, EntryPoint = "objc_msgSendSuper")
static extern IntPtr IntPtr_objc_msgSendSuper(IntPtr receiver, IntPtr selector);

[DllImport(Constants.ObjectiveCLibrary, EntryPoint = "objc_msgSendSuper")]
static extern void void_objc_msgSendSuper(IntPtr receiver, IntPtr selector, IntPtr arg);

[Export("selectedTextRange")]
public new IntPtr SelectedTextRange
{
    get { return IntPtr_objc_msgSendSuper(SuperHandle, Selector.GetHandle("selectedTextRange")); }
    set => void_objc_msgSendSuper(SuperHandle, Selector.GetHandle("setSelectedTextRange:"), value);
}
```

to work on the dynamic registrar since it already work with the static one.
This allows the simulators (which defaults to dynamic) to share the same code which is useful for implementing a workaround for related issue xamarin#15677.
@dalexsoto
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@dalexsoto dalexsoto added the community Community contribution ❤ label Aug 19, 2022
if (!strcmp (fullname, "System.IntPtr")) {
returnValue = *(void **) mono_object_unbox (retval);
} else {
xamarin_assertion_message ("Don't know how to marshal a return value of type '%s.%s'. Please file a bug with a test case at https://github.com/xamarin/xamarin-macios/issues/new\n", mono_class_get_namespace (r_klass), mono_class_get_name (r_klass));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you have the fullname, why not change the assertion message to:
xamarin_assertion_message ("Don't know how to marshal a return value of type '%s', Please Please file a bug with a test case at https://github.com/xamarin/xamarin-macios/issues/new\n", full name);

On a side note, I wonder if this won't be immediately stale with the .NET 6 transition to NativeHandle instead of IntPtr.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both good points @stephen-hawley I'll address them shortly. Thanks!

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@dalexsoto
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

spouliot added a commit to spouliot/uno that referenced this pull request Aug 20, 2022
…ashes

Pro: It does not break app compatibility, selection works

Con: This does not work _currently_ with the dynamic registrar [1] which is the default when building for iOS simulators. OTOH there's a workaround for that [2].

[1] Unless building with the iOS SDK for Xcode 14 (currently only previews) once xamarin/xamarin-macios#15712 is merged

[2] Adding `--registrar=static` to the simulator builds will fix this, sadly build times will be longer (so better use [1] asap)
#if DOTNET
if (!strcmp (fullname, "System.IntPtr") || !strcmp (fullname, "ObjCRuntime.NativeHandle")) {
#else
if (!strcmp (fullname, "System.IntPtr")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two functions that are much faster and simpler: xamarin_is_class_intptr and xamarin_is_class_nativehandle, no need to compute a full type name nor compare strings.

@@ -201,7 +201,17 @@
}
}
} else {
xamarin_assertion_message ("Don't know how to marshal a return value of type '%s.%s'. Please file a bug with a test case at https://github.com/xamarin/xamarin-macios/issues/new\n", mono_class_get_namespace (r_klass), mono_class_get_name (r_klass));
char *fullname = xamarin_class_get_full_name (r_klass, exception_gchandle);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

last little bit - since fullname is only used in the error and @rolfbjarne implies that it's more costly than the xamarin_is_class_ tests, how about moving the allocation and deallocation into the else clause so that the price only gets paid in the failing case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reverted the assertion to the original code as it did not need (extra) allocation, inside the caller, and still produced the same output.

@dalexsoto
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@vs-mobiletools-engineering-service2

This comment has been minimized.

@dalexsoto
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ API diff for current PR / commit

Legacy Xamarin (No breaking changes)
  • iOS (no change detected)
  • tvOS (no change detected)
  • watchOS (no change detected)
  • macOS (no change detected)
NET (empty diffs)
  • iOS: (empty diff detected)
  • tvOS: (empty diff detected)
  • MacCatalyst: (empty diff detected)
  • macOS: (empty diff detected)

❗ API diff vs stable (Breaking changes)

Legacy Xamarin (:heavy_exclamation_mark: Breaking changes :heavy_exclamation_mark:)
  • iOS: vsdrops gist (:heavy_exclamation_mark: Breaking changes :heavy_exclamation_mark:)
  • tvOS: vsdrops gist (:heavy_exclamation_mark: Breaking changes :heavy_exclamation_mark:)
  • watchOS: vsdrops gist (:heavy_exclamation_mark: Breaking changes :heavy_exclamation_mark:)
  • macOS: vsdrops gist (:heavy_exclamation_mark: Breaking changes :heavy_exclamation_mark:)
.NET (:heavy_exclamation_mark: Breaking changes :heavy_exclamation_mark:)
  • iOS: vsdrops gist (:heavy_exclamation_mark: Breaking changes :heavy_exclamation_mark:)
  • tvOS: vsdrops gist (:heavy_exclamation_mark: Breaking changes :heavy_exclamation_mark:)
  • MacCatalyst: vsdrops gist (:heavy_exclamation_mark: Breaking changes :heavy_exclamation_mark:)
  • macOS: vsdrops gist (:heavy_exclamation_mark: Breaking changes :heavy_exclamation_mark:)
  • Microsoft.iOS vs Microsoft.MacCatalyst: vsdrops gist
Legacy Xamarin (stable) vs .NET

✅ Generator diff

Generator diff is empty

Pipeline on Agent
Hash: 14b4d7d2b3ee8f3b6fc66f15935567c74ea9bb48 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [PR Build] Tests on macOS Mac Catalina (10.15) passed 💻

All tests on macOS Mac Catalina (10.15) passed.

Pipeline on Agent
Hash: 14b4d7d2b3ee8f3b6fc66f15935567c74ea9bb48 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

📚 [PR Build] Artifacts 📚

Packages generated

View packages

Pipeline on Agent XAMBOT-1174.Monterey'
Hash: 14b4d7d2b3ee8f3b6fc66f15935567c74ea9bb48 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

❌ [PR Build] Tests on macOS M1 - Mac Big Sur (11.5) failed ❌

Failed tests are:

  • dontlink
  • introspection
  • xammac_tests
  • monotouch-test

Pipeline on Agent
Hash: 14b4d7d2b3ee8f3b6fc66f15935567c74ea9bb48 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

🔥 [CI Build] Test results 🔥

Test results

❌ Tests failed on VSTS: simulator tests

0 tests crashed, 7 tests failed, 221 tests passed.

Failures

❌ introspection tests

1 tests failed, 12 tests passed.
  • introspection/watchOS 32-bits - simulator/Debug (watchOS 6.0): Crashed Known issue: HE0038)

Html Report (VSDrops) Download

❌ mononative tests

2 tests failed, 10 tests passed.
  • mono-native-compat/watchOS 32-bits - simulator/Debug: TimedOut
  • mono-native-unified/watchOS 32-bits - simulator/Debug: TimedOut

Html Report (VSDrops) Download

❌ monotouch tests

4 tests failed, 19 tests passed.
  • monotouch-test/watchOS 32-bits - simulator/Debug: TimedOut
  • monotouch-test/watchOS 32-bits - simulator/Debug (LinkSdk): TimedOut
  • monotouch-test/watchOS 32-bits - simulator/Debug (static registrar): HarnessException (Harness exception for 'monotouch-test': System.InvalidOperationException: The Writer is closed or in error state.
    at System.Xml.XmlWellFormedWriter.AdvanceState (System.Xml.XmlWellFormedWriter+Token token) [0x001f6] in /Users/builder/jenkins/workspace/build-package-osx-mono/2020-02/external/bockbuild/builds/mono-x64/mcs/class/referencesource/System.Xml/System/Xml/Core/XmlWellFormedWriter.cs:1712
    at System.Xml.XmlWellFormedWriter.WriteCData (System.String text) [0x00029] in /Users/builder/jenkins/workspace/build-package-osx-mono/2020-02/external/bockbuild/builds/mono-x64/mcs/class/referencesource/System.Xml/System/Xml/Core/XmlWellFormedWriter.cs:771
    at Microsoft.DotNet.XHarness.iOS.Shared.Utilities.Extensions.WriteCDataSafe (System.Xml.XmlWriter writer, System.String text) [0x0001b] in //src/Microsoft.DotNet.XHarness.iOS.Shared/Utilities/Extensions.cs:130
    at Microsoft.DotNet.XHarness.iOS.Shared.XmlResults.TestReportGenerator.WriteFailure (System.Xml.XmlWriter writer, System.String message, System.IO.TextReader stderr) [0x00031] in /
    /src/Microsoft.DotNet.XHarness.iOS.Shared/XmlResults/TestReportGenerator.cs:43
    at Microsoft.DotNet.XHarness.iOS.Shared.XmlResults.NUnitV3TestReportGenerator.GenerateFailure (System.Xml.XmlWriter writer, System.String title, System.String message, System.IO.TextReader stderr) [0x0030e] in //src/Microsoft.DotNet.XHarness.iOS.Shared/XmlResults/NUnitV3TestReportGenerator.cs:124
    at Microsoft.DotNet.XHarness.iOS.Shared.XmlResults.XmlResultParser.GenerateFailureXml (System.String destination, System.String title, System.String message, System.IO.TextReader stderrReader, Microsoft.DotNet.XHarness.Common.XmlResultJargon jargon) [0x00033] in /
    /src/Microsoft.DotNet.XHarness.iOS.Shared/XmlResults/XmlResultParser.cs:226
    at Microsoft.DotNet.XHarness.iOS.Shared.XmlResults.XmlResultParser.GenerateFailure (Microsoft.DotNet.XHarness.iOS.Shared.Logging.ILogs logs, System.String source, System.String appName, System.String variation, System.String title, System.String message, System.IO.TextReader stderrReader, Microsoft.DotNet.XHarness.Common.XmlResultJargon jargon) [0x000a4] in //src/Microsoft.DotNet.XHarness.iOS.Shared/XmlResults/XmlResultParser.cs:248
    at Microsoft.DotNet.XHarness.iOS.Shared.XmlResults.XmlResultParser.GenerateFailure (Microsoft.DotNet.XHarness.iOS.Shared.Logging.ILogs logs, System.String source, System.String appName, System.String variation, System.String title, System.String message, System.String stderrPath, Microsoft.DotNet.XHarness.Common.XmlResultJargon jargon) [0x00008] in /
    /src/Microsoft.DotNet.XHarness.iOS.Shared/XmlResults/XmlResultParser.cs:236
    at Microsoft.DotNet.XHarness.iOS.Shared.TestReporter.GenerateXmlFailures (System.String failure, System.Boolean crashed, System.String crashReason) [0x00247] in //src/Microsoft.DotNet.XHarness.iOS.Shared/TestReporter.cs:575
    at Microsoft.DotNet.XHarness.iOS.Shared.TestReporter.ParseResult () [0x0056f] in /
    /src/Microsoft.DotNet.XHarness.iOS.Shared/TestReporter.cs:713
    at Xharness.AppRunner.RunAsync () [0x01b78] in /Users/builder/azdo/_work/2/s/xamarin-macios/tests/xharness/AppRunner.cs:453
    at Xharness.Jenkins.TestTasks.RunSimulator.RunTestAsync () [0x002b1] in /Users/builder/azdo/_work/2/s/xamarin-macios/tests/xharness/Jenkins/TestTasks/RunSimulator.cs:128
    at Xharness.Jenkins.TestTasks.RunTest.ExecuteAsync () [0x001b9] in /Users/builder/azdo/_work/2/s/xamarin-macios/tests/xharness/Jenkins/TestTasks/RunTest.cs:113
    at Xharness.Jenkins.TestTasks.TestTasks.RunInternalAsync () [0x00226] in /Users/builder/azdo/_work/2/s/xamarin-macios/tests/xharness/Jenkins/TestTasks/TestTask.cs:269 )
  • monotouch-test/watchOS 32-bits - simulator/Release (all optimizations): TimedOut

Html Report (VSDrops) Download

Successes

✅ bcl: All 69 tests passed. Html Report (VSDrops) Download
✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests: All 1 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 7 tests passed. Html Report (VSDrops) Download
✅ framework: All 8 tests passed. Html Report (VSDrops) Download
✅ generator: All 2 tests passed. Html Report (VSDrops) Download
✅ interdependent_binding_projects: All 7 tests passed. Html Report (VSDrops) Download
✅ install_source: All 1 tests passed. Html Report (VSDrops) Download
✅ linker: All 65 tests passed. Html Report (VSDrops) Download
✅ mac_binding_project: All 1 tests passed. Html Report (VSDrops) Download
✅ mmp: All 2 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ mtouch: All 1 tests passed. Html Report (VSDrops) Download
✅ xammac: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 8 tests passed. Html Report (VSDrops) Download
✅ xtro: All 2 tests passed. Html Report (VSDrops) Download

Pipeline on Agent
Hash: [PR build]

@rolfbjarne
Copy link
Member

@rolfbjarne rolfbjarne merged commit a331034 into xamarin:xcode14 Aug 23, 2022
@spouliot spouliot deleted the gh15708 branch August 23, 2022 13:20
jeromelaban pushed a commit to unoplatform/uno that referenced this pull request Aug 25, 2022
…ashes

Pro: It does not break app compatibility, selection works

Con: This does not work _currently_ with the dynamic registrar [1] which is the default when building for iOS simulators. OTOH there's a workaround for that [2].

[1] Unless building with the iOS SDK for Xcode 14 (currently only previews) once xamarin/xamarin-macios#15712 is merged

[2] Adding `--registrar=static` to the simulator builds will fix this, sadly build times will be longer (so better use [1] asap)
jeromelaban pushed a commit to unoplatform/uno that referenced this pull request Aug 25, 2022
…ashes

Pro: It does not break app compatibility, selection works

Con: This does not work _currently_ with the dynamic registrar [1] which is the default when building for iOS simulators. OTOH there's a workaround for that [2].

[1] Unless building with the iOS SDK for Xcode 14 (currently only previews) once xamarin/xamarin-macios#15712 is merged

[2] Adding `--registrar=static` to the simulator builds will fix this, sadly build times will be longer (so better use [1] asap)
jeromelaban pushed a commit to unoplatform/uno that referenced this pull request Aug 26, 2022
…ashes

Pro: It does not break app compatibility, selection works

Con: This does not work _currently_ with the dynamic registrar [1] which is the default when building for iOS simulators. OTOH there's a workaround for that [2].

[1] Unless building with the iOS SDK for Xcode 14 (currently only previews) once xamarin/xamarin-macios#15712 is merged

[2] Adding `--registrar=static` to the simulator builds will fix this, sadly build times will be longer (so better use [1] asap)
jeromelaban pushed a commit to unoplatform/uno that referenced this pull request Aug 30, 2022
…ashes

Pro: It does not break app compatibility, selection works

Con: This does not work _currently_ with the dynamic registrar [1] which is the default when building for iOS simulators. OTOH there's a workaround for that [2].

[1] Unless building with the iOS SDK for Xcode 14 (currently only previews) once xamarin/xamarin-macios#15712 is merged

[2] Adding `--registrar=static` to the simulator builds will fix this, sadly build times will be longer (so better use [1] asap)
jeromelaban pushed a commit to unoplatform/uno that referenced this pull request Aug 30, 2022
…ashes

Pro: It does not break app compatibility, selection works

Con: This does not work _currently_ with the dynamic registrar [1] which is the default when building for iOS simulators. OTOH there's a workaround for that [2].

[1] Unless building with the iOS SDK for Xcode 14 (currently only previews) once xamarin/xamarin-macios#15712 is merged

[2] Adding `--registrar=static` to the simulator builds will fix this, sadly build times will be longer (so better use [1] asap)
jeromelaban pushed a commit to unoplatform/uno that referenced this pull request Aug 31, 2022
…ashes

Pro: It does not break app compatibility, selection works

Con: This does not work _currently_ with the dynamic registrar [1] which is the default when building for iOS simulators. OTOH there's a workaround for that [2].

[1] Unless building with the iOS SDK for Xcode 14 (currently only previews) once xamarin/xamarin-macios#15712 is merged

[2] Adding `--registrar=static` to the simulator builds will fix this, sadly build times will be longer (so better use [1] asap)
jeromelaban pushed a commit to unoplatform/uno that referenced this pull request Aug 31, 2022
…ashes

Pro: It does not break app compatibility, selection works

Con: This does not work _currently_ with the dynamic registrar [1] which is the default when building for iOS simulators. OTOH there's a workaround for that [2].

[1] Unless building with the iOS SDK for Xcode 14 (currently only previews) once xamarin/xamarin-macios#15712 is merged

[2] Adding `--registrar=static` to the simulator builds will fix this, sadly build times will be longer (so better use [1] asap)
jeromelaban pushed a commit to unoplatform/uno that referenced this pull request Sep 6, 2022
…ashes

Pro: It does not break app compatibility, selection works

Con: This does not work _currently_ with the dynamic registrar [1] which is the default when building for iOS simulators. OTOH there's a workaround for that [2].

[1] Unless building with the iOS SDK for Xcode 14 (currently only previews) once xamarin/xamarin-macios#15712 is merged

[2] Adding `--registrar=static` to the simulator builds will fix this, sadly build times will be longer (so better use [1] asap)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Community contribution ❤
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants