]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Fix container equality tests to handle size mismatch.
authorRoland McGrath <roland@redhat.com>
Fri, 30 Jan 2009 03:06:25 +0000 (19:06 -0800)
committerRoland McGrath <roland@redhat.com>
Fri, 30 Jan 2009 03:06:25 +0000 (19:06 -0800)
libdw/c++/dwarf
libdw/c++/dwarf_edit
libdw/c++/subr.hh

index fc07c5d25f816eadafbe6ba4b144298051194158..9ceb4b40a964fa8a151ceb3d762bcee87dc2e8a3 100644 (file)
@@ -471,6 +471,8 @@ namespace elfutils
       inline raw_children (const debug_info_entry &die) : _m_die (die) {}
 
     public:
+      typedef debug_info_entry value_type;
+
       inline raw_children (const raw_children &c) : _m_die (c._m_die) {}
 
       bool empty () const
@@ -555,7 +557,7 @@ namespace elfutils
       template<typename other_children>
       bool operator== (const other_children &other) const
       {
-       return std::equal (begin (), end (), other.begin ());
+       return subr::container_equal (*this, other);
       }
       template<typename other_children>
       bool operator!= (const other_children &other) const
@@ -576,6 +578,8 @@ namespace elfutils
       raw_attributes (const debug_info_entry &die) : _m_die (die) {}
 
     public:
+      typedef attribute value_type;
+
       inline raw_attributes (const raw_attributes &a) : _m_die (a._m_die) {}
 
       size_t size () const;
@@ -689,6 +693,8 @@ namespace elfutils
        : raw_children::raw_children (die) {}
 
     public:
+      typedef debug_info_entry value_type;
+
       inline children (const children &c) : raw_children (c) {}
 
       class const_iterator
@@ -796,7 +802,7 @@ namespace elfutils
       template<typename other_children>
       bool operator== (const other_children &other) const
       {
-       return std::equal (begin (), end (), other.begin ());
+       return subr::container_equal (*this, other);
       }
       template<typename other_children>
       bool operator!= (const other_children &other) const
@@ -829,6 +835,8 @@ namespace elfutils
        : attributes_base (raw) {}
 
     public:
+      typedef attribute value_type;
+
       inline attributes (const class attributes &a)
        : attributes_base (a) {}
 
@@ -1301,8 +1309,9 @@ namespace elfutils
           The directory table itself matches regardless.  */
        const_iterator i = begin ();
        typename table::const_iterator j = other.begin ();
-       return std::equal (++i, end (), ++j,
-                          name_equal<typename table::value_type> ());
+       return subr::container_equal
+         (++i, end (), ++j, other.end (),
+          name_equal<typename table::value_type> ());
       }
 
     public:
@@ -1528,7 +1537,7 @@ namespace elfutils
       template<typename table>
       inline bool operator== (const table &other) const
       {
-       return std::equal (begin (), end (), other.begin ());
+       return subr::container_equal (*this, other);
       }
       template<typename table>
       inline bool operator!= (const table &other) const
@@ -1539,7 +1548,7 @@ namespace elfutils
       inline bool operator== (const line_table &other) const
       {
        return (_m_lines == other._m_lines
-               || std::equal (begin (), end (), other.begin ()));
+               || subr::container_equal (*this, other));
       }
 
       // Look up by matching address.
@@ -1798,7 +1807,7 @@ namespace elfutils
     };
 
     // Container for raw CUs in file order, intended to be compatible
-    // with a read-only subset of std::list<raw_compile_unit>.
+    // with a read-only subset of std::list<compile_unit>.
     class raw_compile_units
     {
       friend class dwarf;
@@ -1808,6 +1817,8 @@ namespace elfutils
       raw_compile_units (const dwarf &file) : _m_file (file) {}
 
     public:
+      typedef compile_unit value_type;
+
       inline raw_compile_units (const raw_compile_units &u)
        : _m_file (u._m_file) {}
 
@@ -1914,12 +1925,14 @@ namespace elfutils
       compile_units (class raw_compile_units raw) : compile_units_base (raw) {}
 
     public:
+      typedef compile_unit value_type;
+
       compile_units (const compile_units &u) : compile_units_base (u) {}
 
       template<typename units>
       bool operator== (const units &other) const
       {
-       return std::equal (begin (), end (), other.begin ());
+       return subr::container_equal (*this, other);
       }
       template<typename units>
       bool operator!= (const units &other) const
index 630a70921fa587f3e06fd353a7f6c5de26f4ca53..3235199bf84bbf5e1e18b730b52a6db2573afe9d 100644 (file)
@@ -101,12 +101,17 @@ namespace elfutils
        template<typename childrens>
        children (const childrens &other)
          : std::list<debug_info_entry> (other.begin (), other.end ()) {}
+
+      public:
+       typedef debug_info_entry value_type;
       };
 
       class attributes : public std::map<int, attr_value>
       {
        friend class debug_info_entry;
       private:
+       typedef std::map<int, attr_value> base_type;
+
        attributes () {}
 
        template<typename attrs>
@@ -114,6 +119,10 @@ namespace elfutils
          : std::map<int, attr_value> (other.begin (), other.end ()) {}
 
       public:
+       typedef base_type::key_type key_type;
+       typedef base_type::value_type value_type;
+       typedef base_type::mapped_type mapped_type;
+
        template<typename attrs>
        inline operator attrs () const
        {
@@ -221,6 +230,8 @@ namespace elfutils
       {}
 
     public:
+      typedef compile_unit value_type;
+
       inline compile_unit &new_unit ()
       {
        compile_unit nu;
index 070b3cd1fe8a1e8868c06bd5a577648c80df0994..a7ac42e98c820c26b8f6d0aada4556079e443535 100644 (file)
@@ -6,11 +6,43 @@
 #define _ELFUTILS_SUBR_HH      1
 
 #include <iterator>
+#include <functional>
 
 namespace elfutils
 {
   namespace subr
   {
+    template<typename t1, typename t2>
+    struct equal_to : public std::binary_function<t1, t2, bool>
+    {
+      inline bool operator () (const t1 &a, const t2 &b)
+      {
+       return a == b;
+      }
+    };
+
+    template<typename iter1, typename iter2, typename pred_type>
+    inline bool container_equal (iter1 first1, iter1 last1,
+                                iter2 first2, iter2 last2,
+                                pred_type pred)
+    {
+      while (first1 != last1)
+       if (first2 == last2 || !pred (*first1++, *first2++))
+         return false;
+      return first2 == last2;
+    }
+
+    template<typename t1, typename t2>
+    inline bool container_equal (const t1 &a, const t2 &b)
+    {
+      typename t1::const_iterator first1 = a.begin ();
+      typename t1::const_iterator last1 = a.end ();
+      typename t2::const_iterator first2 = b.begin ();
+      typename t2::const_iterator last2 = b.end ();
+      return container_equal (first1, last1, first2, last2,
+                             equal_to<typename t1::value_type,
+                                      typename t2::value_type> ());
+    }
 
     template<typename array, typename element = typename array::value_type>
     class indexed_iterator