Skip to content

Commit 1e60113

Browse files
committed
Fix naming for function pointers with strings
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent f97ad43 commit 1e60113

File tree

4 files changed

+6
-2
lines changed

4 files changed

+6
-2
lines changed

src/Generator/Passes/DelegatesPass.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,9 @@ private static StringBuilder FormatTypesStringForIdentifier(StringBuilder types)
276276
// TODO: all of this needs proper general fixing by only leaving type names
277277
return types.Replace("global::System.", string.Empty)
278278
.Replace("[MarshalAs(UnmanagedType.LPUTF8Str)] ", string.Empty)
279-
.Replace("[MarshalAs(UnmanagedType.LPWStr)] ", string.Empty)
279+
.Replace("[MarshalAs(UnmanagedType.LPWStr)] string", "wstring")
280+
.Replace("[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(CppSharp.Runtime.UTF8Marshaller))] string", "string8")
281+
.Replace("[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(CppSharp.Runtime.UTF32Marshaller))] string", "string32")
280282
.Replace("global::", string.Empty).Replace("*", "Ptr")
281283
.Replace('.', '_').Replace(' ', '_').Replace("::", "_")
282284
.Replace("[]", "Array");

src/Generator/Types/Std/Stdlib.CSharp.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public override Type CSharpSignatureType(TypePrinterContext ctx)
103103
// This is not really right. ASCII is 7-bit only - the 8th bit is stripped; ANSI has
104104
// multi-byte support via a code page. MarshalAs(UnmanagedType.LPStr) marshals as ANSI.
105105
// Perhaps we need a CppSharp.Runtime.ASCIIMarshaller?
106-
return new CustomType("[MarshalAs(UnmanagedType.LPStr)] string");
106+
return new CustomType("[MarshalAs(UnmanagedType.LPStr)] string");
107107
else if (encoding == Encoding.UTF8)
108108
return new CustomType("[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(CppSharp.Runtime.UTF8Marshaller))] string");
109109
else if (encoding == Encoding.Unicode || encoding == Encoding.BigEndianUnicode)

tests/CSharp/CSharp.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,6 +1489,7 @@ void TestChar32String::UpdateString(const char32_t* s)
14891489
}
14901490

14911491
const char32_t* TestChar32String::RetrieveString() { return thirtyTwoBitConst; }
1492+
void TestChar32String::functionPointerUTF32(void(*ptr)(const char32_t*)) {}
14921493

14931494
TestChar16String::TestChar16String() :
14941495
sixteenBitConst(u"ქართული ენა")

tests/CSharp/CSharp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,7 @@ class DLL_API TestChar32String
11651165

11661166
void UpdateString(const char32_t* s);
11671167
const char32_t* RetrieveString();
1168+
void functionPointerUTF32(void(*ptr)(const char32_t*));
11681169
};
11691170

11701171
class DLL_API TestChar16String

0 commit comments

Comments
 (0)