diff --git a/python/spot/__init__.py b/python/spot/__init__.py index b49538fbe..9a14ff8c6 100644 --- a/python/spot/__init__.py +++ b/python/spot/__init__.py @@ -137,6 +137,31 @@ def __om_init_new(self, str=None): option_map.__init__ = __om_init_new +__twa__acc1 = twa.acc +__twa__acc2 = twa.get_acceptance + + +# We store the automaton into the acceptance condition +# returned by acc so that it does not crash when +# taking the reference to a temporary, as in +# spot.translate('Foo').acc() +# Issue #468. +def __twa_acc1_tmp(self): + a = __twa__acc1(self) + a._aut = self + return a + + +def __twa_acc2_tmp(self): + a = __twa__acc2(self) + a._aut = self + return a + + +twa.acc = __twa_acc1_tmp +twa.get_acceptance = __twa_acc2_tmp + + @_extend(twa, ta) class twa: def _repr_svg_(self, opt=None): @@ -181,7 +206,6 @@ class twa: self.highlight_edge(val, color) return self - @_extend(twa) class twa: def to_str(a, format='hoa', opt=None): diff --git a/tests/python/setacc.py b/tests/python/setacc.py index f82fba37d..3ccf935cf 100644 --- a/tests/python/setacc.py +++ b/tests/python/setacc.py @@ -96,3 +96,13 @@ except RuntimeError as e: pass else: raise e + + +# issue #468 +from gc import collect +acc = spot.translate('a').acc() +collect() +assert acc == spot.acc_cond('Inf(0)') +acc = spot.translate('b').get_acceptance() +collect() +assert acc == spot.acc_code('Inf(0)')