Commit 3d1bd94a authored by Robert Bradshaw's avatar Robert Bradshaw

Merge branch 'except_plus_null_pyobject' of https://github.com/bloomberg/cython

parents f61160ed 790b0994
......@@ -5846,7 +5846,7 @@ class SimpleCallNode(CallNode):
elif self.type.is_memoryviewslice:
assert self.is_temp
exc_checks.append(self.type.error_condition(self.result()))
else:
elif func_type.exception_check != '+':
exc_val = func_type.exception_value
exc_check = func_type.exception_check
if exc_val is not None:
......
......@@ -21,7 +21,7 @@ cdef extern from "cpp_exceptions_helper.h":
cdef void raise_typeerror() except +
cdef void raise_underflow() except +
cdef object raise_py(bint fire_py) except +
cdef raise_or_throw(bint py) except +
cdef cppclass Foo:
int bar_raw "bar"(bint fire) except +
......@@ -100,6 +100,19 @@ def test_underflow():
"""
raise_underflow()
def test_func_that_can_raise_or_throw(bint py):
"""
>>> test_func_that_can_raise_or_throw(0)
Traceback (most recent call last):
...
RuntimeError: oopsie
>>> test_func_that_can_raise_or_throw(1)
Traceback (most recent call last):
...
ValueError: oopsie
"""
raise_or_throw(py)
def test_int_raw(bint fire):
"""
>>> test_int_raw(False)
......@@ -201,17 +214,3 @@ def test_cppclass_method_custom(bint fire):
foo.bar_custom(fire)
finally:
del foo
def test_py(bint py_fire):
"""
>>> test_py(True)
Traceback (most recent call last):
...
RuntimeError: py error
>>> test_py(False)
Traceback (most recent call last):
...
IndexError: c++ error
"""
raise_py(py_fire)
#include <Python.h>
#include <ios>
#include <new>
#include <stdexcept>
......@@ -62,11 +63,10 @@ void raise_underflow() {
throw std::underflow_error("underflow_error");
}
PyObject* raise_py(int fire_py) {
if (fire_py) {
PyErr_SetString(PyExc_RuntimeError, "py error");
return NULL;
} else {
throw std::out_of_range("c++ error");
PyObject *raise_or_throw(int py) {
if (!py) {
throw std::runtime_error("oopsie");
}
PyErr_SetString(PyExc_ValueError, "oopsie");
return NULL;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment