Added IdString::destruct_guard hack
authorClifford Wolf <clifford@clifford.at>
Thu, 11 Dec 2014 20:46:36 +0000 (21:46 +0100)
committerClifford Wolf <clifford@clifford.at>
Thu, 11 Dec 2014 20:46:36 +0000 (21:46 +0100)
kernel/rtlil.cc
kernel/rtlil.h

index f5dbafe1615f30bcddfe070f70ea7f7e2ecb678b..5c010dabfca9403c4a5e14e46f1621aa3ee2cd18 100644 (file)
@@ -27,6 +27,7 @@
 
 YOSYS_NAMESPACE_BEGIN
 
+RTLIL::IdString::destruct_guard_t RTLIL::IdString::destruct_guard;
 std::vector<int> RTLIL::IdString::global_refcount_storage_;
 std::vector<char*> RTLIL::IdString::global_id_storage_;
 std::map<char*, int, RTLIL::IdString::char_ptr_cmp> RTLIL::IdString::global_id_index_;
index 0157f3b7cd6b1321e2c02c3475b7992f4e03f0e5..29fa90692b32b895e227ebafab8bc778806cd2b9 100644 (file)
@@ -85,6 +85,12 @@ namespace RTLIL
                        }
                };
 
+               static struct destruct_guard_t {
+                       bool ok = false;
+                       destruct_guard_t() { ok = true; }
+                       ~destruct_guard_t() { ok = false; }
+               } destruct_guard;
+
                static std::vector<int> global_refcount_storage_;
                static std::vector<char*> global_id_storage_;
                static std::map<char*, int, char_ptr_cmp> global_id_index_;
@@ -98,6 +104,8 @@ namespace RTLIL
 
                static inline int get_reference(const char *p)
                {
+                       log_assert(destruct_guard.ok);
+
                        if (p[0]) {
                                log_assert(p[1] != 0);
                                log_assert(p[0] == '$' || p[0] == '\\');
@@ -126,6 +134,11 @@ namespace RTLIL
 
                static inline void put_reference(int idx)
                {
+                       // put_reference() may be called from destructors after the destructor of
+                       // global_refcount_storage_ has been run. in this case we simply do nothing.
+                       if (!destruct_guard.ok)
+                               return;
+
                        log_assert(global_refcount_storage_.at(idx) > 0);
 
                        if (--global_refcount_storage_.at(idx) != 0)