From: Morgan Deters Date: Mon, 6 Jun 2011 21:37:23 +0000 (+0000) Subject: Fix for Mac OS breakage (x86 didn't crash, but probably would, eventually, on some... X-Git-Tag: cvc5-1.0.0~8533 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e64686fed86068e977ac84c5776438935f446f00;p=cvc5.git Fix for Mac OS breakage (x86 didn't crash, but probably would, eventually, on some problems---valgrind gave many complaints): the problem was that calloc() (in the Backtracker) wasn't allocating enough space for the type located at the resulting address. Resolves bug #263. Also, some debugging improvements. --- diff --git a/src/context/context.h b/src/context/context.h index aabe4e7c2..6375707b9 100644 --- a/src/context/context.h +++ b/src/context/context.h @@ -577,7 +577,7 @@ public: * ContextMemoryManager as an argument. */ void deleteSelf() { - Debug("context") << "deleteSelf(" << this << ")" << std::endl; + Debug("context") << "deleteSelf(" << this << ") " << typeid(*this).name() << std::endl; this->~ContextObj(); ::operator delete(this); } diff --git a/src/expr/node_builder.h b/src/expr/node_builder.h index cc7e89bc8..95f7c0437 100644 --- a/src/expr/node_builder.h +++ b/src/expr/node_builder.h @@ -900,8 +900,12 @@ expr::NodeValue* NodeBuilder::constructNV() { nv->d_id = expr::NodeValue::next_id++;// FIXME multithreading nv->d_rc = 0; setUsed(); - Debug("gc") << "creating node value " << nv - << " [" << nv->d_id << "]: " << *nv << "\n"; + if(Debug.isOn("gc")) { + Debug("gc") << "creating node value " << nv + << " [" << nv->d_id << "]: "; + nv->printAst(Debug("gc")); + Debug("gc") << std::endl; + } return nv; } @@ -982,8 +986,12 @@ expr::NodeValue* NodeBuilder::constructNV() { //poolNv = nv; d_nm->poolInsert(nv); - Debug("gc") << "creating node value " << nv - << " [" << nv->d_id << "]: " << *nv << "\n"; + if(Debug.isOn("gc")) { + Debug("gc") << "creating node value " << nv + << " [" << nv->d_id << "]: "; + nv->printAst(Debug("gc")); + Debug("gc") << std::endl; + } return nv; } } else { diff --git a/src/expr/node_manager.cpp b/src/expr/node_manager.cpp index 4cde0c624..95124d297 100644 --- a/src/expr/node_manager.cpp +++ b/src/expr/node_manager.cpp @@ -202,8 +202,12 @@ void NodeManager::reclaimZombies() { // collect ONLY IF still zero if(nv->d_rc == 0) { - Debug("gc") << "deleting node value " << nv - << " [" << nv->d_id << "]: " << *nv << "\n"; + if(Debug.isOn("gc")) { + Debug("gc") << "deleting node value " << nv + << " [" << nv->d_id << "]: "; + nv->printAst(Debug("gc")); + Debug("gc") << std::endl; + } // remove from the pool kind::MetaKind mk = nv->getMetaKind(); diff --git a/src/expr/node_manager.h b/src/expr/node_manager.h index 9974df6ca..54266db13 100644 --- a/src/expr/node_manager.h +++ b/src/expr/node_manager.h @@ -185,10 +185,13 @@ class NodeManager { // if d_reclaiming is set, make sure we don't call // reclaimZombies(), because it's already running. - Debug("gc") << "zombifying node value " << nv - << " [" << nv->d_id << "]: " << *nv - << (d_inReclaimZombies ? " [CURRENTLY-RECLAIMING]" : "") - << std::endl; + if(Debug.isOn("gc")) { + Debug("gc") << "zombifying node value " << nv + << " [" << nv->d_id << "]: "; + nv->printAst(Debug("gc")); + Debug("gc") << (d_inReclaimZombies ? " [CURRENTLY-RECLAIMING]" : "") + << std::endl; + } d_zombies.insert(nv);// FIXME multithreading if(!d_inReclaimZombies) {// FIXME multithreading @@ -1269,8 +1272,12 @@ NodeClass NodeManager::mkConstInternal(const T& val) { new (&nv->d_children) T(val); poolInsert(nv); - Debug("gc") << "creating node value " << nv - << " [" << nv->d_id << "]: " << *nv << "\n"; + if(Debug.isOn("gc")) { + Debug("gc") << "creating node value " << nv + << " [" << nv->d_id << "]: "; + nv->printAst(Debug("gc")); + Debug("gc") << std::endl; + } return NodeClass(nv); } diff --git a/src/util/backtrackable.h b/src/util/backtrackable.h index b11ebf957..418172235 100644 --- a/src/util/backtrackable.h +++ b/src/util/backtrackable.h @@ -1,3 +1,4 @@ +/********************* */ /*! \file backtrackable.h ** \verbatim ** Original author: lianah @@ -12,26 +13,26 @@ ** ** \brief Contains a backtrackable list ** - ** + ** Contains a backtrackable list. **/ #include "cvc4_private.h" + #ifndef __CVC4__UTIL__BACKTRACKABLE_H #define __CVC4__UTIL__BACKTRACKABLE_H - #include #include #include "context/cdo.h" -namespace CVC4{ +namespace CVC4 { template class List; template class List_iterator; template class Backtracker; template -class ListNode{ +class ListNode { private: T data; ListNode* next; @@ -45,10 +46,10 @@ private: friend class List; friend class List_iterator; -}; /*class ListNode */ +};/* class ListNode */ template -class List_iterator: public std::iterator { +class List_iterator : public std::iterator { friend class List; public: @@ -56,17 +57,20 @@ public: List_iterator& operator++(); List_iterator operator++(int); bool operator!=(const List_iterator & other) const; + private: const ListNode* pointee; List_iterator(const ListNode* p) : pointee(p) {} -}; /* class List_iterator */ +};/* class List_iterator */ -template const T& List_iterator::operator*() { +template +const T& List_iterator::operator*() { return pointee->data; } -template List_iterator& List_iterator::operator++() { +template +List_iterator& List_iterator::operator++() { Assert(pointee != NULL); pointee = pointee->next; while(pointee != NULL && pointee->empty ) { @@ -75,19 +79,22 @@ template List_iterator& List_iterator::operator++() { return *this; } -template List_iterator List_iterator::operator++(int) { +template +List_iterator List_iterator::operator++(int) { List_iterator it = *this; ++*this; return it; } -template bool List_iterator::operator!=(const List_iterator& other) const { +template +bool List_iterator::operator!=(const List_iterator& other) const { return (this->pointee != other.pointee); } // !! for the backtracking to work the lists must be allocated on the heap // therefore the hashmap from TNode to List should store pointers! -template class List { +template +class List { ListNode* head; ListNode* tail; ListNode* ptr_to_head; @@ -96,7 +103,7 @@ template class List { List (const List&) {} public: List(Backtracker* b) : ptr_to_head(NULL), uninitialized(true), bck(b) { - head = tail = (ListNode*)calloc(1,sizeof(ListNode*)); + head = tail = (ListNode*)calloc(1,sizeof(ListNode)); head->next = NULL; head->empty = true; } @@ -128,7 +135,7 @@ public: } void concat(List* other); void unconcat(List* other); -}; /* class List */ +};/* class List */ template void List::append (const T& d) { @@ -174,7 +181,8 @@ void List::unconcat(List* other) { /* Backtrackable Table */ -template class Backtracker { +template +class Backtracker { friend class List; std::vector*,List*> > undo_stack; @@ -187,7 +195,7 @@ public: Backtracker(context::Context* c) : undo_stack(), curr_level(0), pop_level(c, 0) {} ~Backtracker() {} -}; /*class Backtrackable */ +};/* class Backtrackable */ template void Backtracker::notifyConcat(List* a, List* b) { curr_level++; @@ -210,5 +218,7 @@ template void Backtracker::checkConsistency() { } Assert(curr_level == pop_level); } -} /* CVC4 namespace */ + +}/* CVC4 namespace */ + #endif /* __CVC4__UTIL__BACKTRACKABLE_H */ diff --git a/src/util/stats.cpp b/src/util/stats.cpp index 428f051e0..70d486ff6 100644 --- a/src/util/stats.cpp +++ b/src/util/stats.cpp @@ -32,7 +32,8 @@ StatisticsRegistry* StatisticsRegistry::current() { void StatisticsRegistry::registerStat(Stat* s) throw(AssertionException) { #ifdef CVC4_STATISTICS_ON StatSet& registeredStats = NodeManager::currentNM()->getStatisticsRegistry()->d_registeredStats; - AlwaysAssert(registeredStats.find(s) == registeredStats.end()); + AlwaysAssert(registeredStats.find(s) == registeredStats.end(), + "Statistic `%s' was already registered with this registry.", s->getName().c_str()); registeredStats.insert(s); #endif /* CVC4_STATISTICS_ON */ }/* StatisticsRegistry::registerStat() */ @@ -40,7 +41,8 @@ void StatisticsRegistry::registerStat(Stat* s) throw(AssertionException) { void StatisticsRegistry::unregisterStat(Stat* s) throw(AssertionException) { #ifdef CVC4_STATISTICS_ON StatSet& registeredStats = NodeManager::currentNM()->getStatisticsRegistry()->d_registeredStats; - AlwaysAssert(registeredStats.find(s) != registeredStats.end()); + AlwaysAssert(registeredStats.find(s) != registeredStats.end(), + "Statistic `%s' was not registered with this registry.", s->getName().c_str()); registeredStats.erase(s); #endif /* CVC4_STATISTICS_ON */ }/* StatisticsRegistry::unregisterStat() */