File tree Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -1193,7 +1193,26 @@ internal static bool PyString_Check(IntPtr ob)
1193
1193
1194
1194
internal static IntPtr PyString_FromString( string value)
1195
1195
{
1196
- return PyString_FromStringAndSize( value, value. Length) ;
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;
1197
1216
}
1198
1217
1199
1218
#if PYTHON3
@@ -1211,7 +1230,7 @@ internal static IntPtr PyBytes_AS_STRING(IntPtr ob)
1211
1230
[ DllImport( _PythonDll, CallingConvention = CallingConvention. Cdecl,
1212
1231
EntryPoint = "PyUnicode_FromStringAndSize") ]
1213
1232
internal static extern IntPtr PyString_FromStringAndSize(
1214
- [ MarshalAs ( UnmanagedType . CustomMarshaler , MarshalTypeRef = typeof ( Utf8Marshaler ) ) ] string value,
1233
+ IntPtr value,
1215
1234
int size
1216
1235
) ;
1217
1236
You can’t perform that action at this time.
0 commit comments