File tree 2 files changed +8
-5
lines changed
2 files changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ public int GetNativeDataSize()
42
42
public class StrMarshaler : MarshalerBase
43
43
{
44
44
private static readonly MarshalerBase Instance = new StrMarshaler ( ) ;
45
- private static readonly Encoding PyEncoding = Runtime . UCS == 2 ? Encoding . Unicode : Encoding . UTF32 ;
45
+ private static readonly Encoding PyEncoding = Runtime . PyEncoding ;
46
46
47
47
public override IntPtr MarshalManagedToNative ( object managedObj )
48
48
{
@@ -82,7 +82,7 @@ public static ICustomMarshaler GetInstance(string cookie)
82
82
public class StrArrayMarshaler : MarshalerBase
83
83
{
84
84
private static readonly MarshalerBase Instance = new StrArrayMarshaler ( ) ;
85
- private static readonly Encoding PyEncoding = Runtime . UCS == 2 ? Encoding . Unicode : Encoding . UTF32 ;
85
+ private static readonly Encoding PyEncoding = Runtime . PyEncoding ;
86
86
87
87
public override IntPtr MarshalManagedToNative ( object managedObj )
88
88
{
Original file line number Diff line number Diff line change @@ -170,6 +170,11 @@ public class Runtime
170
170
internal static bool IsPython2 ;
171
171
internal static bool IsPython3 ;
172
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
+
173
178
/// <summary>
174
179
/// Initialize the runtime...
175
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
-
1735
1738
IntPtr p = PyUnicode_AsUnicode( op) ;
1736
1739
int length = PyUnicode_GetSize( op ) ;
1737
1740
1738
1741
int size = length * UCS;
1739
1742
var buffer = new byte [ size ] ;
1740
1743
Marshal . Copy ( p , buffer , 0 , size ) ;
1741
- return encoding . GetString ( buffer , 0 , size ) ;
1744
+ return PyEncoding . GetString ( buffer , 0 , size ) ;
1742
1745
}
1743
1746
1744
1747
return null ;
You can’t perform that action at this time.
0 commit comments