@@ -82,8 +82,20 @@ public class Runtime
82
82
{
83
83
#if UCS4
84
84
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_" ;
85
91
#elif UCS2
86
92
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_" ;
87
99
#else
88
100
#error You must define either UCS2 or UCS4!
89
101
#endif
@@ -1231,8 +1243,8 @@ int size
1231
1243
[ DllImport ( PythonDll ) ]
1232
1244
internal static extern IntPtr PyString_FromStringAndSize ( string value , int size ) ;
1233
1245
1234
- [ DllImport ( PythonDll , EntryPoint = " PyString_AsString " ) ]
1235
- internal static extern IntPtr PyString_AS_STRING ( IntPtr op ) ;
1246
+ [ DllImport ( PythonDll ) ]
1247
+ internal static extern IntPtr PyString_AsString ( IntPtr op ) ;
1236
1248
1237
1249
[ DllImport( PythonDll ) ]
1238
1250
internal static extern int PyString_Size ( IntPtr pointer ) ;
@@ -1243,64 +1255,23 @@ internal static bool PyUnicode_Check(IntPtr ob)
1243
1255
return PyObject_TYPE( ob) == PyUnicodeType;
1244
1256
}
1245
1257
1246
- #if UCS2 && PYTHON3
1258
+ #if PYTHON3
1247
1259
[ DllImport ( PythonDll ) ]
1248
1260
internal static extern IntPtr PyUnicode_FromObject( IntPtr ob ) ;
1249
1261
1250
1262
[ DllImport( PythonDll ) ]
1251
1263
internal static extern IntPtr PyUnicode_FromEncodedObject( IntPtr ob , IntPtr enc , IntPtr err ) ;
1252
1264
1253
- [ DllImport ( PythonDll , EntryPoint = "PyUnicode_FromKindAndData ", CharSet = CharSet . Unicode ) ]
1254
- internal static extern IntPtr PyUnicode_FromKindAndString( int kind , string s , int size ) ;
1255
-
1256
- internal static IntPtr PyUnicode_FromUnicode( string s , int size )
1257
- {
1258
- return PyUnicode_FromKindAndString ( 2 , s , size ) ;
1259
- }
1260
-
1261
- [ DllImport ( PythonDll ) ]
1262
- internal static extern int PyUnicode_GetSize( IntPtr ob) ;
1263
-
1264
- [ DllImport( PythonDll) ]
1265
- internal static extern IntPtr PyUnicode_AsUnicode( IntPtr ob) ;
1266
<
A3D4
span class="diff-text-marker">-
1267
1265
[ DllImport ( PythonDll ) ]
1268
- internal static extern IntPtr PyUnicode_FromOrdinal( int c) ;
1269
- #elif UCS2 && PYTHON2
1270
- [ DllImport ( PythonDll , EntryPoint = "PyUnicodeUCS2_FromObject" ) ]
1271
- internal static extern IntPtr PyUnicode_FromObject( IntPtr ob ) ;
1272
-
1273
- [ DllImport( PythonDll , EntryPoint = "PyUnicodeUCS2_FromEncodedObject ") ]
1274
- internal static extern IntPtr PyUnicode_FromEncodedObject( IntPtr ob , IntPtr enc , IntPtr err ) ;
1275
-
1276
- [ DllImport ( PythonDll , EntryPoint = "PyUnicodeUCS2_FromUnicode ", CharSet = CharSet . Unicode ) ]
1277
- internal static extern IntPtr PyUnicode_FromUnicode( string s , int size ) ;
1278
-
1279
- [ DllImport ( PythonDll , EntryPoint = "PyUnicodeUCS2_GetSize ") ]
1280
- internal static extern int PyUnicode_GetSize ( IntPtr ob ) ;
1281
-
1282
- [ DllImport( PythonDll , EntryPoint = "PyUnicodeUCS2_AsUnicode ") ]
1283
- internal static extern IntPtr PyUnicode_AsUnicode( IntPtr ob ) ;
1284
-
1285
- [ DllImport( PythonDll , EntryPoint = "PyUnicodeUCS2_FromOrdinal ") ]
1286
- 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(
1266
+ internal static extern IntPtr PyUnicode_FromKindAndData (
1296
1267
int kind ,
1297
1268
[ MarshalAs ( UnmanagedType . CustomMarshaler , MarshalTypeRef = typeof ( StrMarshaler ) ) ] string s,
1298
1269
int size
1299
1270
) ;
1300
1271
1301
1272
internal static IntPtr PyUnicode_FromUnicode( string s , int size )
1302
1273
{
1303
- return PyUnicode_FromKindAndString ( 4 , s , size ) ;
1274
+ return PyUnicode_FromKindAndData ( UCS , s , size ) ;
1304
1275
}
1305
1276
1306
1277
[ DllImport ( PythonDll ) ]
@@ -1311,26 +1282,26 @@ internal static IntPtr PyUnicode_FromUnicode(string s, int size)
1311
1282
1312
1283
[ DllImport( PythonDll) ]
1313
1284
internal static extern IntPtr PyUnicode_FromOrdinal( int c) ;
1314
- #elif UCS4 && PYTHON2
1315
- [ DllImport ( PythonDll , EntryPoint = "PyUnicodeUCS4_FromObject ") ]
1285
+ #elif PYTHON2
1286
+ [ DllImport ( PythonDll , EntryPoint = PyUnicodeEntryPoint + "FromObject ") ]
1316
1287
internal static extern IntPtr PyUnicode_FromObject( IntPtr ob ) ;
1317
1288
1318
- [ DllImport( PythonDll , EntryPoint = " PyUnicodeUCS4_FromEncodedObject ") ]
1289
+ [ DllImport( PythonDll , EntryPoint = PyUnicodeEntryPoint + " FromEncodedObject ") ]
1319
1290
internal static extern IntPtr PyUnicode_FromEncodedObject( IntPtr ob , IntPtr enc , IntPtr err ) ;
1320
1291
1321
- [ DllImport ( PythonDll , EntryPoint = " PyUnicodeUCS4_FromUnicode ") ]
1292
+ [ DllImport ( PythonDll , EntryPoint = PyUnicodeEntryPoint + " FromUnicode ") ]
1322
1293
internal static extern IntPtr PyUnicode_FromUnicode(
1323
1294
[ MarshalAs ( UnmanagedType . CustomMarshaler , MarshalTypeRef = typeof ( StrMarshaler ) ) ] string s ,
1324
1295
int size
1325
1296
) ;
1326
1297
1327
- [ DllImport ( PythonDll , EntryPoint = " PyUnicodeUCS4_GetSize ") ]
1298
+ [ DllImport ( PythonDll , EntryPoint = PyUnicodeEntryPoint + " GetSize ") ]
1328
1299
internal static extern int PyUnicode_GetSize ( IntPtr ob) ;
1329
1300
1330
- [ DllImport ( PythonDll , EntryPoint = " PyUnicodeUCS4_AsUnicode ") ]
1301
+ [ DllImport ( PythonDll , EntryPoint = PyUnicodeEntryPoint + " AsUnicode ") ]
1331
1302
internal static extern IntPtr PyUnicode_AsUnicode( IntPtr ob) ;
1332
1303
1333
- [ DllImport ( PythonDll , EntryPoint = " PyUnicodeUCS4_FromOrdinal ") ]
1304
+ [ DllImport ( PythonDll , EntryPoint = PyUnicodeEntryPoint + " FromOrdinal ") ]
1334
1305
internal static extern IntPtr PyUnicode_FromOrdinal( int c ) ;
1335
1306
#endif
1336
1307
@@ -1359,7 +1330,7 @@ internal static string GetManagedString(IntPtr op)
1359
1330
#if PYTHON2 // Python 3 strings are all Unicode
1360
1331
if ( type = = PyStringType )
1361
1332
{
1362
- return Marshal . PtrToStringAnsi ( PyString_AS_STRING ( op ) , PyString_Size ( op ) ) ;
1333
+ return Marshal . PtrToStringAnsi ( PyString_AsString ( op ) , PyString_Size ( op ) ) ;
1363
1334
}
1364
1335
#endif
1365
1336
0 commit comments