We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent edafdf2 commit 78939c5Copy full SHA for 78939c5
2 files changed
src/runtime/CustomMarshaler.cs
@@ -42,7 +42,7 @@ public int GetNativeDataSize()
42
public class StrMarshaler : MarshalerBase
43
{
44
private static readonly MarshalerBase Instance = new StrMarshaler();
45
- private static readonly Encoding PyEncoding = Runtime.UCS == 2 ? Encoding.Unicode : Encoding.UTF32;
+ private static readonly Encoding PyEncoding = Runtime.PyEncoding;
46
47
public override IntPtr MarshalManagedToNative(object managedObj)
48
@@ -82,7 +82,7 @@ public static ICustomMarshaler GetInstance(string cookie)
82
public class StrArrayMarshaler : MarshalerBase
83
84
private static readonly MarshalerBase Instance = new StrArrayMarshaler();
85
86
87
88
src/runtime/runtime.cs
@@ -170,6 +170,11 @@ public class Runtime
170
internal static bool IsPython2;
171
internal static bool IsPython3;
172
173
+ /// <summary>
174
+ /// Encoding to use to convert Unicode to/from Managed to Native
175
+ /// </summary>
176
+ internal static readonly Encoding PyEncoding = UCS == 2 ? Encoding.Unicode : Encoding.UTF32;
177
+
178
/// <summary>
179
/// Initialize the runtime...
180
/// </summary>
@@ -1730,15 +1735,13 @@ internal static string GetManagedString(IntPtr op)
1730
1735
1731
1736
if (type == Runtime.PyUnicodeType)
1732
1737
1733
- Encoding encoding = UCS == 2 ? Encoding.Unicode : Encoding.UTF32;
1734
-
1738
IntPtr p = PyUnicode_AsUnicode(op);
1739
int length = PyUnicode_GetSize(op);
1740
1741
int size = length * UCS;
1742
var buffer = new byte[size];
1743
Marshal.Copy(p, buffer, 0, size);
- return encoding.GetString(buffer, 0, size);
1744
+ return PyEncoding.GetString(buffer, 0, size);
1745
}
1746
1747
return null;
0 commit comments