Spaces:
Build error
Build error
/////////////// CppExceptionConversion.proto /////////////// | |
static void __Pyx_CppExn2PyErr() { | |
// Catch a handful of different errors here and turn them into the | |
// equivalent Python errors. | |
try { | |
if (PyErr_Occurred()) | |
; // let the latest Python exn pass through and ignore the current one | |
else | |
throw; | |
} catch (const std::bad_alloc& exn) { | |
PyErr_SetString(PyExc_MemoryError, exn.what()); | |
} catch (const std::bad_cast& exn) { | |
PyErr_SetString(PyExc_TypeError, exn.what()); | |
} catch (const std::bad_typeid& exn) { | |
PyErr_SetString(PyExc_TypeError, exn.what()); | |
} catch (const std::domain_error& exn) { | |
PyErr_SetString(PyExc_ValueError, exn.what()); | |
} catch (const std::invalid_argument& exn) { | |
PyErr_SetString(PyExc_ValueError, exn.what()); | |
} catch (const std::ios_base::failure& exn) { | |
// Unfortunately, in standard C++ we have no way of distinguishing EOF | |
// from other errors here; be careful with the exception mask | |
PyErr_SetString(PyExc_IOError, exn.what()); | |
} catch (const std::out_of_range& exn) { | |
// Change out_of_range to IndexError | |
PyErr_SetString(PyExc_IndexError, exn.what()); | |
} catch (const std::overflow_error& exn) { | |
PyErr_SetString(PyExc_OverflowError, exn.what()); | |
} catch (const std::range_error& exn) { | |
PyErr_SetString(PyExc_ArithmeticError, exn.what()); | |
} catch (const std::underflow_error& exn) { | |
PyErr_SetString(PyExc_ArithmeticError, exn.what()); | |
} catch (const std::exception& exn) { | |
PyErr_SetString(PyExc_RuntimeError, exn.what()); | |
} | |
catch (...) | |
{ | |
PyErr_SetString(PyExc_RuntimeError, "Unknown exception"); | |
} | |
} | |
/////////////// PythranConversion.proto /////////////// | |
template <class T> | |
auto __Pyx_pythran_to_python(T &&value) -> decltype(to_python( | |
typename pythonic::returnable<typename std::remove_cv<typename std::remove_reference<T>::type>::type>::type{std::forward<T>(value)})) | |
{ | |
using returnable_type = typename pythonic::returnable<typename std::remove_cv<typename std::remove_reference<T>::type>::type>::type; | |
return to_python(returnable_type{std::forward<T>(value)}); | |
} | |
////////////// MoveIfSupported.proto ////////////////// | |
////////////// EnumClassDecl.proto ////////////////// | |
//@proto_block: utility_code_proto_before_types | |
////////////// OptionalLocals.proto //////////////// | |
//@proto_block: utility_code_proto_before_types | |
// fallback mode - std::optional is preferred but this gives | |
// people with a less up-to-date compiler a chance | |
// since std::optional is a C++17 features, a templated using declaration should be safe | |
// (although it could be replaced with a define) | |
template <typename T> | |
using __Pyx_Optional_BaseType = std::optional<T>; | |
// This class reuses as much of the implementation of std::optional as possible. | |
// The only place it differs significantly is the assignment operators, which use | |
// "emplace" (thus requiring move/copy constructors, but not move/copy | |
// assignment operators). This is preferred because it lets us work with assignable | |
// types (for example those with const members) | |
template <typename T> | |
class __Pyx_Optional_Type : private __Pyx_Optional_BaseType<T> { | |
public: | |
using __Pyx_Optional_BaseType<T>::__Pyx_Optional_BaseType; | |
using __Pyx_Optional_BaseType<T>::has_value; | |
using __Pyx_Optional_BaseType<T>::operator*; | |
using __Pyx_Optional_BaseType<T>::operator->; | |
__Pyx_Optional_Type& operator=(const __Pyx_Optional_Type& rhs) { | |
this->emplace(*rhs); | |
return *this; | |
} | |
__Pyx_Optional_Type& operator=(__Pyx_Optional_Type&& rhs) { | |
this->emplace(std::move(*rhs)); | |
return *this; | |
} | |
template <typename U=T> | |
__Pyx_Optional_Type& operator=(U&& rhs) { | |
this->emplace(std::forward<U>(rhs)); | |
return *this; | |
} | |
// Note - the "cpp_locals" feature is designed to require C++14. | |
// This pre-c++11 fallback is largely untested, and definitely won't work | |
// in all the cases that the more modern version does | |
using __Pyx_Optional_BaseType<T>::operator=; // the chances are emplace can't work... | |
}; | |