| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d1044c3 commit 5f56ebc
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,7 +25,7 @@ dotnet_sort_system_directives_first = true | |||
| 25 | 25 | dotnet_separate_import_directive_groups = true | |
| 26 | 26 | ||
| 27 | 27 | [*.cs] | |
| 28 | - csharp_new_line_before_open_brace = true | ||
| 28 | + csharp_new_line_before_open_brace = all | ||
| 29 | 29 | csharp_new_line_before_else = true | |
| 30 | 30 | csharp_new_line_before_catch = true | |
| 31 | 31 | csharp_new_line_before_finally = true | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -38,6 +38,7 @@ public ExtensionType() | |||
| 38 | 38 | ||
| 39 | 39 | Runtime.PyObject_GC_UnTrack(py); | |
| 40 | 40 | ||
| 41 | + // Steals a ref to tpHandle. | ||
| 41 | 42 | tpHandle = tp; | |
| 42 | 43 | pyHandle = py; | |
| 43 | 44 | gcHandle = gc; | |
@@ -50,7 +51,7 @@ public ExtensionType() | |||
| 50 | 51 | public static void FinalizeObject(ManagedType self) | |
| 51 | 52 | { | |
| 52 | 53 | Runtime.PyObject_GC_Del(self.pyHandle); | |
| 53 | - Runtime.XDecref(self.tpHandle); | ||
| 54 | + // Not necessary for decref of `tpHandle`. | ||
| 54 | 55 | self.gcHandle.Free(); | |
| 55 | 56 | } | |
| 56 | 57 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -266,6 +266,7 @@ private static IntPtr DoInstanceCheck(IntPtr tp, IntPtr args, bool checkType) | |||
| 266 | 266 | return Runtime.PyFalse; | |
| 267 | 267 | } | |
| 268 | 268 | ||
| 269 | + Runtime.XIncref(args); | ||
| 269 | 270 | using (var argsObj = new PyList(args)) | |
| 270 | 271 | { | |
| 271 | 272 | if (argsObj.Length() != 1) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,5 @@ | |||
| 1 | 1 | using System; | |
| 2 | + using System.Runtime.CompilerServices; | ||
| 2 | 3 | ||
| 3 | 4 | namespace Python.Runtime | |
| 4 | 5 | { | |
@@ -190,5 +191,21 @@ public static bool Matches(IntPtr ob) | |||
| 190 | 191 | { | |
| 191 | 192 | return Runtime.PyErr_ExceptionMatches(ob) != 0; | |
| 192 | 193 | } | |
| 194 | + | ||
| 195 | + public static void ThrowIfIsNull(IntPtr ob) | ||
| 196 | + { | ||
| 197 | + if (ob == IntPtr.Zero) | ||
| 198 | + { | ||
| 199 | + throw new PythonException(); | ||
| 200 | + } | ||
| 201 | + } | ||
| 202 | + | ||
| 203 | + public static void ThrowIfIsNotZero(int value) | ||
| 204 | + { | ||
| 205 | + if (value != 0) | ||
| 206 | + { | ||
| 207 | + throw new PythonException(); | ||
| 208 | + } | ||
| 209 | + } | ||
| 193 | 210 | } | |
| 194 | 211 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1368,6 +1368,10 @@ internal static IntPtr PyUnicode_FromStringAndSize(IntPtr value, long size) | |||
| 1368 | 1368 | ||
| 1369 | 1369 | [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] | |
| 1370 | 1370 | private static extern IntPtr PyUnicode_FromStringAndSize(IntPtr value, IntPtr size); | |
| 1371 | + | ||
| 1372 | + [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] | ||
| 1373 | + internal static extern IntPtr PyUnicode_AsUTF8(IntPtr unicode); | ||
| 1374 | + | ||
| 1371 | 1375 | #elif PYTHON2 | |
| 1372 | 1376 | internal static IntPtr PyString_FromStringAndSize(string value, long size) | |
| 1373 | 1377 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -409,12 +409,8 @@ internal static IntPtr AllocateTypeObject(string name) | |||
| 409 | 409 | // the Python version of the type name - otherwise we'd have to | |
| 410 | 410 | // allocate the tp_name and would have no way to free it. | |
| 411 | 411 | #if PYTHON3 | |
| 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 | - IntPtr temp = Runtime.PyBytes_FromString(name); | ||
| 416 | - IntPtr raw = Runtime.PyBytes_AS_STRING(temp); | ||
| 417 | - temp = Runtime.PyUnicode_FromString(name); | ||
| 412 | + IntPtr temp = Runtime.PyUnicode_FromString(name); | ||
| 413 | + IntPtr raw = Runtime.PyUnicode_AsUTF8(temp); | ||
| 418 | 414 | #elif PYTHON2 | |
| 419 | 415 | IntPtr temp = Runtime.PyString_FromString(name); | |
| 420 | 416 | IntPtr raw = Runtime.PyString_AsString(temp); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments