Commit 5c8cf1bc authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz
Browse files

fix python bindings for spot::parsed_formula::f getter

* python/spot/impl.i: Add a typemap.
* tests/python/ltlsimple.py: Add a test case for an issue.
* NEWS: Mention the bug.
parent 701a3b1c
Pipeline #3200 passed with stage
in 150 minutes and 55 seconds
...@@ -21,6 +21,10 @@ New in spot 2.6.0.dev (not yet released) ...@@ -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 documentation was also matching the code, so this is a backward
incompatible change. 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) New in spot 2.6 (2018-07-04)
......
...@@ -384,6 +384,15 @@ namespace swig ...@@ -384,6 +384,15 @@ namespace swig
SWIG_POINTER_IMPLICIT_CONV)); 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 { %typemap(out) spot::formula {
if (!$1) if (!$1)
$result = SWIG_Py_Void(); $result = SWIG_Py_Void();
......
...@@ -134,3 +134,11 @@ for (input, output) in [('(a&b)<->b', 'b->(a&b)'), ...@@ -134,3 +134,11 @@ for (input, output) in [('(a&b)<->b', 'b->(a&b)'),
print(input, f, output) print(input, f, output)
assert(f == output) assert(f == output)
assert(spot.are_equivalent(input, 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')
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment