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

Skip to content

Commit 464080f

Browse files
committed
Unify PY2 UCS2/UCS4 unicode methods
PyUnicodeEntryPoint is not used for PY3 since it was unified by PEP393. It could be defined as "PyUnicode_" for PY3 and further unify the code between PY2/PY3. Not implementing since not all PY3 methods exist in PY2
1 parent 6e9fed9 commit 464080f

File tree

1 file changed

+19
-25
lines changed

1 file changed

+19
-25
lines changed

src/runtime/runtime.cs

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,20 @@ public class Runtime
8282
{
8383
#if UCS4
8484
public const int UCS = 4;
85+
86+
/// <summary>
87+
/// EntryPoint to be used in DllImport to map to correct Unicode
88+
/// methods prior to PEP393. Only used for PY27.
89+
/// </summary>
90+
private const string PyUnicodeEntryPoint = "PyUnicodeUCS4_";
8591
#elif UCS2
8692
public const int UCS = 2;
93+
94+
/// <summary>
95+
/// EntryPoint to be used in DllImport to map to correct Unicode
96+
/// methods prior to PEP393. Only used for PY27.
97+
/// </summary>
98+
private const string PyUnicodeEntryPoint = "PyUnicodeUCS2_";
8799
#else
88100
#error You must define either UCS2 or UCS4!
89101
#endif
@@ -1270,44 +1282,26 @@ internal static IntPtr PyUnicode_FromUnicode(string s, int size)
12701282

12711283
[DllImport(PythonDll)]
12721284
internal static extern IntPtr PyUnicode_FromOrdinal(int c);
1273-
#elif UCS2 && PYTHON2
1274-
[DllImport(PythonDll, EntryPoint = "PyUnicodeUCS2_FromObject")]
1275-
internal static extern IntPtr PyUnicode_FromObject(IntPtr ob);
1276-
1277-
[DllImport(PythonDll, EntryPoint = "PyUnicodeUCS2_FromEncodedObject")]
1278-
internal static extern IntPtr PyUnicode_FromEncodedObject(IntPtr ob, IntPtr enc, IntPtr err);
1279-
1280-
[DllImport(PythonDll, EntryPoint = "PyUnicodeUCS2_FromUnicode", CharSet = CharSet.Unicode)]
1281-
internal static extern IntPtr PyUnicode_FromUnicode(string s, int size);
1282-
1283-
[DllImport(PythonDll, EntryPoint = "PyUnicodeUCS2_GetSize")]
1284-
internal static extern int PyUnicode_GetSize(IntPtr ob);
1285-
1286-
[DllImport(PythonDll, EntryPoint = "PyUnicodeUCS2_AsUnicode")]
1287-
internal static extern IntPtr PyUnicode_AsUnicode(IntPtr ob);
1288-
1289-
[DllImport(PythonDll, EntryPoint = "PyUnicodeUCS2_FromOrdinal")]
1290-
internal static extern IntPtr PyUnicode_FromOrdinal(int c);
1291-
#elif UCS4 && PYTHON2
1292-
[DllImport(PythonDll, EntryPoint = "PyUnicodeUCS4_FromObject")]
1285+
#elif PYTHON2
1286+
[DllImport(PythonDll, EntryPoint = PyUnicodeEntryPoint + "FromObject")]
12931287
internal static extern IntPtr PyUnicode_FromObject(IntPtr ob);
12941288

1295-
[DllImport(PythonDll, EntryPoint = "PyUnicodeUCS4_FromEncodedObject")]
1289+
[DllImport(PythonDll, EntryPoint = PyUnicodeEntryPoint + "FromEncodedObject")]
12961290
internal static extern IntPtr PyUnicode_FromEncodedObject(IntPtr ob, IntPtr enc, IntPtr err);
12971291

1298-
[DllImport(PythonDll, EntryPoint = "PyUnicodeUCS4_FromUnicode")]
1292+
[DllImport(PythonDll, EntryPoint = PyUnicodeEntryPoint + "FromUnicode")]
12991293
internal static extern IntPtr PyUnicode_FromUnicode(
13001294
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(StrMarshaler))] string s,
13011295
int size
13021296
);
13031297

1304-
[DllImport(PythonDll, EntryPoint = "PyUnicodeUCS4_GetSize")]
1298+
[DllImport(PythonDll, EntryPoint = PyUnicodeEntryPoint + "GetSize")]
13051299
internal static extern int PyUnicode_GetSize(IntPtr ob);
13061300

1307-
[DllImport(PythonDll, EntryPoint = "PyUnicodeUCS4_AsUnicode")]
1301+
[DllImport(PythonDll, EntryPoint = PyUnicodeEntryPoint + "AsUnicode")]
13081302
internal static extern IntPtr PyUnicode_AsUnicode(IntPtr ob);
13091303

1310-
[DllImport(PythonDll, EntryPoint = "PyUnicodeUCS4_FromOrdinal")]
1304+
[DllImport(PythonDll, EntryPoint = PyUnicodeEntryPoint + "FromOrdinal")]
13111305
internal static extern IntPtr PyUnicode_FromOrdinal(int c);
13121306
#endif
13131307

0 commit comments

Comments
 (0)