We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see ourdocumentation.
There was an error while loading.Please reload this page.
1 parentd1044c3 commit5f56ebcCopy full SHA for 5f56ebc
.editorconfig
@@ -25,7 +25,7 @@ dotnet_sort_system_directives_first = true
25
dotnet_separate_import_directive_groups =true
26
27
[*.cs]
28
-csharp_new_line_before_open_brace =true
+csharp_new_line_before_open_brace =all
29
csharp_new_line_before_else =true
30
csharp_new_line_before_catch =true
31
csharp_new_line_before_finally =true
src/runtime/extensiontype.cs
@@ -38,6 +38,7 @@ public ExtensionType()
38
39
Runtime.PyObject_GC_UnTrack(py);
40
41
+// Steals a ref to tpHandle.
42
tpHandle=tp;
43
pyHandle=py;
44
gcHandle=gc;
@@ -50,7 +51,7 @@ public ExtensionType()
50
51
publicstaticvoidFinalizeObject(ManagedTypeself)
52
{
53
Runtime.PyObject_GC_Del(self.pyHandle);
-Runtime.XDecref(self.tpHandle);
54
+// Not necessary for decref of `tpHandle`.
55
self.gcHandle.Free();
56
}
57
src/runtime/metatype.cs
@@ -266,6 +266,7 @@ private static IntPtr DoInstanceCheck(IntPtr tp, IntPtr args, bool checkType)
266
returnRuntime.PyFalse;
267
268
269
+Runtime.XIncref(args);
270
using(varargsObj=newPyList(args))
271
272
if(argsObj.Length()!=1)
src/runtime/pythonexception.cs
@@ -1,4 +1,5 @@
1
usingSystem;
2
+usingSystem.Runtime.CompilerServices;
3
4
namespacePython.Runtime
5
@@ -190,5 +191,21 @@ public static bool Matches(IntPtr ob)
190
191
192
returnRuntime.PyErr_ExceptionMatches(ob)!=0;
193
194
+
195
+publicstaticvoidThrowIfIsNull(IntPtrob)
196
+{
197
+if(ob==IntPtr.Zero)
198
199
+thrownewPythonException();
200
+}
201
202
203
+publicstaticvoidThrowIfIsNotZero(intvalue)
204
205
+if(value!=0)
206
207
208
209
210
211
src/runtime/runtime.cs
@@ -1368,6 +1368,10 @@ internal static IntPtr PyUnicode_FromStringAndSize(IntPtr value, long size)
1368
1369
[DllImport(_PythonDll, CallingConvention= CallingConvention.Cdecl)]
1370
privatestaticextern IntPtr PyUnicode_FromStringAndSize(IntPtr value, IntPtr size);
1371
1372
+[DllImport(_PythonDll, CallingConvention= CallingConvention.Cdecl)]
1373
+ internalstaticextern IntPtr PyUnicode_AsUTF8(IntPtr unicode);
1374
1375
#elif PYTHON2
1376
internalstatic IntPtr PyString_FromStringAndSize(string value,long size)
1377
src/runtime/typemanager.cs
@@ -409,12 +409,8 @@ internal static IntPtr AllocateTypeObject(string name)
409
// the Python version of the type name - otherwise we'd have to
410
// allocate the tp_name and would have no way to free it.
411
#ifPYTHON3
412
-// For python3 we leak two objects. One for the ASCII representation
413
-// required for tp_name, and another for the Unicode representation
414
-// for ht_name.
415
-IntPtrtemp=Runtime.PyBytes_FromString(name);
416
-IntPtrraw=Runtime.PyBytes_AS_STRING(temp);
417
-temp=Runtime.PyUnicode_FromString(name);
+IntPtrtemp=Runtime.PyUnicode_FromString(name);
+IntPtrraw=Runtime.PyUnicode_AsUTF8(temp);
418
#elifPYTHON2
419
IntPtrtemp=Runtime.PyString_FromString(name);
420
IntPtrraw=Runtime.PyString_AsString(temp);