File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed
com.oracle.graal.python.cext/src
com.oracle.graal.python.test/src/tests/cpyext Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change 40
40
41
41
#include <pyerrors.h>
42
42
43
- #define PY_EXCEPTION (__EXC_NAME__ ) ((PyObject*)polyglot_as__object(to_sulong(truffle_import_cached("python_" __EXC_NAME__) )))
43
+ #define PY_EXCEPTION (__EXC_NAME__ ) (UPCALL_CEXT_O("PyTruffle_Type", polyglot_from_string( __EXC_NAME__, SRC_CS )))
44
44
45
45
PyObject * PyExc_BaseException = NULL ;
46
46
PyObject * PyExc_Exception = NULL ;
Original file line number Diff line number Diff line change @@ -187,6 +187,35 @@ def compile_module(self, name):
187
187
cmpfunc = unhandled_error_compare
188
188
)
189
189
190
+ test_PyErr_GivenExceptionMatchesNative = CPyExtFunction (
191
+ lambda args : args [2 ],
192
+ lambda : (
193
+ # ValueError = 0
194
+ # KeyError = 1
195
+ (ValueError , 0 , True ),
196
+ (ValueError , 1 , False ),
197
+ (KeyError , 0 , False ),
198
+ (KeyError , 1 , True ),
199
+ (Dummy , 0 , False ),
200
+ (Dummy , 1 , False ),
201
+ ),
202
+ code = """int PyErr_GivenExceptionMatchesNative(PyObject* exc, int selector, int unused) {
203
+ switch(selector) {
204
+ case 0:
205
+ return exc == PyExc_ValueError;
206
+ case 1:
207
+ return exc == PyExc_KeyError;
208
+ }
209
+ return 0;
210
+ }
211
+ """ ,
212
+ resultspec = "i" ,
213
+ argspec = 'Oii' ,
214
+ arguments = ["PyObject* exc" , "int selector" , "int unused" ],
215
+ callfunction = "PyErr_GivenExceptionMatchesNative" ,
216
+ cmpfunc = unhandled_error_compare
217
+ )
218
+
190
219
test_PyErr_Occurred = CPyExtFunction (
191
220
lambda args : args [0 ] if _is_exception_class (args [0 ]) else SystemError ,
192
221
lambda : (
You can’t perform that action at this time.
0 commit comments