File tree 1 file changed +6
-28
lines changed 1 file changed +6
-28
lines changed Original file line number Diff line number Diff line change @@ -1193,26 +1193,11 @@ internal static bool PyString_Check(IntPtr ob)
1193
1193
1194
1194
internal static IntPtr PyString_FromString( string value)
1195
1195
{
1196
- if ( value == null )
1197
- {
1198
- return IntPtr. Zero;
1199
- }
1200
-
1201
- byte [ ] bStr = Encoding. UTF8. GetBytes( value) ;
1202
- IntPtr mem = Marshal. AllocHGlobal( bStr. Length) ;
1203
- try
1204
- {
1205
- Marshal. Copy( bStr, 0 , mem, bStr. Length) ;
1206
- }
1207
- catch ( Exception)
1208
- {
1209
- Marshal. FreeHGlobal( mem) ;
1210
- throw ;
1211
- }
1212
-
1213
- IntPtr result = PyString_FromStringAndSize( mem, bStr. Length) ;
1214
- Marshal. FreeHGlobal( mem) ;
1215
- return result;
1196
+ #if PYTHON3
1197
+ return PyUnicode_FromKindAndData( _UCS, value, value. Length) ;
1198
+ #elif PYTHON2
1199
+ return PyString_FromStringAndSize( value, value. Length) ;
1200
+ #endif
1216
1201
}
1217
1202
1218
1203
#if PYTHON3
@@ -1226,14 +1211,7 @@ internal static IntPtr PyBytes_AS_STRING(IntPtr ob)
1226
1211
{
1227
1212
return ob + BytesOffset. ob_sval;
1228
1213
}
1229
-
1230
- [ DllImport( _PythonDll, CallingConvention = CallingConvention. Cdecl,
1231
- EntryPoint = "PyUnicode_FromStringAndSize") ]
1232
- internal static extern IntPtr PyString_FromStringAndSize(
1233
- IntPtr value,
1234
- int size
1235
- ) ;
1236
-
1214
+
1237
1215
[ DllImport( _PythonDll, CallingConvention = CallingConvention. Cdecl) ]
1238
1216
internal static extern IntPtr PyUnicode_FromStringAndSize( IntPtr value, int size) ;
1239
1217
#elif PYTHON2
You can’t perform that action at this time.
0 commit comments