From 63f59901af507ae7486be786288bfd7c0a04c173 Mon Sep 17 00:00:00 2001 From: Jonathan Lambrechts <jonathan.lambrechts@uclouvain.be> Date: Thu, 30 Jun 2011 12:47:24 +0000 Subject: [PATCH] functionPython : when an error occurs in python code executed from c, print it and exit --- Solver/functionPython.h | 9 ++++++++- gmshpy/gmshCommon.i | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Solver/functionPython.h b/Solver/functionPython.h index 303d9dad88..0a87f75379 100644 --- a/Solver/functionPython.h +++ b/Solver/functionPython.h @@ -20,7 +20,14 @@ class functionPython : public function { { R.setAsProxy(res); R.setDataCacheMap(m); - PyEval_CallObject(_pycallback, _pyargs); + PyObject *result = PyEval_CallObject(_pycallback, _pyargs); + if (result) { + Py_DECREF(result); + } + else { + PyErr_Print(); + Msg::Fatal("An error occurs in the python function."); + } } functionPython (int nbCol, PyObject *callback, std::vector<const function*> dependencies) : function(nbCol), _pycallback(callback) diff --git a/gmshpy/gmshCommon.i b/gmshpy/gmshCommon.i index d76c61e5a8..6d4dc71764 100644 --- a/gmshpy/gmshCommon.i +++ b/gmshpy/gmshCommon.i @@ -24,7 +24,7 @@ #endif std::cout<<level<<" : "<<message<<std::endl; if (level == "Fatal") - throw; + Msg::Exit(1); } }; %} -- GitLab