public inbox for libabigail@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Bug 22075 data_member_diff_comp comparison functor isn't a total ordering.
@ 2017-01-01  0:00 Mark Wielaard
  2017-01-01  0:00 ` Dodji Seketeli
  0 siblings, 1 reply; 9+ messages in thread
From: Mark Wielaard @ 2017-01-01  0:00 UTC (permalink / raw)
  To: libabigail; +Cc: Mark Wielaard

Make data_member_diff_comp comparison functor a total ordering.
The initial value offset can be similar, in that case order based
on the offset of the second instance, or if those are also equal
order based on the qualified name.

This makes sure that offset change reports have a stable ordering.
Makes the runtestdiffpkg testcase succeeds on debian-i386.

	* src/abg-comparison.cc (data_member_diff_comp): Make comparison
	functor a total ordering.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 src/abg-comparison.cc | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/src/abg-comparison.cc b/src/abg-comparison.cc
index 8747e0c..70221e6 100644
--- a/src/abg-comparison.cc
+++ b/src/abg-comparison.cc
@@ -6731,7 +6731,8 @@ sort_string_base_diff_sptr_map(const string_base_diff_sptr_map& map,
 
 /// A comparison functor to compare two instances of @ref var_diff
 /// that represent changed data members based on the offset of their
-/// initial value.
+/// initial value, or if equal based on the offset of their second
+/// instance, of if those are also equal, based on their name.
 struct data_member_diff_comp
 {
   /// @param f the first change to data member to take into account
@@ -6749,7 +6750,29 @@ struct data_member_diff_comp
     assert(is_data_member(first_dm));
     assert(is_data_member(second_dm));
 
-    return get_data_member_offset(first_dm) < get_data_member_offset(second_dm);
+    size_t off1 = get_data_member_offset(first_dm);
+    size_t off2 = get_data_member_offset(second_dm);
+    if (off1 != off2)
+      return off1 < off2;
+
+    first_dm = f->second_var();
+    second_dm = s->second_var();
+
+    assert(is_data_member(first_dm));
+    assert(is_data_member(second_dm));
+
+    off1 = get_data_member_offset(first_dm);
+    off2 = get_data_member_offset(second_dm);
+
+    if (off1 != off2)
+      return off1 < off2;
+
+    string name1 = first_dm->get_qualified_name();
+    string name2 = second_dm->get_qualified_name();
+
+    assert (name1 != name2);
+
+    return name1 < name2;
   }
 }; // end struct var_diff_comp
 
-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-09-18 21:48 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-01  0:00 [PATCH] Bug 22075 data_member_diff_comp comparison functor isn't a total ordering Mark Wielaard
2017-01-01  0:00 ` Dodji Seketeli
2017-01-01  0:00   ` Mark Wielaard
2017-01-01  0:00     ` Dodji Seketeli
2017-01-01  0:00       ` Mark Wielaard
2017-01-01  0:00         ` Dodji Seketeli
2017-01-01  0:00           ` Mark Wielaard
2017-01-01  0:00             ` Dodji Seketeli
2017-01-01  0:00         ` Mark Wielaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).