moved C++ exception conversion utility code into new utility code file Cython/Utility...
authorStefan Behnel <stefan_ml@behnel.de>
Sun, 8 Jul 2012 19:30:59 +0000 (21:30 +0200)
committerStefan Behnel <stefan_ml@behnel.de>
Sun, 8 Jul 2012 19:30:59 +0000 (21:30 +0200)
Cython/Compiler/ExprNodes.py
Cython/Utility/CppSupport.cpp [new file with mode: 0644]

index 9b94e1e..9a4784c 100755 (executable)
@@ -3975,7 +3975,7 @@ class SimpleCallNode(CallNode):
         # C++ exception handler
         if func_type.exception_check == '+':
             if func_type.exception_value is None:
-                env.use_utility_code(cpp_exception_utility_code)
+                env.use_utility_code(UtilityCode.load_cached("CppExceptionConversion", "CppSupport.cpp"))
 
     def calculate_result_code(self):
         return self.c_call_code()
@@ -9870,54 +9870,6 @@ bad:
 
 #------------------------------------------------------------------------------------
 
-cpp_exception_utility_code = UtilityCode(
-proto = """
-#ifndef __Pyx_CppExn2PyErr
-#include <new>
-#include <typeinfo>
-#include <stdexcept>
-#include <iostream>
-
-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::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");
-  }
-}
-#endif
-""")
-
 pyerr_occurred_withgil_utility_code= UtilityCode(
 proto = """
 static CYTHON_INLINE int __Pyx_ErrOccurredWithGIL(void); /* proto */
diff --git a/Cython/Utility/CppSupport.cpp b/Cython/Utility/CppSupport.cpp
new file mode 100644 (file)
index 0000000..8913253
--- /dev/null
@@ -0,0 +1,46 @@
+/////////////// CppExceptionConversion.proto ///////////////
+
+#ifndef __Pyx_CppExn2PyErr
+#include <new>
+#include <typeinfo>
+#include <stdexcept>
+#include <iostream>
+
+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::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");
+  }
+}
+#endif