1 /////////////// CppExceptionConversion.proto ///////////////
2 
3 #ifndef __Pyx_CppExn2PyErr
4 #include <new>
5 #include <typeinfo>
6 #include <stdexcept>
7 #include <ios>
8 
__Pyx_CppExn2PyErr()9 static void __Pyx_CppExn2PyErr() {
10   // Catch a handful of different errors here and turn them into the
11   // equivalent Python errors.
12   try {
13     if (PyErr_Occurred())
14       ; // let the latest Python exn pass through and ignore the current one
15     else
16       throw;
17   } catch (const std::bad_alloc& exn) {
18     PyErr_SetString(PyExc_MemoryError, exn.what());
19   } catch (const std::bad_cast& exn) {
20     PyErr_SetString(PyExc_TypeError, exn.what());
21   } catch (const std::bad_typeid& exn) {
22     PyErr_SetString(PyExc_TypeError, exn.what());
23   } catch (const std::domain_error& exn) {
24     PyErr_SetString(PyExc_ValueError, exn.what());
25   } catch (const std::invalid_argument& exn) {
26     PyErr_SetString(PyExc_ValueError, exn.what());
27   } catch (const std::ios_base::failure& exn) {
28     // Unfortunately, in standard C++ we have no way of distinguishing EOF
29     // from other errors here; be careful with the exception mask
30     PyErr_SetString(PyExc_IOError, exn.what());
31   } catch (const std::out_of_range& exn) {
32     // Change out_of_range to IndexError
33     PyErr_SetString(PyExc_IndexError, exn.what());
34   } catch (const std::overflow_error& exn) {
35     PyErr_SetString(PyExc_OverflowError, exn.what());
36   } catch (const std::range_error& exn) {
37     PyErr_SetString(PyExc_ArithmeticError, exn.what());
38   } catch (const std::underflow_error& exn) {
39     PyErr_SetString(PyExc_ArithmeticError, exn.what());
40   } catch (const std::exception& exn) {
41     PyErr_SetString(PyExc_RuntimeError, exn.what());
42   }
43   catch (...)
44   {
45     PyErr_SetString(PyExc_RuntimeError, "Unknown exception");
46   }
47 }
48 #endif
49 
50 /////////////// PythranConversion.proto ///////////////
51 
52 template <class T>
__Pyx_pythran_to_python(T && value)53 auto __Pyx_pythran_to_python(T &&value) -> decltype(to_python(
54       typename pythonic::returnable<typename std::remove_cv<typename std::remove_reference<T>::type>::type>::type{std::forward<T>(value)}))
55 {
56   using returnable_type = typename pythonic::returnable<typename std::remove_cv<typename std::remove_reference<T>::type>::type>::type;
57   return to_python(returnable_type{std::forward<T>(value)});
58 }
59