-
Notifications
You must be signed in to change notification settings - Fork 518
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
Added support for wchar_t and std::wstring for C# #983
base: main
Are you sure you want to change the base?
Conversation
@@ -20,5 +20,15 @@ public static string MarshalEncodedString(IntPtr ptr, Encoding encoding) | |||
|
|||
return encoding.GetString(buffer); | |||
} | |||
|
|||
public static IntPtr StringToHGlobalMultiByteUni(string str) |
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.
This isn't used anywhere.
@@ -68,7 +68,11 @@ public override bool VisitFunctionDecl(Function function) | |||
|
|||
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what this means, is it that our binding for wstring does not always work properly?
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 that C# char (UTF-16) type cannot represent the entirety of Unicode (UTF-32).
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.
We should then think about throwing an exception if out of range.
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 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
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
97610ec
to
a2aeaed
Compare
With the help of @tritao:
C++/CLI
with marshalling attributes on the P/Invokes