Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jul 22, 2023. It is now read-only.
/pythonnetPublic archive
forked frompythonnet/pythonnet

Commit6e4cf9d

Browse files
committed
Refactor Exception checking on tested classes
1 parent977ee96 commit6e4cf9d

File tree

5 files changed

+22
-88
lines changed

5 files changed

+22
-88
lines changed

‎src/runtime/pyansistring.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ public PyAnsiString(PyObject o)
4545
publicPyAnsiString(strings)
4646
{
4747
obj=Runtime.PyString_FromString(s);
48-
if(obj==IntPtr.Zero)
49-
{
50-
thrownewPythonException();
51-
}
48+
Runtime.CheckExceptionOccurred();
5249
}
5350

5451

‎src/runtime/pyfloat.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,7 @@ public PyFloat(PyObject o)
5151
publicPyFloat(doublevalue)
5252
{
5353
obj=Runtime.PyFloat_FromDouble(value);
54-
if(obj==IntPtr.Zero)
55-
{
56-
thrownewPythonException();
57-
}
54+
Runtime.CheckExceptionOccurred();
5855
}
5956

6057

@@ -69,10 +66,7 @@ public PyFloat(string value)
6966
using(vars=newPyString(value))
7067
{
7168
obj=Runtime.PyFloat_FromString(s.obj,IntPtr.Zero);
72-
if(obj==IntPtr.Zero)
73-
{
74-
thrownewPythonException();
75-
}
69+
Runtime.CheckExceptionOccurred();
7670
}
7771
}
7872

@@ -100,10 +94,7 @@ public static bool IsFloatType(PyObject value)
10094
publicstaticPyFloatAsFloat(PyObjectvalue)
10195
{
10296
IntPtrop=Runtime.PyNumber_Float(value.obj);
103-
if(op==IntPtr.Zero)
104-
{
105-
thrownewPythonException();
106-
}
97+
Runtime.CheckExceptionOccurred();
10798
returnnewPyFloat(op);
10899
}
109100
}

‎src/runtime/pyint.cs

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,7 @@ public PyInt(PyObject o)
5151
publicPyInt(intvalue)
5252
{
5353
obj=Runtime.PyInt_FromInt32(value);
54-
if(obj==IntPtr.Zero)
55-
{
56-
thrownewPythonException();
57-
}
54+
Runtime.CheckExceptionOccurred();
5855
}
5956

6057

@@ -68,10 +65,7 @@ public PyInt(int value)
6865
publicPyInt(uintvalue):base(IntPtr.Zero)
6966
{
7067
obj=Runtime.PyInt_FromInt64(value);
71-
if(obj==IntPtr.Zero)
72-
{
73-
thrownewPythonException();
74-
}
68+
Runtime.CheckExceptionOccurred();
7569
}
7670

7771

@@ -84,10 +78,7 @@ public PyInt(uint value) : base(IntPtr.Zero)
8478
publicPyInt(longvalue):base(IntPtr.Zero)
8579
{
8680
obj=Runtime.PyInt_FromInt64(value);
87-
if(obj==IntPtr.Zero)
88-
{
89-
thrownewPythonException();
90-
}
81+
Runtime.CheckExceptionOccurred();
9182
}
9283

9384

@@ -101,10 +92,7 @@ public PyInt(long value) : base(IntPtr.Zero)
10192
publicPyInt(ulongvalue):base(IntPtr.Zero)
10293
{
10394
obj=Runtime.PyInt_FromInt64((long)value);
104-
if(obj==IntPtr.Zero)
105-
{
106-
thrownewPythonException();
107-
}
95+
Runtime.CheckExceptionOccurred();
10896
}
10997

11098

@@ -163,10 +151,7 @@ public PyInt(sbyte value) : this((int)value)
163151
publicPyInt(stringvalue)
164152
{
165153
obj=Runtime.PyInt_FromString(value,IntPtr.Zero,0);
166-
if(obj==IntPtr.Zero)
167-
{
168-
thrownewPythonException();
169-
}
154+
Runtime.CheckExceptionOccurred();
170155
}
171156

172157

@@ -193,10 +178,7 @@ public static bool IsIntType(PyObject value)
193178
publicstaticPyIntAsInt(PyObjectvalue)
194179
{
195180
IntPtrop=Runtime.PyNumber_Int(value.obj);
196-
if(op==IntPtr.Zero)
197-
{
198-
thrownewPythonException();
199-
}
181+
Runtime.CheckExceptionOccurred();
200182
returnnewPyInt(op);
201183
}
202184

‎src/runtime/pylong.cs

Lines changed: 11 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,7 @@ public PyLong(PyObject o)
5151
publicPyLong(intvalue)
5252
{
5353
obj=Runtime.PyLong_FromLong(value);
54-
if(obj==IntPtr.Zero)
55-
{
56-
thrownewPythonException();
57-
}
54+
Runtime.CheckExceptionOccurred();
5855
}
5956

6057

@@ -68,10 +65,7 @@ public PyLong(int value)
6865
publicPyLong(uintvalue)
6966
{
7067
obj=Runtime.PyLong_FromLong(value);
71-
if(obj==IntPtr.Zero)
72-
{
73-
thrownewPythonException();
74-
}
68+
Runtime.CheckExceptionOccurred();
7569
}
7670

7771

@@ -84,10 +78,7 @@ public PyLong(uint value)
8478
publicPyLong(longvalue)
8579
{
8680
obj=Runtime.PyLong_FromLongLong(value);
87-
if(obj==IntPtr.Zero)
88-
{
89-
thrownewPythonException();
90-
}
81+
Runtime.CheckExceptionOccurred();
9182
}
9283

9384

@@ -101,10 +92,7 @@ public PyLong(long value)
10192
publicPyLong(ulongvalue)
10293
{
10394
obj=Runtime.PyLong_FromUnsignedLongLong(value);
104-
if(obj==IntPtr.Zero)
105-
{
106-
thrownewPythonException();
107-
}
95+
Runtime.CheckExceptionOccurred();
10896
}
10997

11098

@@ -117,10 +105,7 @@ public PyLong(ulong value)
117105
publicPyLong(shortvalue)
118106
{
119107
obj=Runtime.PyLong_FromLong(value);
120-
if(obj==IntPtr.Zero)
121-
{
122-
thrownewPythonException();
123-
}
108+
Runtime.CheckExceptionOccurred();
124109
}
125110

126111

@@ -134,10 +119,7 @@ public PyLong(short value)
134119
publicPyLong(ushortvalue)
135120
{
136121
obj=Runtime.PyLong_FromLong(value);
137-
if(obj==IntPtr.Zero)
138-
{
139-
thrownewPythonException();
140-
}
122+
Runtime.CheckExceptionOccurred();
141123
}
142124

143125

@@ -150,10 +132,7 @@ public PyLong(ushort value)
150132
publicPyLong(bytevalue)
151133
{
152134
obj=Runtime.PyLong_FromLong(value);
153-
if(obj==IntPtr.Zero)
154-
{
155-
thrownewPythonException();
156-
}
135+
Runtime.CheckExceptionOccurred();
157136
}
158137

159138

@@ -167,10 +146,7 @@ public PyLong(byte value)
167146
publicPyLong(sbytevalue)
168147
{
169148
obj=Runtime.PyLong_FromLong(value);
170-
if(obj==IntPtr.Zero)
171-
{
172-
thrownewPythonException();
173-
}
149+
Runtime.CheckExceptionOccurred();
174150
}
175151

176152

@@ -183,10 +159,7 @@ public PyLong(sbyte value)
183159
publicPyLong(doublevalue)
184160
{
185161
obj=Runtime.PyLong_FromDouble(value);
186-
if(obj==IntPtr.Zero)
187-
{
188-
thrownewPythonException();
189-
}
162+
Runtime.CheckExceptionOccurred();
190163
}
191164

192165

@@ -199,10 +172,7 @@ public PyLong(double value)
199172
publicPyLong(stringvalue)
200173
{
201174
obj=Runtime.PyLong_FromString(value,IntPtr.Zero,0);
202-
if(obj==IntPtr.Zero)
203-
{
204-
thrownewPythonException();
205-
}
175+
Runtime.CheckExceptionOccurred();
206176
}
207177

208178

@@ -229,10 +199,7 @@ public static bool IsLongType(PyObject value)
229199
publicstaticPyLongAsLong(PyObjectvalue)
230200
{
231201
IntPtrop=Runtime.PyNumber_Long(value.obj);
232-
if(op==IntPtr.Zero)
233-
{
234-
thrownewPythonException();
235-
}
202+
Runtime.CheckExceptionOccurred();
236203
returnnewPyLong(op);
237204
}
238205

‎src/runtime/pystring.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ public PyString(PyObject o)
5454
publicPyString(strings)
5555
{
5656
obj=Runtime.PyUnicode_FromUnicode(s,s.Length);
57-
if(obj==IntPtr.Zero)
58-
{
59-
thrownewPythonException();
60-
}
57+
Runtime.CheckExceptionOccurred();
6158
}
6259

6360

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp