-
-
Notifications
You must be signed in to change notification settings - Fork 419
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
Fix behavior of SilkMarshal.StringToPtr and related methods on Linux #2377
Conversation
a597187
to
f5de3bc
Compare
f5de3bc
to
af1f79d
Compare
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.
Just a few comments, looks great!
I changed the code to use Encoding.UTF32 for both converting to a pointer and from a pointer. The test cases pass, but I'm still wondering if this is correct (see my reply to your review comment). I also don't test for any edge cases. I'm considering about including some of those. |
Will merge following #2376 |
Hold on. I want to do a bit more research and make sure the behavior here is correct. |
Interesting. It looks like on Windows, LPWStr is UTF-16 as expected. However, on Linux, LPWStr is UTF-32. For example, the memory for 🧵:
I checked this by inspecting the memory of The codepoint for 🧵 is Ignoring byte order, everything matches up. This means that it is indeed correct to use UTF32 on non-Windows platforms. |
This is because LPStr doesn't always support non-ascii characters.
Okay, never mind. That technically is expected behavior since that case is testing LPStr (which is 8 bits, but not necessarily UTF-8) and non-ascii characters are not guaranteed to be supported. |
Summary of the PR
This fixes #2374 by checking for whether the platform is Windows and using 2-byte LPWStrs if it is Windows and 4-byte LPWStrs if it is not.
Related issues, Discord discussions, or proposals
#2374
Further Comments
This pull request includes the changes made in #2376.
In that pull request, I added a test project (Silk.NET.Core.Tests) which is used here to test the changes I made.