python: make sere twa::acc() survives its automaton

Fixes #468.

* python/spot/__init__.py: Add wrapper around twa::acc() and
twa::get_acceptance() to store the automaton into the acceptance
proxy, therefore ensuring that the automaton survives that proxy.
* tests/python/setacc.py: Test it.
This commit is contained in:
Alexandre Duret-Lutz 2021-07-12 15:27:07 +02:00
parent b767411a82
commit d019ea61fe
2 changed files with 35 additions and 1 deletions

View file

@ -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):