Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ffe6448

Browse files
committed
Rename internal StrMarshaler to UcsMarshaler
To clarify that this is meant to be applied on Unicode type IntPtr and not strings like ones. Made Marshalers internal, don't see a reason to expose it.
1 parent 0cfc67a commit ffe6448

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

src/runtime/CustomMarshaler.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Python.Runtime
99
/// Abstract class defining boiler plate methods that
1010
/// Custom Marshalers will use.
1111
/// </summary>
12-
public abstract class MarshalerBase : ICustomMarshaler
12+
internal abstract class MarshalerBase : ICustomMarshaler
1313
{
1414
public object MarshalNativeToManaged(IntPtr pNativeData)
1515
{
@@ -39,9 +39,9 @@ public int GetNativeDataSize()
3939
/// Custom Marshaler to deal with Managed String to Native
4040
/// conversion differences on UCS2/UCS4.
4141
/// </summary>
42-
public class StrMarshaler : MarshalerBase
42+
internal class UcsMarshaler : MarshalerBase
4343
{
44-
private static readonly MarshalerBase Instance = new StrMarshaler();
44+
private static readonly MarshalerBase Instance = new UcsMarshaler();
4545
private static readonly Encoding PyEncoding = Runtime.PyEncoding;
4646

4747
public override IntPtr MarshalManagedToNative(object managedObj)
@@ -106,7 +106,7 @@ public static int GetUnicodeByteLength(IntPtr p)
106106
/// Custom Marshaler to deal with Managed String Arrays to Native
107107
/// conversion differences on UCS2/UCS4.
108108
/// </summary>
109-
public class StrArrayMarshaler : MarshalerBase
109+
internal class StrArrayMarshaler : MarshalerBase
110110
{
111111
private static readonly MarshalerBase Instance = new StrArrayMarshaler();
112112
private static readonly Encoding PyEncoding = Runtime.PyEncoding;
@@ -161,7 +161,7 @@ public static ICustomMarshaler GetInstance(string cookie)
161161
/// If instead we used `MarshalAs(UnmanagedType.LPWStr)` the output to
162162
/// `foo` would be `f\x00o\x00o\x00`.
163163
/// </remarks>
164-
public class Utf8Marshaler : MarshalerBase
164+
internal class Utf8Marshaler : MarshalerBase
165165
{
166166
private static readonly MarshalerBase Instance = new Utf8Marshaler();
167167
private static readonly Encoding PyEncoding = Encoding.UTF8;

src/runtime/pythonengine.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public static string ProgramName
5959
{
6060
IntPtr p = Runtime.Py_GetProgramName();
6161
string result = Runtime.IsPython3
62-
? StrMarshaler.PtrToStringUni(p)
62+
? UcsMarshaler.PtrToStringUni(p)
6363
: Marshal.PtrToStringAnsi(p);
6464

6565
return result ?? "";
@@ -73,7 +73,7 @@ public static string PythonHome
7373
{
7474
IntPtr p = Runtime.Py_GetPythonHome();
7575
string result = Runtime.IsPython3
76-
? StrMarshaler.PtrToStringUni(p)
76+
? UcsMarshaler.PtrToStringUni(p)
7777
: Marshal.PtrToStringAnsi(p);
7878

7979
return result ?? "";
@@ -87,7 +87,7 @@ public static string PythonPath
8787
{
8888
IntPtr p = Runtime.Py_GetPath();
8989
string result = Runtime.IsPython3
90-
? StrMarshaler.PtrToStringUni(p)
90+
? UcsMarshaler.PtrToStringUni(p)
9191
: Marshal.PtrToStringAnsi(p);
9292

9393
return result ?? "";

src/runtime/runtime.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,7 @@ internal static bool PyUnicode_Check(IntPtr ob)
12391239
[DllImport(PythonDll)]
12401240
internal static extern IntPtr PyUnicode_FromKindAndData(
12411241
int kind,
1242-
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(StrMarshaler))] string s,
1242+
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UcsMarshaler))] string s,
12431243
int size
12441244
);
12451245

@@ -1265,7 +1265,7 @@ internal static IntPtr PyUnicode_FromUnicode(string s, int size)
12651265

12661266
[DllImport(PythonDll, EntryPoint = PyUnicodeEntryPoint + "FromUnicode")]
12671267
internal static extern IntPtr PyUnicode_FromUnicode(
1268-
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(StrMarshaler))] string s,
1268+
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UcsMarshaler))] string s,
12691269
int size
12701270
);
12711271

0 commit comments

Comments
 (0)