From 1932e9b861d17f6da68dc5e5fa485d621d11bab6 Mon Sep 17 00:00:00 2001 From: Ewald Zietsman Date: Wed, 9 May 2018 19:00:18 +0200 Subject: [PATCH] Added Python 3.x support to fpectmodule.cpp and added fpectl back into test scripts. --- tests/CheckScripts.py | 2 ++ tests/TestLGearSteer.py | 5 +++++ tests/fpectlmodule.cpp | 40 ++++++++++++++++++++++++++++++++++++++-- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/tests/CheckScripts.py b/tests/CheckScripts.py index d46ef22485..293dd63e05 100644 --- a/tests/CheckScripts.py +++ b/tests/CheckScripts.py @@ -18,12 +18,14 @@ # You should have received a copy of the GNU General Public License along with # this program; if not, see # +import fpectl from JSBSim_utils import JSBSimTestCase, CreateFDM, RunTest, ExecuteUntil class CheckScripts(JSBSimTestCase): def testScripts(self): + fpectl.turnon_sigfpe() for s in self.script_list(['737_cruise_steady_turn_simplex.xml']): fdm = CreateFDM(self.sandbox) diff --git a/tests/TestLGearSteer.py b/tests/TestLGearSteer.py index aef798a0a9..19bf2146b4 100644 --- a/tests/TestLGearSteer.py +++ b/tests/TestLGearSteer.py @@ -21,6 +21,7 @@ import os import xml.etree.ElementTree as et from JSBSim_utils import JSBSimTestCase, CreateFDM, RunTest, CopyAircraftDef +import fpectl class TestLGearSteer(JSBSimTestCase): @@ -33,12 +34,16 @@ def test_direct_steer(self): self.assertAlmostEqual(fdm['fcs/steer-cmd-norm'], 0.0) self.assertAlmostEqual(fdm['fcs/steer-pos-deg'], 0.0) + # Should be part of a unit test in C++ ? + fpectl.turnon_sigfpe() grndreact = fdm.get_ground_reactions() for i in range(grndreact.get_num_gear_units()): gear = grndreact.get_gear_unit(i) self.assertEqual(gear.get_steer_norm(), 0.0) + fpectl.turnoff_sigfpe() + fdm['fcs/steer-pos-deg'] = 5.0 self.assertAlmostEqual(fdm['fcs/steer-pos-deg'], 5.0) fdm.run() diff --git a/tests/fpectlmodule.cpp b/tests/fpectlmodule.cpp index 189f77b58d..c516344d89 100644 --- a/tests/fpectlmodule.cpp +++ b/tests/fpectlmodule.cpp @@ -133,14 +133,50 @@ static PyObject *turnoff_sigfpe(PyObject *self, PyObject *args) return Py_None; } +struct module_state { + PyObject *error; +}; + +#if PY_MAJOR_VERSION >= 3 +#define GETSTATE(m) ((struct module_state*)PyModule_GetState(m)) + +static struct PyModuleDef fpectl = { + PyModuleDef_HEAD_INIT, + "fpectl", + NULL, + sizeof(struct module_state), + fpectl_methods, + NULL, + NULL, + NULL, + NULL +}; + +PyMODINIT_FUNC PyInit_fpectl(void) +#else PyMODINIT_FUNC initfpectl(void) +#endif { - PyObject *m = Py_InitModule("fpectl", fpectl_methods); + #if PY_MAJOR_VERSION >= 3 + PyObject *m = PyModule_Create(&fpectl); + #else + PyObject *m = Py_InitModule("fpectl", fpectl_methods); + #endif + if (m == NULL) - return; + #if PY_MAJOR_VERSION >= 3 + return NULL; + #else + return; + #endif + 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); + + #if PY_MAJOR_VERSION >= 3 + return m; + #endif }