-
Notifications
You must be signed in to change notification settings - Fork 519
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
[registrar] Improve naming of generated P/Invoke wrappers. #15480
Conversation
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)
💻 [PR Build] Tests on macOS Mac Catalina (10.15) passed 💻✅ All tests on macOS Mac Catalina (10.15) passed. Pipeline on Agent |
✅ API diff for current PR / commitLegacy Xamarin (No breaking changes)
NET (empty diffs)
✅ API diff vs stableLegacy Xamarin (No breaking changes).NET (No breaking changes)✅ Generator diffGenerator diff is empty Pipeline on Agent |
❌ [PR Build] Tests on macOS M1 - Mac Big Sur (11.5) failed ❌Failed tests are:
Pipeline on Agent |
@@ -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 ('|', '_'); |
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 wish we had:
str.ReplaceAll(new [] {'a', 'b'}, '_');
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.
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;
}
});
This comment was marked as outdated.
This comment was marked as outdated.
🔥 [CI Build] Test results 🔥Test results❌ Tests failed on VSTS: simulator tests 0 tests crashed, 3 tests failed, 220 tests passed. Failures❌ xcframework tests
Html Report (VSDrops) Download Successes✅ bcl: All 69 tests passed. Html Report (VSDrops) Download Pipeline on Agent |
Test failures are unrelated (dotnet/xharness#922). |
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: