@@ -51,10 +51,7 @@ public PyLong(PyObject o)
5151 public PyLong ( int value )
5252 {
5353 obj = Runtime . PyLong_FromLong ( value ) ;
54- if ( obj == IntPtr . Zero )
55- {
56- throw new PythonException ( ) ;
57- }
54+ Runtime . CheckExceptionOccurred ( ) ;
5855 }
5956
6057
@@ -68,10 +65,7 @@ public PyLong(int value)
6865 public PyLong ( uint value )
6966 {
7067 obj = Runtime . PyLong_FromLong ( value ) ;
71- if ( obj == IntPtr . Zero )
72- {
73- throw new PythonException ( ) ;
74- }
68+ Runtime . CheckExceptionOccurred ( ) ;
7569 }
7670
7771
@@ -84,10 +78,7 @@ public PyLong(uint value)
8478 public PyLong ( long value )
8579 {
8680 obj = Runtime . PyLong_FromLongLong ( value ) ;
87- if ( obj == IntPtr . Zero )
88- {
89- throw new PythonException ( ) ;
90- }
81+ Runtime . CheckExceptionOccurred ( ) ;
9182 }
9283
9384
@@ -101,10 +92,7 @@ public PyLong(long value)
10192 public PyLong ( ulong value )
10293 {
10394 obj = Runtime . PyLong_FromUnsignedLongLong ( value ) ;
104- if ( obj == IntPtr . Zero )
105- {
106- throw new PythonException ( ) ;
107- }
95+ Runtime . CheckExceptionOccurred ( ) ;
10896 }
10997
11098
@@ -117,10 +105,7 @@ public PyLong(ulong value)
117105 public PyLong ( short value )
118106 {
119107 obj = Runtime . PyLong_FromLong ( value ) ;
120- if ( obj == IntPtr . Zero )
121- {
122- throw new PythonException ( ) ;
123- }
108+ Runtime . CheckExceptionOccurred ( ) ;
124109 }
125110
126111
@@ -134,10 +119,7 @@ public PyLong(short value)
134119 public PyLong ( ushort value )
135120 {
136121 obj = Runtime . PyLong_FromLong ( value ) ;
137- if ( obj == IntPtr . Zero )
138- {
139- throw new PythonException ( ) ;
140- }
122+ Runtime . CheckExceptionOccurred ( ) ;
141123 }
142124
143125
@@ -150,10 +132,7 @@ public PyLong(ushort value)
150132 public PyLong ( byte value )
151133 {
152134 obj = Runtime . PyLong_FromLong ( value ) ;
153- if ( obj == IntPtr . Zero )
154- {
155- throw new PythonException ( ) ;
156- }
135+ Runtime . CheckExceptionOccurred ( ) ;
157136 }
158137
159138
@@ -167,10 +146,7 @@ public PyLong(byte value)
167146 public PyLong ( sbyte value )
168147 {
169148 obj = Runtime . PyLong_FromLong ( value ) ;
170- if ( obj == IntPtr . Zero )
171- {
172- throw new PythonException ( ) ;
173- }
149+ Runtime . CheckExceptionOccurred ( ) ;
174150 }
175151
176152
@@ -183,10 +159,7 @@ public PyLong(sbyte value)
183159 public PyLong ( double value )
184160 {
185161 obj = Runtime . PyLong_FromDouble ( value ) ;
186- if ( obj == IntPtr . Zero )
187- {
188- throw new PythonException ( ) ;
189- }
162+ Runtime . CheckExceptionOccurred ( ) ;
190163 }
191164
192165
@@ -199,10 +172,7 @@ public PyLong(double value)
199172 public PyLong ( string value )
200173 {
201174 obj = Runtime . PyLong_FromString ( value , IntPtr . Zero , 0 ) ;
202- if ( obj == IntPtr . Zero )
203- {
204- throw new PythonException ( ) ;
205- }
175+ Runtime . CheckExceptionOccurred ( ) ;
206176 }
207177
208178
@@ -229,10 +199,7 @@ public static bool IsLongType(PyObject value)
229199 public static PyLong AsLong ( PyObject value )
230200 {
231201 IntPtr op = Runtime . PyNumber_Long ( value . obj ) ;
232- if ( op == IntPtr . Zero )
233- {
234- throw new PythonException ( ) ;
235- }
202+ Runtime . CheckExceptionOccurred ( ) ;
236203 return new PyLong ( op ) ;
237204 }
238205
0 commit comments