Skip to content

Commit

Permalink
Added Python 3.x support to fpectmodule.cpp and added fpectl back int…
Browse files Browse the repository at this point in the history
…o test scripts.
  • Loading branch information
ezietsman committed May 9, 2018
1 parent 94d510a commit 1932e9b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
2 changes: 2 additions & 0 deletions tests/CheckScripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
# You should have received a copy of the GNU General Public License along with
# this program; if not, see <http://www.gnu.org/licenses/>
#
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)
Expand Down
5 changes: 5 additions & 0 deletions tests/TestLGearSteer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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()
Expand Down
40 changes: 38 additions & 2 deletions tests/fpectlmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 1932e9b

Please sign in to comment.