File tree Expand file tree Collapse file tree 2 files changed +8
-5
lines changed
Expand file tree Collapse file tree 2 files changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ public int GetNativeDataSize()
4242 public class StrMarshaler : MarshalerBase
4343 {
4444 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 ;
4646
4747 public override IntPtr MarshalManagedToNative ( object managedObj )
4848 {
@@ -82,7 +82,7 @@ public static ICustomMarshaler GetInstance(string cookie)
8282 public class StrArrayMarshaler : MarshalerBase
8383 {
8484 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 ;
8686
8787 public override IntPtr MarshalManagedToNative ( object managedObj )
8888 {
Original file line number Diff line number Diff line change @@ -170,6 +170,11 @@ public class Runtime
170170 internal static bool IsPython2 ;
171171 internal static bool IsPython3 ;
172172
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+
173178 /// <summary>
174179 /// Initialize the runtime...
175180 /// </summary>
@@ -1730,15 +1735,13 @@ internal static string GetManagedString(IntPtr op)
17301735
17311736 if ( type = = Runtime . PyUnicodeType )
17321737 {
1733- Encoding encoding = UCS == 2 ? Encoding. Unicode : Encoding. UTF32;
1734-
17351738 IntPtr p = PyUnicode_AsUnicode( op) ;
17361739 int length = PyUnicode_GetSize( op ) ;
17371740
17381741 int size = length * UCS;
17391742 var buffer = new byte [ size ] ;
17401743 Marshal . Copy ( p , buffer , 0 , size ) ;
1741- return encoding . GetString ( buffer , 0 , size ) ;
1744+ return PyEncoding . GetString ( buffer , 0 , size ) ;
17421745 }
17431746
17441747 return null ;
You can’t perform that action at this time.
0 commit comments