]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Fix copying vs destruction regression.
authorRoland McGrath <roland@redhat.com>
Mon, 17 Aug 2009 02:05:25 +0000 (19:05 -0700)
committerRoland McGrath <roland@redhat.com>
Mon, 17 Aug 2009 02:05:25 +0000 (19:05 -0700)
libdw/c++/dwarf_data
libdw/c++/dwarf_output

index 2a2dead8037649638a19c8c608e3d7ceff2517e3..005fc5dcedfe8a29dd33a574eeffdc24dd037cb6 100644 (file)
@@ -141,6 +141,15 @@ namespace elfutils
                                  require_cu (cu), arg)
       {}
 
+      /* Assignment details are up to the base class.
+        We just ensure it's really a compile_unit.  */
+      inline compile_unit &
+      operator= (const typename impl::debug_info_entry &other)
+      {
+       impl::debug_info_entry::operator= (require_cu (other));
+       return *this;
+      }
+
       // Fetch the CU's DW_AT_stmt_list.
       inline const typename impl::line_info_table &line_info () const
       {
@@ -1200,15 +1209,25 @@ namespace elfutils
        return vw::variant (p, _m_value);
       }
 
+      template<typename value>
+      inline attr_value &copy (const value &other)
+      {
+       if (_m_value != NULL)
+         {
+           delete _m_value;
+           _m_value = NULL;
+         }
+       init<value> me (this, 0, other);
+       return *this;
+      }
+
     public:
-#if 0 // XXX
       attr_value (const attr_value &other)
        : _m_value (NULL)
       {
        if (other._m_value != NULL)
          init<attr_value> me (this, 0, other);
       }
-#endif
 
       inline attr_value ()
        : _m_value (NULL)
@@ -1220,29 +1239,19 @@ namespace elfutils
          delete _m_value;
       }
 
-#if 0 // XXX
-      inline attr_value &operator= (const attr_value &other)
-      {
-       if (_m_value != NULL)
-         {
-           delete _m_value;
-           _m_value = NULL;
-         }
-       init<attr_value> me (this, 0, other);
-       return *this;
-      }
       template<typename value>
       inline attr_value &operator= (const value &other)
       {
-       if (_m_value != NULL)
-         {
-           delete _m_value;
-           _m_value = NULL;
-         }
-       init<value> me (this, 0, other);
-       return *this;
+       return copy (other);
+      }
+
+      /* This is the same as the generic template one,
+        but we have to define it explicitly to override
+        the default assignment operator.  */
+      inline attr_value &operator= (const attr_value &other)
+      {
+       return copy (other);
       }
-#endif
 
       dwarf::value_space what_space () const;
       inline std::string to_string () const;
index db4587d149ab17944f2ad818439172f7ef3e51a2..b03dbd4838f4b631d287bbe66c3f81d964305a46 100644 (file)
@@ -1877,7 +1877,7 @@ namespace elfutils
 
       /* Complain if we still have dangling references.
         If not, it should be impossible to have pending entries left.  */
-      inline void demand_complete () const
+      inline die_info_pair *final () const
       {
        assert (_m_out == NULL);
        if (unlikely (_m_in->_m_final == NULL))
@@ -1888,6 +1888,7 @@ namespace elfutils
              ("compile_unit contains dangling reference attributes");
          }
        assert (_m_copier->_m_defined == _m_copier->_m_seen.size ());
+       return _m_in->_m_final;
       }
 
       // We're adding a reference attribute inside populate, above.
@@ -1945,6 +1946,15 @@ namespace elfutils
       }
     };
 
+    struct unit_copier : public entry_copier
+    {
+      inline unit_copier (copier *c, const typename dw::compile_unit &in)
+       : entry_copier (c, 0, c->enter_seen (in), in)
+      {
+       populate (in);
+      }
+    };
+
     /* Create a whole CU in the output.
      */
     inline void
@@ -1953,11 +1963,7 @@ namespace elfutils
     {
       typename tracker::walk into (_m_tracker, in, out);
 
-      entry_copier maker (this, 0, enter_seen (*in), *in);
-      maker.populate (*in);
-
-      dump_seen ();
-      maker.demand_complete ();
+      *out = unit_copier (this, *in).final ()->first;
     }
 
     typedef std::tr1::unordered_map< ::Dwarf_Off, seen> seen_map;