Commit 574a2285 authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz
Browse files

Introduce a destroy() method on states, and use it instead of delete.

Right now, destroy() just executes "delete this".  But in a later
version, we will rewrite tgba_explicit so that it does not
allocate new states (and the destroy() method for explicit state
will do nothing).

* src/tgba/state.hh (state::destroy): New method, to replace
state::~state() in the future.
(shared_state_deleter): New function.
* src/evtgba/product.cc, src/evtgbaalgos/reachiter.cc,
src/evtgbaalgos/save.cc, src/evtgbaalgos/tgba2evtgba.cc,
src/tgba/tgba.cc, src/tgba/tgbaproduct.cc, src/tgba/tgbareduc.cc,
src/tgba/tgbasafracomplement.cc, src/tgba/tgbasgba.cc,
src/tgba/tgbatba.cc, src/tgba/tgbaunion.cc, src/tgba/wdbacomp.cc,
src/tgbaalgos/cutscc.cc, src/tgbaalgos/emptiness.cc,
src/tgbaalgos/gtec/ce.cc, src/tgbaalgos/gtec/explscc.cc,
src/tgbaalgos/gtec/gtec.cc, src/tgbaalgos/gtec/nsheap.cc,
src/tgbaalgos/gv04.cc, src/tgbaalgos/magic.cc,
src/tgbaalgos/minimize.cc, src/tgbaalgos/ndfs_result.hxx,
src/tgbaalgos/neverclaim.cc, src/tgbaalgos/powerset.hh,
src/tgbaalgos/reachiter.cc, src/tgbaalgos/reducerun.cc,
src/tgbaalgos/reductgba_sim.cc,
src/tgbaalgos/reductgba_sim_del.cc, src/tgbaalgos/replayrun.cc,
src/tgbaalgos/safety.cc, src/tgbaalgos/save.cc,
src/tgbaalgos/scc.cc, src/tgbaalgos/se05.cc,
src/tgbaalgos/tau03.cc, src/tgbaalgos/tau03opt.cc: Adjust to call
"s->destroy()" instead of "delete s".
* src/saba/sabacomplementtgba.cc, src/tgba/tgbakvcomplement.cc:
Pass shared_state_deleter to the shared_ptr constructor, so that
it calls destroy() instead of delete.
parent 60930d7a
2011-01-25 Alexandre Duret-Lutz <adl@lrde.epita.fr>
Introduce a destroy() method on states, and use it instead of delete.
Right now, destroy() just executes "delete this". But in a later
version, we will rewrite tgba_explicit so that it does not
allocate new states (and the destroy() method for explicit state
will do nothing).
* src/tgba/state.hh (state::destroy): New method, to replace
state::~state() in the future.
(shared_state_deleter): New function.
* src/evtgba/product.cc, src/evtgbaalgos/reachiter.cc,
src/evtgbaalgos/save.cc, src/evtgbaalgos/tgba2evtgba.cc,
src/tgba/tgba.cc, src/tgba/tgbaproduct.cc, src/tgba/tgbareduc.cc,
src/tgba/tgbasafracomplement.cc, src/tgba/tgbasgba.cc,
src/tgba/tgbatba.cc, src/tgba/tgbaunion.cc, src/tgba/wdbacomp.cc,
src/tgbaalgos/cutscc.cc, src/tgbaalgos/emptiness.cc,
src/tgbaalgos/gtec/ce.cc, src/tgbaalgos/gtec/explscc.cc,
src/tgbaalgos/gtec/gtec.cc, src/tgbaalgos/gtec/nsheap.cc,
src/tgbaalgos/gv04.cc, src/tgbaalgos/magic.cc,
src/tgbaalgos/minimize.cc, src/tgbaalgos/ndfs_result.hxx,
src/tgbaalgos/neverclaim.cc, src/tgbaalgos/powerset.hh,
src/tgbaalgos/reachiter.cc, src/tgbaalgos/reducerun.cc,
src/tgbaalgos/reductgba_sim.cc,
src/tgbaalgos/reductgba_sim_del.cc, src/tgbaalgos/replayrun.cc,
src/tgbaalgos/safety.cc, src/tgbaalgos/save.cc,
src/tgbaalgos/scc.cc, src/tgbaalgos/se05.cc,
src/tgbaalgos/tau03.cc, src/tgbaalgos/tau03opt.cc: Adjust to call
"s->destroy()" instead of "delete s".
* src/saba/sabacomplementtgba.cc, src/tgba/tgbakvcomplement.cc:
Pass shared_state_deleter to the shared_ptr constructor, so that
it calls destroy() instead of delete.
2011-01-26 Alexandre Duret-Lutz <adl@lrde.epita.fr>
* wrap/python/ajax/ltl2tgba.html: Display the Spot version in
* wrap/python/ajax/ltl2tgba.html: Display the Spot version in
the tooltip over the Spot logo.
2011-01-26 Alexandre Duret-Lutz <adl@lrde.epita.fr>
......@@ -17,7 +51,7 @@
* wrap/python/ajax/ltl2tgba.html: Remove the auto-update button, and
enable auto-update automatically after the first submission. Add
tools tips for the "Desired Output" tabs, and the Spot logo.
tools tips for the "Desired Output" tabs, and the Spot logo.
Add a email icon to encourage feedback.
* wrap/python/ajax/ltl2tgba.css: fix sizes of formula field and
send button. Set position of mail icon.
......
// Copyright (C) 2008 Laboratoire de Recherche et Développement
// Copyright (C) 2008, 2011 Laboratoire de Recherche et Développement
// de l'Epita (LRDE).
// Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
// dpartement Systmes Rpartis Coopratifs (SRC), Universit Pierre
......@@ -43,7 +43,7 @@ namespace spot
~evtgba_product_state()
{
for (int j = 0; j < n_; ++j)
delete s_[j];
s_[j]->destroy();
delete[] s_;
}
......
// Copyright (C) 2011 Laboratoire de Recherche et Developpement de
// l'Epita (LRDE).
// Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
// dpartement Systmes Rpartis Coopratifs (SRC), Universit Pierre
// et Marie Curie.
......@@ -40,7 +42,7 @@ namespace spot
// Advance the iterator before deleting the "key" pointer.
const state* ptr = s->first;
++s;
delete ptr;
ptr->destroy();
}
}
......@@ -79,7 +81,7 @@ namespace spot
else
{
process_link(tn, s->second, si);
delete current;
current->destroy();
}
}
delete si;
......
// Copyright (C) 2011 Laboratoire de Recherche et Developpement de
// l'Epita (LRDE).
// Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
// dpartement Systmes Rpartis Coopratifs (SRC), Universit Pierre
// et Marie Curie.
......@@ -48,7 +50,7 @@ namespace spot
{
const state* s = i->current_state();
os_ << " " << quote_unless_bare_word(automata_->format_state(s));
delete s;
s->destroy();
}
os_ << ";" << std::endl;
delete i;
......@@ -69,7 +71,7 @@ namespace spot
<< ",";
output_acc_set(si->current_acceptance_conditions());
os_ << ";" << std::endl;
delete dest;
dest->destroy();
}
}
......
// Copyright (C) 2009 Laboratoire de Recherche et Développement
// Copyright (C) 2009, 2011 Laboratoire de Recherche et Developpement
// de l'Epita (LRDE).
// Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
// dpartement Systmes Rpartis Coopratifs (SRC), Universit Pierre
......@@ -72,7 +72,7 @@ namespace spot
{
const state* s = si->current_state();
process_state(s, out, 0);
delete s;
s->destroy();
}
rsymbol_set ss = acc_to_symbol_set(si->current_acceptance_conditions());
......
// Copyright (C) 2009, 2010 Laboratoire de Recherche et Développement
// Copyright (C) 2009, 2010, 2011 Laboratoire de Recherche et Développement
// de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
......@@ -220,7 +220,8 @@ namespace spot
{
bdd c = iterator->current_condition();
if ((c & condition) != bddfalse)
state_list.push_back(shared_state(iterator->current_state()));
state_list.push_back(shared_state(iterator->current_state(),
shared_state_deleter));
}
delete iterator;
......@@ -399,12 +400,14 @@ namespace spot
saba_state_complement_tgba* new_init;
if (automaton_->state_is_accepting(original_init_state))
new_init =
new saba_state_complement_tgba(shared_state(original_init_state),
new saba_state_complement_tgba(shared_state(original_init_state,
shared_state_deleter),
2 * nb_states_,
the_acceptance_cond_);
else
new_init =
new saba_state_complement_tgba(shared_state(original_init_state),
new saba_state_complement_tgba(shared_state(original_init_state,
shared_state_deleter),
2 * nb_states_,
bddfalse);
......
// Copyright (C) 2009 Laboratoire de Recherche et Développement
// Copyright (C) 2009, 2011 Laboratoire de Recherche et Développement
// de l'Epita (LRDE).
// Copyright (C) 2003, 2004 Laboratoire d'Informatique de Paris 6
// (LIP6), département Systèmes Répartis Coopératifs (SRC), Université
......@@ -74,6 +74,27 @@ namespace spot
/// Duplicate a state.
virtual state* clone() const = 0;
/// \brief Release a state.
///
/// Methods from the tgba or tgba_succ_iterator always return a
/// new state that you should deallocate with this function.
/// Before Spot 0.7, you had to "delete" your state directly.
/// Starting with Spot 0.7, you update your code to this function
/// instead (which simply calls "delete"). In a future version,
/// some subclasses will redefine destroy() to allow better memory
/// management (e.g. no memory allocation for explicit automata).
virtual void destroy() const
{
delete this;
}
// FIXME: Make the destructor protected after Spot 0.7.
//protected:
/// \brief Destructor.
///
/// \deprecated Client code should now call
/// <code>s->destroy();</code> instead of <code>delete s;</code>.
virtual ~state()
{
}
......@@ -156,6 +177,8 @@ namespace spot
typedef boost::shared_ptr<const state> shared_state;
inline void shared_state_deleter(state* s) { s->destroy(); }
/// \brief Strict Weak Ordering for \c shared_state
/// (shared_ptr<const state*>).
/// \ingroup tgba_essentials
......
// Copyright (C) 2011 Laboratoire de Recherche et Developpement de
// l'EPITA (LRDE).
// Copyright (C) 2003, 2004, 2005 Laboratoire d'Informatique de Paris 6 (LIP6),
// dpartement Systmes Rpartis Coopratifs (SRC), Universit Pierre
// et Marie Curie.
......@@ -32,8 +34,10 @@ namespace spot
tgba::~tgba()
{
delete last_support_conditions_input_;
delete last_support_variables_input_;
if (last_support_conditions_input_)
last_support_conditions_input_->destroy();
if (last_support_variables_input_)
last_support_variables_input_->destroy();
}
bdd
......@@ -43,7 +47,8 @@ namespace spot
|| last_support_conditions_input_->compare(state) != 0)
{
last_support_conditions_output_ = compute_support_conditions(state);
delete last_support_conditions_input_;
if (last_support_conditions_input_)
last_support_conditions_input_->destroy();
last_support_conditions_input_ = state->clone();
}
return last_support_conditions_output_;
......@@ -56,7 +61,8 @@ namespace spot
|| last_support_variables_input_->compare(state) != 0)
{
last_support_variables_output_ = compute_support_variables(state);
delete last_support_variables_input_;
if (last_support_variables_input_)
last_support_variables_input_->destroy();
last_support_variables_input_ = state->clone();
}
return last_support_variables_output_;
......
// Copyright (C) 2009, 2010 Laboratoire de Recherche et Développement
// Copyright (C) 2009, 2010, 2011 Laboratoire de Recherche et Développement
// de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
......@@ -443,7 +443,7 @@ namespace spot
bdd c = iterator->current_condition();
if ((c & condition) != bddfalse)
{
shared_state s(iterator->current_state());
shared_state s(iterator->current_state(), shared_state_deleter);
if (highest_current_ranks_.find(s) != highest_current_ranks_.end())
{
if (i->second < highest_current_ranks_[s])
......@@ -470,7 +470,7 @@ namespace spot
bdd c = iterator->current_condition();
if ((c & condition) != bddfalse)
{
shared_state s(iterator->current_state());
shared_state s(iterator->current_state(), shared_state_deleter);
highest_state_set_.insert(s);
}
}
......@@ -621,7 +621,8 @@ namespace spot
{
state_kv_complement* init = new state_kv_complement();
rank_t r = {2 * nb_states_, bdd_ordered()};
init->add(shared_state(automaton_->get_init_state()), r);
init->add(shared_state(automaton_->get_init_state(), shared_state_deleter),
r);
return init;
}
......
......@@ -41,8 +41,8 @@ namespace spot
state_product::~state_product()
{
delete left_;
delete right_;
left_->destroy();
right_->destroy();
}
int
......
// Copyright (C) 2008, 2009 Laboratoire de Recherche et Développement
// de l'Epita (LRDE).
// Copyright (C) 2008, 2009, 2011 Laboratoire de Recherche et
// Developpement de l'Epita (LRDE).
// Copyright (C) 2004, 2005 Laboratoire d'Informatique de Paris
// 6 (LIP6), département Systèmes Répartis Coopératifs (SRC),
// Université Pierre et Marie Curie.
......@@ -156,7 +156,7 @@ namespace spot
spot::state* init = automata_->get_init_state();
if (init->compare(s) == 0)
this->set_init_state(automata_->format_state(s));
delete init;
init->destroy();
transition* t;
for (si->first(); !si->done(); si->next())
......@@ -165,7 +165,7 @@ namespace spot
t = this->create_transition(s, init);
this->add_conditions(t, si->current_condition());
this->add_acceptance_conditions(t, si->current_acceptance_conditions());
delete init;
init->destroy();
}
}
......@@ -361,7 +361,7 @@ namespace spot
sim1 = sim2;
sim2 = simtmp;
}
delete init;
init->destroy();
sp_map::iterator i = state_predecessor_map_.find(s1);
if (i == state_predecessor_map_.end()) // 0 predecessor
......
// Copyright (C) 2009, 2010 Laboratoire de Recherche et Développement
// Copyright (C) 2009, 2010, 2011 Laboratoire de Recherche et Développement
// de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
......@@ -170,7 +170,7 @@ namespace spot
delete *i;
for (subset_t::iterator i = nodes.begin(); i != nodes.end(); ++i)
delete *i;
(*i)->destroy();
}
const safra_tree&
......@@ -403,7 +403,7 @@ namespace spot
const state* s = *node_it;
(*child_it)->remove_node_from_children(*node_it);
(*child_it)->nodes.erase(node_it++);
delete s;
s->destroy();
}
else
{
......@@ -431,7 +431,7 @@ namespace spot
{
const spot::state* s = *it;
(*child_it)->nodes.erase(it);
delete s;
s->destroy();
}
(*child_it)->remove_node_from_children(state);
}
......@@ -679,7 +679,7 @@ namespace spot
for (safra_tree::tr_cache_t::iterator j = i->second.begin();
j != i->second.end();
++j)
delete j->second;
j->second->destroy();
// delete node;
}
......
// Copyright (C) 2009 Laboratoire de Recherche et Développement
// Copyright (C) 2009, 2011 Laboratoire de Recherche et Développement
// de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
......@@ -48,7 +48,7 @@ namespace spot
virtual
~state_sgba_proxy()
{
delete s_;
s_->destroy();
}
state*
......
// Copyright (C) 2010 Laboratoire de Recherche et Développement de
// Copyright (C) 2010, 2011 Laboratoire de Recherche et Développement de
// l'Epita.
// Copyright (C) 2003, 2004, 2005 Laboratoire d'Informatique de Paris
// 6 (LIP6), département Systèmes Répartis Coopératifs (SRC),
......@@ -56,7 +56,7 @@ namespace spot
virtual
~state_tba_proxy()
{
delete s_;
s_->destroy();
}
state*
......@@ -204,7 +204,7 @@ namespace spot
else // Yes, combine labels.
{
id->second |= it->current_condition();
delete dest;
dest->destroy();
}
}
delete it;
......@@ -219,7 +219,7 @@ namespace spot
const state* d = i->first.first;
// Advance i before deleting d.
++i;
delete d;
d->destroy();
}
}
......@@ -318,7 +318,7 @@ namespace spot
// Advance the iterator before deleting the key.
const state* s = i->first;
++i;
delete s;
s->destroy();
}
}
......@@ -452,15 +452,15 @@ namespace spot
// duplication of the initial state.
// The cycle_start_ points to the right starting
// point already, so just return.
delete dest;
dest->destroy();
delete it;
delete init;
init->destroy();
return;
}
delete dest;
dest->destroy();
}
delete it;
delete init;
init->destroy();
}
// If we arrive here either because the number of acceptance
......
// Copyright (C) 2009 Laboratoire de Recherche et Développement
// Copyright (C) 2009, 2011 Laboratoire de Recherche et Développement
// de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
......@@ -38,8 +38,8 @@ namespace spot
state_union::~state_union()
{
delete left_;
delete right_;
left_->destroy();
right_->destroy();
}
int
......@@ -293,8 +293,8 @@ namespace spot
right_acc_missing_,
left_var_missing_,
right_var_missing_);
delete left_init;
delete right_init;
left_init->destroy();
right_init->destroy();
}
else
{
......
......@@ -44,7 +44,8 @@ namespace spot
virtual
~state_wdba_comp_proxy()
{
delete s_;
if (s_)
s_->destroy();
}
state*
......
// Copyright (C) 2009 Laboratoire de Recherche et Developpement de
// l'Epita (LRDE).
// Copyright (C) 2009, 2011 Laboratoire de Recherche et Developpement
// de l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
//
......@@ -72,7 +72,7 @@ namespace spot
}
else
{
delete dst;
dst->destroy();
}
tgba_explicit::transition* t =
sub_a->create_transition(cur_format, dst_format);
......@@ -83,7 +83,7 @@ namespace spot
}
else
{
delete dst;
dst->destroy();
}
}
delete sit;
......@@ -93,7 +93,7 @@ namespace spot
// Free visited states.
for (it2 = seen.begin(); it2 != seen.end(); it2++)
{
delete *it2;
(*it2)->destroy();
}
return sub_a;
}
......@@ -255,7 +255,7 @@ namespace spot
scc_sizes[i] = m.states_of(i).size();
state* initial_state = a->get_init_state();
unsigned init = m.scc_of_state(initial_state);
delete initial_state;
initial_state->destroy();
// Find all interesting pathes in our automaton.
find_paths_sub(init, m, d, scc_sizes);
......@@ -272,7 +272,7 @@ namespace spot
std::vector<std::vector<sccs_set* > >* rec_paths = find_paths(a, m);
state* initial_state = a->get_init_state();
unsigned init = m.scc_of_state(initial_state);
delete initial_state;
initial_state->destroy();
std::vector<sccs_set*>* final_sets =&(*rec_paths)[init];
if (rec_paths->empty())
{
......
// Copyright (C) 2009 Laboratoire de Recherche et Dveloppement
// Copyright (C) 2009, 2011 Laboratoire de Recherche et Dveloppement
// de l'Epita (LRDE).
// Copyright (C) 2004, 2005 Laboratoire d'Informatique de Paris 6 (LIP6),
// dpartement Systmes Rpartis Coopratifs (SRC), Universit Pierre
......@@ -42,9 +42,9 @@ namespace spot
tgba_run::~tgba_run()
{
for (steps::const_iterator i = prefix.begin(); i != prefix.end(); ++i)
delete i->s;
i->s->destroy();
for (steps::const_iterator i = cycle.begin(); i != cycle.end(); ++i)
delete i->s;
i->s->destroy();
}
tgba_run::tgba_run(const tgba_run& run)
......@@ -345,7 +345,7 @@ namespace spot
// browse the actual outgoing transitions
tgba_succ_iterator* j = a->succ_iter(s);
delete s;
s->destroy(); // FIXME: is it always legitimate to destroy s before j?
for (j->first(); !j->done(); j->next())
{
if (j->current_condition() != label
......@@ -355,7 +355,7 @@ namespace spot
const state* s2 = j->current_state();
if (s2->compare(next) != 0)
{
delete s2;
s2->destroy();
continue;
}
else
......@@ -386,7 +386,7 @@ namespace spot
if (l == &run->cycle && i != l->begin())
seen_acc |= acc;
}
delete s;
s->destroy();
assert(seen_acc == a->all_acceptance_conditions());
......
// Copyright (C) 2010, 2011 Laboratoire de Recherche et Développement de
// l'Epita (LRDE).
// Copyright (C) 2004, 2005 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
// et Marie Curie.
// Copyright (C) 2010 Laboratoire de Recherche et Développement de
// l'Epita (LRDE).
//
// This file is part of Spot, a model checking library.
//
......@@ -55,7 +55,7 @@ namespace spot
// Ignore unknown states ...
if (!sip.first)
{
delete s;
s->destroy();
return 0;
}
// ... as well as dead states.
......@@ -129,7 +129,7 @@ namespace spot
if (ps != ss.end())
{
// The initial state is on the cycle.
delete prefix_start;
prefix_start->destroy();
cycle_entry_point = *ps;
}
else
......@@ -198,7 +198,7 @@ namespace spot
// Ignore unknown states.
if (!sip.first)
{
delete s;
s->destroy();
return 0;
}
// Stay in the final SCC.
......
// Copyright (C) 2011 Laboratoire de Recherche et Developpement de
// l'Epita (LRDE).
// Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
// et Marie Curie.
......@@ -30,7 +32,7 @@ namespace spot
if (it != states.end())
{
if (s != *it)
delete s;
s->destroy();
return *it;
}
else
......
Markdown is supported
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