Added support for wchar_t and std::wstring for C##983
Added support for wchar_t and std::wstring for C##983zillemarco wants to merge 1 commit intomono:mainfrom
Conversation
| return encoding.GetString(buffer); | ||
| } | ||
|
|
||
| public static IntPtr StringToHGlobalMultiByteUni(string str) |
| // Deleting destructors (default in v-table) accept an i32 bitfield as a | ||
| // second parameter in MS ABI. | ||
| if (method != null && method.IsDestructor && Context.ParserOptions.IsMicrosoftAbi) | ||
| var @class = method != null ? method.Namespace as Class : null; |
There was a problem hiding this comment.
Needlessly complicated - if the method is not null, then its name-space is always a class, just cast it.
| var type = ctx.Parameter.Type.Desugar(); | ||
| ClassTemplateSpecialization basicString = GetBasicString(type); | ||
|
|
||
| if(basicString.Arguments[0].Type.Type.IsPrimitiveType(PrimitiveType.Char)) |
There was a problem hiding this comment.
A space after the conditional operator.
| // Struct added to help map a the wchar_t C++ type to C# | ||
| // The data is stored as a 64 bit value so it could represent | ||
| // an UTF-32 character but C# only represents UTF-16 characters | ||
| // so beware of possible data loss when using it. |
There was a problem hiding this comment.
Not sure what this means, is it that our binding for wstring does not always work properly?
There was a problem hiding this comment.
Just that C# char (UTF-16) type cannot represent the entirety of Unicode (UTF-32).
There was a problem hiding this comment.
We should then think about throwing an exception if out of range.
There was a problem hiding this comment.
I don't get this comment. wchar_t on Windows is represented as UTF16-LE. On Linux it's UTF-32. Char in C# is always UTF16-LE afaik. There is one more type to consider: char16_t is always UTF16-LE, regardless of the platform that's being used. (Since C++17). C++20 will also define UTF8 type char8_t.
d0c8e15 to
5ca9345
Compare
4dfd9cc to
e53b253
Compare
0464938 to
637018f
Compare
91e219c to
32da859
Compare
a0169c2 to
3ea7e97
Compare
|
Has this been abandoned? Seems like it would be a nice improvement! |
|
Frankly I have to really apologize for leaving this behind. I had other priorities at work so I couldn't give it the final push it needed. I think I could be able to get back at this in my free time since not far from now I'll also need this at work. |
|
I don't recall anymore either, but think it was pretty much good to go. Please rebase it on top of latest master, make sure all tests still pass and lets take it from there. |
With the help of @tritao: - added support for wchar_t - added support for std::wstring - unified the way wide character strings are handled between C# and C++/CLI - changed the way strings are handled, using 'IntPtr' instead of 'string' with marshalling attributes on the P/Invokes
|
It's not compiling anymore: Guess some code moved around or was renamed, and needs to be updated in this PR. |
|
Yeah I know, during the rebase I had quite a bit of conflicts. I was thinking about drafting the PR until I get it back to work. |
c930b78 to
c38556a
Compare
4c1e9b8 to
2fdd082
Compare
bcf41e4 to
851ec5e
Compare
8f64166 to
12f456e
Compare
With the help of @tritao:
C++/CLI
with marshalling attributes on the P/Invokes