| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -51,10 +51,7 @@ public PyTuple(PyObject o) | |||
| 51 | 51 | public PyTuple() | |
| 52 | 52 | { | |
| 53 | 53 | obj = Runtime.PyTuple_New(0); | |
| 54 | - if (obj == IntPtr.Zero) | ||
| 55 | - { | ||
| 56 | - throw new PythonException(); | ||
| 57 | - } | ||
| 54 | + Runtime.CheckExceptionOccurred(); | ||
| 58 | 55 | } | |
| 59 | 56 | ||
| 60 | 57 | ||
@@ -63,6 +60,9 @@ public PyTuple() | |||
| 63 | 60 | /// </summary> | |
| 64 | 61 | /// <remarks> | |
| 65 | 62 | /// Creates a new PyTuple from an array of PyObject instances. | |
| 63 | + /// <para /> | ||
| 64 | + /// See caveats about PyTuple_SetItem: | ||
| 65 | + /// https://www.coursehero.com/file/p4j2ogg/important-exceptions-to-this-rule-PyTupleSetItem-and-PyListSetItem-These/ | ||
| 66 | 66 | /// </remarks> | |
| 67 | 67 | public PyTuple(PyObject[] items) | |
| 68 | 68 | { | |
@@ -72,11 +72,8 @@ public PyTuple(PyObject[] items) | |||
| 72 | 72 | { | |
| 73 | 73 | IntPtr ptr = items[i].obj; | |
| 74 | 74 | Runtime.XIncref(ptr); | |
| 75 | - int r = Runtime.PyTuple_SetItem(obj, i, ptr); | ||
| 76 | - if (r < 0) | ||
| 77 | - { | ||
| 78 | - throw new PythonException(); | ||
| 79 | - } | ||
| 75 | + Runtime.PyTuple_SetItem(obj, i, ptr); | ||
| 76 | + Runtime.CheckExceptionOccurred(); | ||
| 80 | 77 | } | |
| 81 | 78 | } | |
| 82 | 79 | ||
@@ -104,10 +101,7 @@ public static bool IsTupleType(PyObject value) | |||
| 104 | 101 | public static PyTuple AsTuple(PyObject value) | |
| 105 | 102 | { | |
| 106 | 103 | IntPtr op = Runtime.PySequence_Tuple(value.obj); | |
| 107 | - if (op == IntPtr.Zero) | ||
| 108 | - { | ||
| 109 | - throw new PythonException(); | ||
| 110 | - } | ||
| 104 | + Runtime.CheckExceptionOccurred(); | ||
| 111 | 105 | return new PyTuple(op); | |
| 112 | 106 | } | |
| 113 | 107 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -384,6 +384,21 @@ internal static int AtExit() | |||
| 384 | 384 | internal static IntPtr PyNone; | |
| 385 | 385 | internal static IntPtr Error; | |
| 386 | 386 | ||
| 387 | + /// <summary> | ||
| 388 | + /// Check if any Python Exceptions occurred. | ||
| 389 | + /// If any exist throw new PythonException. | ||
| 390 | + /// </summary> | ||
| 391 | + /// <remarks> | ||
| 392 | + /// Can be used instead of `obj == IntPtr.Zero` for example. | ||
| 393 | + /// </remarks> | ||
| 394 | + internal static void CheckExceptionOccurred() | ||
| 395 | + { | ||
| 396 | + if (PyErr_Occurred() != 0) | ||
| 397 | + { | ||
| 398 | + throw new PythonException(); | ||
| 399 | + } | ||
| 400 | + } | ||
| 401 | + | ||
| 387 | 402 | internal static IntPtr GetBoundArgTuple(IntPtr obj, IntPtr args) | |
| 388 | 403 | { | |
| 389 | 404 | if (Runtime.PyObject_TYPE(args) != Runtime.PyTupleType) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments