From: Bertrand <bco...@us...> - 2016-06-19 12:40:02
|
Update of /cvsroot/jsbsim/JSBSim/tests In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv24490/tests Modified Files: fpectlmodule.h fpectlmodule.cpp ExceptionManagement.h Log Message: Better conformance to the fpectl module official documentation: the exception fpectl.FloatingPointError is now raised when the signal SIGFPE is caught. Index: fpectlmodule.h =================================================================== RCS file: /cvsroot/jsbsim/JSBSim/tests/fpectlmodule.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -r1.1 -r1.2 *** fpectlmodule.h 19 Jun 2016 09:26:22 -0000 1.1 --- fpectlmodule.h 19 Jun 2016 12:39:59 -0000 1.2 *************** *** 17,20 **** --- 17,21 ---- */ + #include "Python.h" #include <exception> #include <string> *************** *** 24,32 **** { public: ! FloatingPointException(const std::string& _msg) : msg(_msg) {} const char* what() const throw() { return msg.c_str(); } ~FloatingPointException() throw() {} private: std::string msg; }; --- 25,36 ---- { public: ! FloatingPointException(PyObject* _pyexc, const std::string& _msg) ! : pyexc(_pyexc), msg(_msg) {} const char* what() const throw() { return msg.c_str(); } + PyObject* getPyExc() const { return pyexc; } ~FloatingPointException() throw() {} private: + PyObject* pyexc; std::string msg; }; Index: fpectlmodule.cpp =================================================================== RCS file: /cvsroot/jsbsim/JSBSim/tests/fpectlmodule.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -r1.1 -r1.2 *** fpectlmodule.cpp 19 Jun 2016 09:26:22 -0000 1.1 --- fpectlmodule.cpp 19 Jun 2016 12:39:59 -0000 1.2 *************** *** 66,74 **** */ - #include "Python.h" - #include <signal.h> - #include "fpectlmodule.h" #if defined(_MSC_VER) # include <float.h> --- 66,73 ---- */ #include "fpectlmodule.h" + #include <signal.h> + #if defined(_MSC_VER) # include <float.h> *************** *** 81,84 **** --- 80,84 ---- static PyOS_sighandler_t handler = 0; + static PyObject *fpe_error; PyMODINIT_FUNC initfpectl(void); static PyObject *turnon_sigfpe(PyObject *self,PyObject *args); *************** *** 94,98 **** { PyOS_setsig(SIGFPE, sigfpe_handler); ! throw JSBSim::FloatingPointException("Caught signal SIGFPE in JSBSim"); } --- 94,99 ---- { PyOS_setsig(SIGFPE, sigfpe_handler); ! throw JSBSim::FloatingPointException(fpe_error, ! "Caught signal SIGFPE in JSBSim"); } *************** *** 127,130 **** PyMODINIT_FUNC initfpectl(void) { ! Py_InitModule("fpectl", fpectl_methods); } --- 128,138 ---- PyMODINIT_FUNC initfpectl(void) { ! PyObject *m = Py_InitModule("fpectl", fpectl_methods); ! if (m == NULL) ! return; ! PyObject *d = PyModule_GetDict(m); ! fpe_error = PyErr_NewException((char*)"fpectl.FloatingPointError", ! PyExc_FloatingPointError, NULL); ! if (fpe_error != NULL) ! PyDict_SetItemString(d, "FloatingPointError", fpe_error); } Index: ExceptionManagement.h =================================================================== RCS file: /cvsroot/jsbsim/JSBSim/tests/ExceptionManagement.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** ExceptionManagement.h 19 Jun 2016 09:26:22 -0000 1.2 --- ExceptionManagement.h 19 Jun 2016 12:39:59 -0000 1.3 *************** *** 18,22 **** #include <string> - #include "Python.h" #include "fpectlmodule.h" --- 18,21 ---- *************** *** 34,38 **** } catch (const JSBSim::FloatingPointException& e) { ! PyErr_SetString(PyExc_FloatingPointError, e.what()); } } --- 33,37 ---- } catch (const JSBSim::FloatingPointException& e) { ! PyErr_SetString(e.getPyExc(), e.what()); } } |