Skip to content

Commit 5bd0036

Browse files
committed
Refactor 'exceptions.c'.
1 parent 6382c87 commit 5bd0036

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

graalpython/com.oracle.graal.python.cext/src/exceptions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
#include <pyerrors.h>
4242

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)))
4444

4545
PyObject * PyExc_BaseException = NULL;
4646
PyObject * PyExc_Exception = NULL;

graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_err.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,35 @@ def compile_module(self, name):
187187
cmpfunc=unhandled_error_compare
188188
)
189189

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+
190219
test_PyErr_Occurred = CPyExtFunction(
191220
lambda args: args[0] if _is_exception_class(args[0]) else SystemError,
192221
lambda: (

0 commit comments

Comments
 (0)