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

[registrar] Improve naming of generated P/Invoke wrappers. #15480

Merged

Conversation

rolfbjarne
Copy link
Member

C# method names generated by the C# compiler can have all sorts of invalid
characters, so just sanitize this a bit.

Fixes errors like these:

/Users/builder/azdo/_work/2/s/xamarin-macios/tests/dotnet/MySimpleApp/iOS/obj/Debug/net7.0-ios/iossimulator-x64/linker-cache/pinvokes.mm:23:70: error: use of undeclared identifier 'NSOperatingSystemVersion_objc_msgSend_stret'
        typedef struct trampoline_struct_ppp(*func_xamarin_pinvoke_wrapper_<NSOperatingSystemVersion_objc_msgSend_stret>g____PInvoke|6_0) (void * basePtr, void * selector);
                                                                            ^
/Users/builder/azdo/_work/2/s/xamarin-macios/tests/dotnet/MySimpleApp/iOS/obj/Debug/net7.0-ios/iossimulator-x64/linker-cache/pinvokes.mm:23:114: error: expected ')'
        typedef struct trampoline_struct_ppp(*func_xamarin_pinvoke_wrapper_<NSOperatingSystemVersion_objc_msgSend_stret>g____PInvoke|6_0) (void * basePtr, void * selector);
                                                                                                                        ^
/Users/builder/azdo/_work/2/s/xamarin-macios/tests/dotnet/MySimpleApp/iOS/obj/Debug/net7.0-ios/iossimulator-x64/linker-cache/pinvokes.mm:23:38: note: to match this '('
        typedef struct trampoline_struct_ppp(*func_xamarin_pinvoke_wrapper_<NSOperatingSystemVersion_objc_msgSend_stret>g____PInvoke|6_0) (void * basePtr, void * selector);
                                            ^
/Users/builder/azdo/_work/2/s/xamarin-macios/tests/dotnet/MySimpleApp/iOS/obj/Debug/net7.0-ios/iossimulator-x64/linker-cache/pinvokes.mm:25:27: error: use of undeclared identifier 'NSOperatingSystemVersion_objc_msgSend_stret'
        xamarin_pinvoke_wrapper_<NSOperatingSystemVersion_objc_msgSend_stret>g____PInvoke|6_0 (void * basePtr, void * selector)

Verified

This commit was signed with the committer’s verified signature.
alexanderbez Aleksandr Bezobchuk
C# method names generated by the C# compiler can have all sorts of invalid
characters, so just sanitize this a bit.

Fixes errors like these:

    /Users/builder/azdo/_work/2/s/xamarin-macios/tests/dotnet/MySimpleApp/iOS/obj/Debug/net7.0-ios/iossimulator-x64/linker-cache/pinvokes.mm:23:70: error: use of undeclared identifier 'NSOperatingSystemVersion_objc_msgSend_stret'
            typedef struct trampoline_struct_ppp(*func_xamarin_pinvoke_wrapper_<NSOperatingSystemVersion_objc_msgSend_stret>g____PInvoke|6_0) (void * basePtr, void * selector);
                                                                                ^
    /Users/builder/azdo/_work/2/s/xamarin-macios/tests/dotnet/MySimpleApp/iOS/obj/Debug/net7.0-ios/iossimulator-x64/linker-cache/pinvokes.mm:23:114: error: expected ')'
            typedef struct trampoline_struct_ppp(*func_xamarin_pinvoke_wrapper_<NSOperatingSystemVersion_objc_msgSend_stret>g____PInvoke|6_0) (void * basePtr, void * selector);
                                                                                                                            ^
    /Users/builder/azdo/_work/2/s/xamarin-macios/tests/dotnet/MySimpleApp/iOS/obj/Debug/net7.0-ios/iossimulator-x64/linker-cache/pinvokes.mm:23:38: note: to match this '('
            typedef struct trampoline_struct_ppp(*func_xamarin_pinvoke_wrapper_<NSOperatingSystemVersion_objc_msgSend_stret>g____PInvoke|6_0) (void * basePtr, void * selector);
                                                ^
    /Users/builder/azdo/_work/2/s/xamarin-macios/tests/dotnet/MySimpleApp/iOS/obj/Debug/net7.0-ios/iossimulator-x64/linker-cache/pinvokes.mm:25:27: error: use of undeclared identifier 'NSOperatingSystemVersion_objc_msgSend_stret'
            xamarin_pinvoke_wrapper_<NSOperatingSystemVersion_objc_msgSend_stret>g____PInvoke|6_0 (void * basePtr, void * selector)
@rolfbjarne rolfbjarne added the not-notes-worthy Ignore for release notes label Jul 13, 2022
@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: 6bf74d602413ebf227884f91831a0e1fc2bdeebf [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

📚 [PR Build] Artifacts 📚

Packages generated

View packages

Pipeline on Agent XAMBOT-1101.Monterey'
Hash: 6bf74d602413ebf227884f91831a0e1fc2bdeebf [PR build]

@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

Legacy Xamarin (No breaking changes)
.NET (No breaking changes)
Legacy Xamarin (stable) vs .NET

✅ Generator diff

Generator diff is empty

Pipeline on Agent
Hash: 6bf74d602413ebf227884f91831a0e1fc2bdeebf [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

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

Failed tests are:

  • xammac_tests
  • monotouch-test

Pipeline on Agent
Hash: 6bf74d602413ebf227884f91831a0e1fc2bdeebf [PR build]

@@ -4945,10 +4945,12 @@ string TryGeneratePInvokeWrapper (PInvokeWrapperGenerator state, MethodDefinitio

string wrapperName;
if (!signatures.TryGetValue (signature.ToString (), out wrapperName)) {
var name = "xamarin_pinvoke_wrapper_" + method.Name;
var methodName = method.Name.Replace ('<', '_').Replace ('>', '_').Replace ('|', '_');
Copy link
Member

Choose a reason for hiding this comment

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

I wish we had:

str.ReplaceAll(new [] {'a', 'b'}, '_');

Copy link
Contributor

Choose a reason for hiding this comment

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

You can likely use something like string.Create to replace those chars instead. Also avoids allocations :D

var originalName = method.Name;
var methodName = string.Create (originalName.Length, originalName, static (span, state) => {
    ReadOnlySpan<char> banned = stackalloc[] { '<', '>', '|' };
    for (int i < 0; i < state.Length; ++i) {
        var ch = state[i];
        span[i] = banned.Contains(ch) ? '_' : ch;
    }
});

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

🔥 [CI Build] Test results 🔥

Test results

❌ Tests failed on VSTS: simulator tests

0 tests crashed, 3 tests failed, 220 tests passed.

Failures

❌ xcframework tests

3 tests failed, 5 tests passed.
  • xcframework-test/tvOS - simulator/Debug [dotnet]: HarnessException (Harness exception for 'xcframework-test': System.AggregateException: One or more errors occurred. (A task was canceled.) ---> System.Threading.Tasks.TaskCanceledException: A task was canceled.
    --- End of inner exception stack trace ---
    at System.Threading.Tasks.Task.ThrowIfExceptional (System.Boolean includeTaskCanceledExceptions) [0x00013] in /Users/builder/jenkins/workspace/build-package-osx-mono/2020-02/external/bockbuild/builds/mono-x64/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2029
    at System.Threading.Tasks.Task1[TResult].GetResultCore (System.Boolean waitCompletionNotification) [0x0002b] in /Users/builder/jenkins/workspace/build-package-osx-mono/2020-02/external/bockbuild/builds/mono-x64/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Future.cs:496 at System.Threading.Tasks.Task1[TResult].get_Result () [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2020-02/external/bockbuild/builds/mono-x64/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Future.cs:466
    at Microsoft.DotNet.XHarness.iOS.Shared.TestReporter.get_TestExecutionStarted () [0x00000] in //src/Microsoft.DotNet.XHarness.iOS.Shared/TestReporter.cs:79
    at Microsoft.DotNet.XHarness.iOS.Shared.TestReporter.ParseResult () [0x002d9] in /
    /src/Microsoft.DotNet.XHarness.iOS.Shared/TestReporter.cs:639
    at Xharness.AppRunner.RunAsync () [0x01b78] in /Users/builder/azdo/_work/1/s/xamarin-macios/tests/xharness/AppRunner.cs:453
    at Xharness.Jenkins.TestTasks.RunSimulator.RunTestAsync () [0x002b1] in /Users/builder/azdo/_work/1/s/xamarin-macios/tests/xharness/Jenkins/TestTasks/RunSimulator.cs:128
    at Xharness.Jenkins.TestTasks.RunTest.ExecuteAsync () [0x001b9] in /Users/builder/azdo/_work/1/s/xamarin-macios/tests/xharness/Jenkins/TestTasks/RunTest.cs:113
    at Xharness.Jenkins.TestTasks.TestTasks.RunInternalAsync () [0x00226] in /Users/builder/azdo/_work/1/s/xamarin-macios/tests/xharness/Jenkins/TestTasks/TestTask.cs:269
    ---> (Inner Exception #0) System.Threading.Tasks.TaskCanceledException: A task was canceled.<---
    )
  • xcframework-test/tvOS - simulator/Debug: HarnessException (Harness exception for 'xcframework-test': System.AggregateException: One or more errors occurred. (A task was canceled.) ---> System.Threading.Tasks.TaskCanceledException: A task was canceled.
    --- End of inner exception stack trace ---
    at System.Threading.Tasks.Task.ThrowIfExceptional (System.Boolean includeTaskCanceledExceptions) [0x00013] in /Users/builder/jenkins/workspace/build-package-osx-mono/2020-02/external/bockbuild/builds/mono-x64/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2029
    at System.Threading.Tasks.Task1[TResult].GetResultCore (System.Boolean waitCompletionNotification) [0x0002b] in /Users/builder/jenkins/workspace/build-package-osx-mono/2020-02/external/bockbuild/builds/mono-x64/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Future.cs:496 at System.Threading.Tasks.Task1[TResult].get_Result () [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2020-02/external/bockbuild/builds/mono-x64/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Future.cs:466
    at Microsoft.DotNet.XHarness.iOS.Shared.TestReporter.get_TestExecutionStarted () [0x00000] in //src/Microsoft.DotNet.XHarness.iOS.Shared/TestReporter.cs:79
    at Microsoft.DotNet.XHarness.iOS.Shared.TestReporter.ParseResult () [0x002d9] in /
    /src/Microsoft.DotNet.XHarness.iOS.Shared/TestReporter.cs:639
    at Xharness.AppRunner.RunAsync () [0x01b78] in /Users/builder/azdo/_work/1/s/xamarin-macios/tests/xharness/AppRunner.cs:453
    at Xharness.Jenkins.TestTasks.RunSimulator.RunTestAsync () [0x002b1] in /Users/builder/azdo/_work/1/s/xamarin-macios/tests/xharness/Jenkins/TestTasks/RunSimulator.cs:128
    at Xharness.Jenkins.TestTasks.RunTest.ExecuteAsync () [0x001b9] in /Users/builder/azdo/_work/1/s/xamarin-macios/tests/xharness/Jenkins/TestTasks/RunTest.cs:113
    at Xharness.Jenkins.TestTasks.TestTasks.RunInternalAsync () [0x00226] in /Users/builder/azdo/_work/1/s/xamarin-macios/tests/xharness/Jenkins/TestTasks/TestTask.cs:269
    ---> (Inner Exception #0) System.Threading.Tasks.TaskCanceledException: A task was canceled.<---
    )
  • xcframework-test/watchOS 32-bits - simulator/Debug: 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
✅ introspection: All 8 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
✅ mononative: All 12 tests passed. Html Report (VSDrops) Download
✅ monotouch: All 23 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
✅ xtro: All 2 tests passed. Html Report (VSDrops) Download

Pipeline on Agent
Hash: [PR build]

@rolfbjarne
Copy link
Member Author

Test failures are unrelated (dotnet/xharness#922).

@rolfbjarne rolfbjarne merged commit e468e75 into dotnet:main Jul 14, 2022
@rolfbjarne rolfbjarne deleted the registrar-improve-pinvoke-wrapper-naming branch July 14, 2022 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
not-notes-worthy Ignore for release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants