* src/tgba/taatgba.cc, src/tgba/taatgba.hh: Fix memory issues
occuring when labels are pointers. * src/tgbaalgos/ltl2taa.cc: Fix a bug. * src/tgbatest/ltl2tgba.cc: Fix a bug.
This commit is contained in:
parent
be78c82e44
commit
9cebcdc124
5 changed files with 61 additions and 28 deletions
|
|
@ -25,6 +25,7 @@
|
|||
#include <iostream>
|
||||
#include "tgba/formula2bdd.hh"
|
||||
#include "ltlvisit/tostring.hh"
|
||||
#include "ltlvisit/clone.hh"
|
||||
#include "misc/bddop.hh"
|
||||
#include "taatgba.hh"
|
||||
|
||||
|
|
@ -350,7 +351,13 @@ namespace spot
|
|||
`----------------*/
|
||||
|
||||
std::string
|
||||
taa_tgba_string::label_to_string(const std::string label) const
|
||||
taa_tgba_string::label_to_string(const label_t& label) const
|
||||
{
|
||||
return label;
|
||||
}
|
||||
|
||||
std::string
|
||||
taa_tgba_string::clone_if(const label_t& label) const
|
||||
{
|
||||
return label;
|
||||
}
|
||||
|
|
@ -359,9 +366,22 @@ namespace spot
|
|||
| taa_tgba_formula |
|
||||
`-----------------*/
|
||||
|
||||
taa_tgba_formula::~taa_tgba_formula()
|
||||
{
|
||||
ns_map::iterator i;
|
||||
for (i = name_state_map_.begin(); i != name_state_map_.end(); ++i)
|
||||
i->first->destroy();
|
||||
}
|
||||
|
||||
std::string
|
||||
taa_tgba_formula::label_to_string(const ltl::formula* label) const
|
||||
taa_tgba_formula::label_to_string(const label_t& label) const
|
||||
{
|
||||
return ltl::to_string(label);
|
||||
}
|
||||
|
||||
ltl::formula*
|
||||
taa_tgba_formula::clone_if(const label_t& label) const
|
||||
{
|
||||
return label->clone();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -264,6 +264,8 @@ namespace spot
|
|||
}
|
||||
|
||||
protected:
|
||||
typedef label label_t;
|
||||
|
||||
typedef Sgi::hash_map<
|
||||
const label, taa_tgba::state*, label_hash
|
||||
> ns_map;
|
||||
|
|
@ -275,7 +277,11 @@ namespace spot
|
|||
sn_map state_name_map_;
|
||||
|
||||
/// \brief Return a label as a string.
|
||||
virtual std::string label_to_string(const label lbl) const = 0;
|
||||
virtual std::string label_to_string(const label_t& lbl) const = 0;
|
||||
|
||||
/// \brief Clone the label if necessary to assure it is owned by
|
||||
/// this, avoiding memory issues when label is a pointer.
|
||||
virtual label_t clone_if(const label_t& lbl) const = 0;
|
||||
|
||||
private:
|
||||
/// \brief Return the taa_tgba::state for \a name, creating it
|
||||
|
|
@ -285,9 +291,10 @@ namespace spot
|
|||
typename ns_map::iterator i = name_state_map_.find(name);
|
||||
if (i == name_state_map_.end())
|
||||
{
|
||||
const label& name_ = clone_if(name);
|
||||
taa_tgba::state* s = new taa_tgba::state;
|
||||
name_state_map_[name] = s;
|
||||
state_name_map_[s] = name;
|
||||
name_state_map_[name_] = s;
|
||||
state_name_map_[s] = name_;
|
||||
return s;
|
||||
}
|
||||
return i->second;
|
||||
|
|
@ -338,17 +345,21 @@ namespace spot
|
|||
taa_tgba_string(bdd_dict* dict) :
|
||||
taa_tgba_labelled<std::string, string_hash>(dict) {};
|
||||
protected:
|
||||
virtual std::string label_to_string(const std::string label) const;
|
||||
virtual std::string label_to_string(const std::string& label) const;
|
||||
virtual std::string clone_if(const std::string& label) const;
|
||||
};
|
||||
|
||||
class taa_tgba_formula :
|
||||
public taa_tgba_labelled<const ltl::formula*, ltl::formula_ptr_hash>
|
||||
{
|
||||
public:
|
||||
taa_tgba_formula(bdd_dict* dict):
|
||||
taa_tgba_formula(bdd_dict* dict) :
|
||||
taa_tgba_labelled<const ltl::formula*, ltl::formula_ptr_hash>(dict) {};
|
||||
// Labels are pointers here and must be destroyed eventually.
|
||||
~taa_tgba_formula();
|
||||
protected:
|
||||
virtual std::string label_to_string(const ltl::formula* label) const;
|
||||
virtual std::string label_to_string(const label_t& label) const;
|
||||
virtual ltl::formula* clone_if(const label_t& label) const;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue