From: Roland McGrath Date: Fri, 30 Jan 2009 03:06:25 +0000 (-0800) Subject: Fix container equality tests to handle size mismatch. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e37557dd6437762352ca51bbef7289bb1d9138e7;p=thirdparty%2Felfutils.git Fix container equality tests to handle size mismatch. --- diff --git a/libdw/c++/dwarf b/libdw/c++/dwarf index fc07c5d25..9ceb4b40a 100644 --- a/libdw/c++/dwarf +++ b/libdw/c++/dwarf @@ -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 bool operator== (const other_children &other) const { - return std::equal (begin (), end (), other.begin ()); + return subr::container_equal (*this, other); } template 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 bool operator== (const other_children &other) const { - return std::equal (begin (), end (), other.begin ()); + return subr::container_equal (*this, other); } template 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 ()); + return subr::container_equal + (++i, end (), ++j, other.end (), + name_equal ()); } public: @@ -1528,7 +1537,7 @@ namespace elfutils template inline bool operator== (const table &other) const { - return std::equal (begin (), end (), other.begin ()); + return subr::container_equal (*this, other); } template 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. + // with a read-only subset of std::list. 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 bool operator== (const units &other) const { - return std::equal (begin (), end (), other.begin ()); + return subr::container_equal (*this, other); } template bool operator!= (const units &other) const diff --git a/libdw/c++/dwarf_edit b/libdw/c++/dwarf_edit index 630a70921..3235199bf 100644 --- a/libdw/c++/dwarf_edit +++ b/libdw/c++/dwarf_edit @@ -101,12 +101,17 @@ namespace elfutils template children (const childrens &other) : std::list (other.begin (), other.end ()) {} + + public: + typedef debug_info_entry value_type; }; class attributes : public std::map { friend class debug_info_entry; private: + typedef std::map base_type; + attributes () {} template @@ -114,6 +119,10 @@ namespace elfutils : std::map (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 inline operator attrs () const { @@ -221,6 +230,8 @@ namespace elfutils {} public: + typedef compile_unit value_type; + inline compile_unit &new_unit () { compile_unit nu; diff --git a/libdw/c++/subr.hh b/libdw/c++/subr.hh index 070b3cd1f..a7ac42e98 100644 --- a/libdw/c++/subr.hh +++ b/libdw/c++/subr.hh @@ -6,11 +6,43 @@ #define _ELFUTILS_SUBR_HH 1 #include +#include namespace elfutils { namespace subr { + template + struct equal_to : public std::binary_function + { + inline bool operator () (const t1 &a, const t2 &b) + { + return a == b; + } + }; + + template + 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 + 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 ()); + } template class indexed_iterator