summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsbrandt <sbrandt@17b73243-c579-4c4c-a9d2-2d5706c11dac>2014-01-13 21:56:07 +0000
committersbrandt <sbrandt@17b73243-c579-4c4c-a9d2-2d5706c11dac>2014-01-13 21:56:07 +0000
commit1f4618cad94f362422c552338c6fe83998a5d329 (patch)
tree17f4fc80419fe19ae8fb5244b8894270dc521738
parent00174f686ddbd11ea904bbf0e1413983de7eddb6 (diff)
Fix for #1363
git-svn-id: http://svn.cactuscode.org/flesh/trunk@5064 17b73243-c579-4c4c-a9d2-2d5706c11dac
-rw-r--r--src/piraha/smart_ptr.cc2
-rw-r--r--src/piraha/smart_ptr.hpp45
2 files changed, 27 insertions, 20 deletions
diff --git a/src/piraha/smart_ptr.cc b/src/piraha/smart_ptr.cc
index 112e0f62..c6600d6f 100644
--- a/src/piraha/smart_ptr.cc
+++ b/src/piraha/smart_ptr.cc
@@ -2,6 +2,6 @@
namespace cctki_piraha {
-std::set<void*> *ptrs = new std::set<void*>();
+std::set<void*> *ptrs = 0;
}
diff --git a/src/piraha/smart_ptr.hpp b/src/piraha/smart_ptr.hpp
index b8784b55..1d9dcf6f 100644
--- a/src/piraha/smart_ptr.hpp
+++ b/src/piraha/smart_ptr.hpp
@@ -10,34 +10,41 @@
namespace cctki_piraha {
+// This global debug variable is used to detect the case
+// where the same pointer is accidentally tracked by two
+// independent smart_ptr_guts objects.
+//
+// This can come about if the programmer does this:
+// foo *f = new foo();
+// smart_ptr<foo> f1(f);
+// smart_ptr<foo> f2(f);
extern std::set<void*> *ptrs;
-// TODO: This code is disabled because it leads to segfaults during
-// startup. Most likely, this code is used during initialisation of
-// global variables, but also implicitly assumes that all global
-// variables have already been initialised.
-#if 0
-//#ifndef NDEBUG
-inline void add(std::set<void*>& v,void *t) {
+#ifndef NDEBUG
+inline void add(void *t) {
if(t == NULL)
return;
+ if(ptrs == 0)
+ ptrs = new std::set<void*>();
// TODO: Don't separate finding and inserting; do it in one go to
// save a lookup.
- assert(v.find(t) == v.end());
- v.insert(t);
+ assert(ptrs->find(t) == ptrs->end());
+ ptrs->insert(t);
}
-inline void remove(std::set<void*>& v,void* t) {
- // TODO: Don't separate finding and erasing; do it in one go
- // to save a lookup.
- std::set<void*>::iterator it = v.find(t);
- assert(it != v.end());
- v.erase(it);
+inline void remove(void* t) {
+ if(t == NULL)
+ return;
+ // TODO: Don't separate finding and erasing; do it in one go
+ // to save a lookup.
+ std::set<void*>::iterator it = ptrs->find(t);
+ assert(it != ptrs->end());
+ ptrs->erase(it);
}
#else
-inline void add(std::set<void*>& v,void* t) {
+inline void add(void* t) {
}
-inline void remove(std::set<void*>& v,void* t) {
+inline void remove(void* t) {
}
#endif
@@ -52,12 +59,12 @@ class smart_ptr_guts {
bool array;
smart_ptr_guts(int rc,T *p,bool array_) : ref_count(rc), ptr(p), array(array_) {
if(ptr != NULL) {
- add(*ptrs,(void*)ptr);
+ add((void*)ptr);
}
}
~smart_ptr_guts() {
if(ptr != NULL) {
- remove(*ptrs,(void*)ptr);
+ remove((void*)ptr);
if(array)
delete[] ptr;
else