| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -45,7 +45,10 @@ public PyAnsiString(PyObject o) | |||
| 45 | 45 | public PyAnsiString(string s) | |
| 46 | 46 | { | |
| 47 | 47 | obj = Runtime.PyString_FromString(s); | |
| 48 | - Runtime.CheckExceptionOccurred(); | ||
| 48 | + if (obj == IntPtr.Zero) | ||
| 49 | + { | ||
| 50 | + throw new PythonException(); | ||
| 51 | + } | ||
| 49 | 52 | } | |
| 50 | 53 | ||
| 51 | 54 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -51,7 +51,10 @@ public PyFloat(PyObject o) | |||
| 51 | 51 | public PyFloat(double value) | |
| 52 | 52 | { | |
| 53 | 53 | obj = Runtime.PyFloat_FromDouble(value); | |
| 54 | - Runtime.CheckExceptionOccurred(); | ||
| 54 | + if (obj == IntPtr.Zero) | ||
| 55 | + { | ||
| 56 | + throw new PythonException(); | ||
| 57 | + } | ||
| 55 | 58 | } | |
| 56 | 59 | ||
| 57 | 60 | ||
@@ -66,7 +69,10 @@ public PyFloat(string value) | |||
| 66 | 69 | using (var s = new PyString(value)) | |
| 67 | 70 | { | |
| 68 | 71 | obj = Runtime.PyFloat_FromString(s.obj, IntPtr.Zero); | |
| 69 | - Runtime.CheckExceptionOccurred(); | ||
| 72 | + if (obj == IntPtr.Zero) | ||
| 73 | + { | ||
| 74 | + throw new PythonException(); | ||
| 75 | + } | ||
| 70 | 76 | } | |
| 71 | 77 | } | |
| 72 | 78 | ||
@@ -94,7 +100,10 @@ public static bool IsFloatType(PyObject value) | |||
| 94 | 100 | public static PyFloat AsFloat(PyObject value) | |
| 95 | 101 | { | |
| 96 | 102 | IntPtr op = Runtime.PyNumber_Float(value.obj); | |
| 97 | - Runtime.CheckExceptionOccurred(); | ||
| 103 | + if (op == IntPtr.Zero) | ||
| 104 | + { | ||
| 105 | + throw new PythonException(); | ||
| 106 | + } | ||
| 98 | 107 | return new PyFloat(op); | |
| 99 | 108 | } | |
| 100 | 109 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -51,7 +51,10 @@ public PyInt(PyObject o) | |||
| 51 | 51 | public PyInt(int value) | |
| 52 | 52 | { | |
| 53 | 53 | obj = Runtime.PyInt_FromInt32(value); | |
| 54 | - Runtime.CheckExceptionOccurred(); | ||
| 54 | + if (obj == IntPtr.Zero) | ||
| 55 | + { | ||
| 56 | + throw new PythonException(); | ||
| 57 | + } | ||
| 55 | 58 | } | |
| 56 | 59 | ||
| 57 | 60 | ||
@@ -78,7 +81,10 @@ public PyInt(uint value) : base(IntPtr.Zero) | |||
| 78 | 81 | public PyInt(long value) : base(IntPtr.Zero) | |
| 79 | 82 | { | |
| 80 | 83 | obj = Runtime.PyInt_FromInt64(value); | |
| 81 | - Runtime.CheckExceptionOccurred(); | ||
| 84 | + if (obj == IntPtr.Zero) | ||
| 85 | + { | ||
| 86 | + throw new PythonException(); | ||
| 87 | + } | ||
| 82 | 88 | } | |
| 83 | 89 | ||
| 84 | 90 | ||
@@ -92,7 +98,10 @@ public PyInt(long value) : base(IntPtr.Zero) | |||
| 92 | 98 | public PyInt(ulong value) : base(IntPtr.Zero) | |
| 93 | 99 | { | |
| 94 | 100 | obj = Runtime.PyInt_FromInt64((long)value); | |
| 95 | - Runtime.CheckExceptionOccurred(); | ||
| 101 | + if (obj == IntPtr.Zero) | ||
| 102 | + { | ||
| 103 | + throw new PythonException(); | ||
| 104 | + } | ||
| 96 | 105 | } | |
| 97 | 106 | ||
| 98 | 107 | ||
@@ -151,7 +160,10 @@ public PyInt(sbyte value) : this((int)value) | |||
| 151 | 160 | public PyInt(string value) | |
| 152 | 161 | { | |
| 153 | 162 | obj = Runtime.PyInt_FromString(value, IntPtr.Zero, 0); | |
| 154 | - Runtime.CheckExceptionOccurred(); | ||
| 163 | + if (obj == IntPtr.Zero) | ||
| 164 | + { | ||
| 165 | + throw new PythonException(); | ||
| 166 | + } | ||
| 155 | 167 | } | |
| 156 | 168 | ||
| 157 | 169 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -51,7 +51,10 @@ public PyTuple(PyObject o) | |||
| 51 | 51 | public PyTuple() | |
| 52 | 52 | { | |
| 53 | 53 | obj = Runtime.PyTuple_New(0); | |
| 54 | - Runtime.CheckExceptionOccurred(); | ||
| 54 | + if (obj == IntPtr.Zero) | ||
| 55 | + { | ||
| 56 | + throw new PythonException(); | ||
| 57 | + } | ||
| 55 | 58 | } | |
| 56 | 59 | ||
| 57 | 60 | ||
@@ -68,12 +71,22 @@ public PyTuple(PyObject[] items) | |||
| 68 | 71 | { | |
| 69 | 72 | int count = items.Length; | |
| 70 | 73 | obj = Runtime.PyTuple_New(count); | |
| 71 | - for (var i = 0; i < count; i++) | ||
| 74 | + if (obj == IntPtr.Zero) | ||
| 75 | + { | ||
| 76 | + throw new PythonException(); | ||
| 77 | + } | ||
| 78 | + for (int i = 0; i < count; i++) | ||
| 72 | 79 | { | |
| 73 | 80 | IntPtr ptr = items[i].obj; | |
| 74 | 81 | Runtime.XIncref(ptr); | |
| 75 | - Runtime.PyTuple_SetItem(obj, i, ptr); | ||
| 76 | - Runtime.CheckExceptionOccurred(); | ||
| 82 | + if (Runtime.PyTuple_SetItem(obj, i, ptr) != 0) | ||
| 83 | + { | ||
| 84 | + for (int j = i; j >= 0; j--) | ||
| 85 | + { | ||
| 86 | + Runtime.XDecref(items[j].obj); | ||
| 87 | + } | ||
| 88 | + throw new PythonException(); | ||
| 89 | + } | ||
| 77 | 90 | } | |
| 78 | 91 | } | |
| 79 | 92 | ||
@@ -101,7 +114,10 @@ public static bool IsTupleType(PyObject value) | |||
| 101 | 114 | public static PyTuple AsTuple(PyObject value) | |
| 102 | 115 | { | |
| 103 | 116 | IntPtr op = Runtime.PySequence_Tuple(value.obj); | |
| 104 | - Runtime.CheckExceptionOccurred(); | ||
| 117 | + if (op == IntPtr.Zero) | ||
| 118 | + { | ||
| 119 | + throw new PythonException(); | ||
| 120 | + } | ||
| 105 | 121 | return new PyTuple(op); | |
| 106 | 122 | } | |
| 107 | 123 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments