diff --git a/NEWS b/NEWS index 3faf047fc..7349ee5e8 100644 --- a/NEWS +++ b/NEWS @@ -21,6 +21,10 @@ New in spot 2.6.0.dev (not yet released) documentation was also matching the code, so this is a backward incompatible change. + - The Python binding of the getter of spot::parsed_formula::f was + returning a reference instead of a copy, causing issues if the + reference outlasted the parsed_formula struct. + New in spot 2.6 (2018-07-04) diff --git a/python/spot/impl.i b/python/spot/impl.i index 1050c7568..7bdcd1bef 100644 --- a/python/spot/impl.i +++ b/python/spot/impl.i @@ -384,6 +384,15 @@ namespace swig SWIG_POINTER_IMPLICIT_CONV)); } +// Access to stucture members, such as spot::parsed_formula::f are done via +// the pointer typemap. We want to enforce a copy. +%typemap(out) spot::formula* { + if (!*$1) + $result = SWIG_Py_Void(); + else + $result = SWIG_NewPointerObj(new spot::formula(*$1), $descriptor(spot::formula*), SWIG_POINTER_OWN); +} + %typemap(out) spot::formula { if (!$1) $result = SWIG_Py_Void(); diff --git a/tests/python/ltlsimple.py b/tests/python/ltlsimple.py index 96ebcda17..a8443a357 100755 --- a/tests/python/ltlsimple.py +++ b/tests/python/ltlsimple.py @@ -134,3 +134,11 @@ for (input, output) in [('(a&b)<->b', 'b->(a&b)'), print(input, f, output) assert(f == output) assert(spot.are_equivalent(input, output)) + +def myparse(input): + env = spot.default_environment.instance() + pf = spot.parse_infix_psl(input, env) + return pf.f +# This used to fail, because myparse would return a pointer +# to pf.f inside the destroyed pf. +assert myparse('a U b') == spot.formula('a U b')