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

Skip to content

Commit 6e9fed9

Browse files
committed
Unify PY3 UCS2/UCS4 unicode methods
CustomMarshal implementation deals w UCS2/4 differences
1 parent c7b4c21 commit 6e9fed9

File tree

1 file changed

+8
-31
lines changed

1 file changed

+8
-31
lines changed

src/runtime/runtime.cs

+8-31
Original file line numberDiff line numberDiff line change
@@ -1243,19 +1243,23 @@ internal static bool PyUnicode_Check(IntPtr ob)
12431243
return PyObject_TYPE(ob) == PyUnicodeType;
12441244
}
12451245

1246-
#if UCS2 && PYTHON3
1246+
#if PYTHON3
12471247
[DllImport(PythonDll)]
12481248
internal static extern IntPtr PyUnicode_FromObject(IntPtr ob);
12491249

12501250
[DllImport(PythonDll)]
12511251
internal static extern IntPtr PyUnicode_FromEncodedObject(IntPtr ob, IntPtr enc, IntPtr err);
12521252

1253-
[DllImport(PythonDll, EntryPoint = "PyUnicode_FromKindAndData", CharSet = CharSet.Unicode)]
1254-
internal static extern IntPtr PyUnicode_FromKindAndString(int kind, string s, int size);
1253+
[DllImport(PythonDll, EntryPoint = "PyUnicode_FromKindAndData")]
1254+
internal static extern IntPtr PyUnicode_FromKindAndString(
1255+
int kind,
1256+
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(StrMarshaler))] string s,
1257+
int size
1258+
);
12551259

12561260
internal static IntPtr PyUnicode_FromUnicode(string s, int size)
12571261
{
1258-
return PyUnicode_FromKindAndString(2, s, size);
1262+
return PyUnicode_FromKindAndString(UCS, s, size);
12591263
}
12601264

12611265
[DllImport(PythonDll)]
@@ -1284,33 +1288,6 @@ internal static IntPtr PyUnicode_FromUnicode(string s, int size)
12841288

12851289
[DllImport(PythonDll, EntryPoint = "PyUnicodeUCS2_FromOrdinal")]
12861290
internal static extern IntPtr PyUnicode_FromOrdinal(int c);
1287-
#elif UCS4 && PYTHON3
1288-
[DllImport(PythonDll)]
1289-
internal static extern IntPtr PyUnicode_FromObject(IntPtr ob);
1290-
1291-
[DllImport(PythonDll)]
1292-
internal static extern IntPtr PyUnicode_FromEncodedObject(IntPtr ob, IntPtr enc, IntPtr err);
1293-
1294-
[DllImport(PythonDll, EntryPoint = "PyUnicode_FromKindAndData")]
1295-
internal static extern IntPtr PyUnicode_FromKindAndString(
1296-
int kind,
1297-
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(StrMarshaler))] string s,
1298-
int size
1299-
);
1300-
1301-
internal static IntPtr PyUnicode_FromUnicode(string s, int size)
1302-
{
1303-
return PyUnicode_FromKindAndString(4, s, size);
1304-
}
1305-
1306-
[DllImport(PythonDll)]
1307-
internal static extern int PyUnicode_GetSize(IntPtr ob);
1308-
1309-
[DllImport(PythonDll)]
1310-
internal static extern IntPtr PyUnicode_AsUnicode(IntPtr ob);
1311-
1312-
[DllImport(PythonDll)]
1313-
internal static extern IntPtr PyUnicode_FromOrdinal(int c);
13141291
#elif UCS4 && PYTHON2
13151292
[DllImport(PythonDll, EntryPoint = "PyUnicodeUCS4_FromObject")]
13161293
internal static extern IntPtr PyUnicode_FromObject(IntPtr ob);

0 commit comments

Comments
 (0)