From 5f2d55ab2e045f7179a1ea674c591d8454b1fa80 Mon Sep 17 00:00:00 2001 From: Alexandre Duret-Lutz Date: Fri, 2 Oct 2015 19:43:39 +0200 Subject: [PATCH] python: do not crash when a function returns a null formula * wrap/python/spot_impl.i: Map null formulas to None. * wrap/python/tests/randgen.py: New file. * wrap/python/tests/Makefile.am: Add it. --- wrap/python/spot_impl.i | 7 +++++++ wrap/python/tests/Makefile.am | 1 + wrap/python/tests/randgen.py | 29 +++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100755 wrap/python/tests/randgen.py diff --git a/wrap/python/spot_impl.i b/wrap/python/spot_impl.i index 6fc2926ac..3ca147720 100644 --- a/wrap/python/spot_impl.i +++ b/wrap/python/spot_impl.i @@ -178,6 +178,13 @@ using namespace spot; }; %apply char** OUTPUT { char** err }; +%typemap(out) spot::formula { + if (!$1) + $result = SWIG_Py_Void(); + else + $result = SWIG_NewPointerObj(new spot::formula($1), $descriptor(spot::formula*), SWIG_POINTER_OWN); +} + %exception { try { $action diff --git a/wrap/python/tests/Makefile.am b/wrap/python/tests/Makefile.am index 667f768b4..3f5c6442a 100644 --- a/wrap/python/tests/Makefile.am +++ b/wrap/python/tests/Makefile.am @@ -48,6 +48,7 @@ TESTS = \ parsetgba.py \ piperead.ipynb \ randaut.ipynb \ + randgen.py \ randltl.ipynb \ relabel.py \ setxor.py \ diff --git a/wrap/python/tests/randgen.py b/wrap/python/tests/randgen.py new file mode 100755 index 000000000..f5cfe7b93 --- /dev/null +++ b/wrap/python/tests/randgen.py @@ -0,0 +1,29 @@ +# -*- mode: python; coding: utf-8 -*- +# Copyright (C) 2015 Laboratoire de Recherche et Développement de +# l'Epita (LRDE). +# +# This file is part of Spot, a model checking library. +# +# Spot is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Spot is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +# License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# This is a python translation of the ltl2tgba C++ test program. +# Compare with src/tgbatest/ltl2tgba.cc. + +import spot + +o = spot.option_map() +g = spot.randltlgenerator(0, o) +assert str(g.next()) == '1' +assert str(g.next()) == '0' +assert str(g.next()) == 'None' -- GitLab