[PATCH] Bug 22075 data_member_diff_comp comparison functor isn't a total ordering.
Dodji Seketeli
dodji@seketeli.org
Sun Jan 1 00:00:00 GMT 2017
Hello Mark,
Mark Wielaard <mark@klomp.org> a écrit:
> 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.
Thanks, this is really useful.
I just have some light comments below.
[...]
> diff --git a/src/abg-comparison.cc b/src/abg-comparison.cc
[...]
> /// 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;
Just so we are clear, the diff nodes (f and s) represent a change from
an initial data member to a new data member. What you are comparing
here are the offsets of the new data members.
And then ...
> +
> + string name1 = first_dm->get_qualified_name();
> + string name2 = second_dm->get_qualified_name();
> +
> + assert (name1 != name2);
> +
> + return name1 < name2;
... here, you are comparing the qualified names of these new data
members.
I think it'd be more natural to compare the qualified names of the
*initial* data members first (when their offset is equal) and then
compare the offset and qualified names of the new data members.
This would result in the slightly modified patch below. Would this one
pass make distcheck in the autobuilder environment? If yes, you can
just commit that one, or I can do it for you if you like.
Thanks a lot and cheers!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Bug-22075-data_member_diff_comp-comparison-functor-i.patch
Type: text/x-patch
Size: 3189 bytes
Desc: Tentative patch
URL: <http://sourceware.org/pipermail/libabigail/attachments/20170101/cf437fbc/attachment.bin>
-------------- next part --------------
--
Dodji
More information about the Libabigail
mailing list