Bug 26780 - Fix array subrange bounds (de)serialization

When serializing subrange bounds to ABIXML today the writer omits the
lower and upper bounds.  Only the length is emitted.  The reader thus
assumes that the lower bound of an array subrange is always 0.  In
Fortran however, that is not true, as the lower bound is 1.

This patch instructs the writer to emits the lower bound whenever it's
different from zero.  It also emits the upper bound in that case.  The
reader is updated accordingly to take the lower and upper bounds into
account whenever they are present.  It they are not, then the
lower bound is assumed to be zero and the upper bound is deduced from
the length, as was already the case until now.

	* src/abg-reader.cc (build_subrange_type): Read lower-bound
	attribute if present.  Then try to read upper-bound attribute as
	well.  If this is not an infinite subrange assert that the length
	must be equal to the difference between the bounds.
	* src/abg-writer.cc (write_array_subrange_type): Write the
	lower-bound if it's present and not zero.  In that case, write the
	upper-bound as well.
	* tests/data/test-diff-pkg/hdf5-1.10.6-2.fc33.x86_64.rpm: Add new
	binary test input.
	* tests/data/test-diff-pkg/hdf5-debuginfo-1.10.6-2.fc33.x86_64.rpm:
	Likewise.
	* tests/data/test-diff-pkg/hdf5-1.10.6-2.fc33.x86_64.self-check-report-0.txt:
	Add new reference output.
	* tests/data/Makefile.am: Add the new test material above to
	source distribution.
	* tests/test-diff-pkg.cc (in_out_specs): Add the binary test input
	to the set of --self-check tests.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
This commit is contained in:
Dodji Seketeli 2020-11-26 13:39:12 +01:00
parent 7d5ef25b9c
commit b553802af8
7 changed files with 73 additions and 0 deletions

View File

@ -3852,6 +3852,19 @@ build_subrange_type(read_context& ctxt,
length = strtoull(CHAR_STR(s), NULL, 0);
}
int64_t lower_bound = 0, upper_bound = 0;
bool bounds_present = false;
if (xml_char_sptr s = XML_NODE_GET_ATTRIBUTE(node, "lower-bound"))
{
lower_bound = strtoll(CHAR_STR(s), NULL, 0);
s = XML_NODE_GET_ATTRIBUTE(node, "upper-bound");
if (!string(CHAR_STR(s)).empty())
upper_bound = strtoll(CHAR_STR(s), NULL, 0);
bounds_present = true;
ABG_ASSERT(is_infinite
|| (length == (uint64_t) upper_bound - lower_bound));
}
string underlying_type_id;
if (xml_char_sptr s = XML_NODE_GET_ATTRIBUTE(node, "type-id"))
underlying_type_id = CHAR_STR(s);
@ -3872,8 +3885,19 @@ build_subrange_type(read_context& ctxt,
array_type_def::subrange_type::bound_value min_bound;
if (!is_infinite)
if (length > 0)
// By default, if no 'lower-bound/upper-bound' attributes are
// set, we assume that the lower bound is 0 and the upper bound
// is length - 1.
max_bound.set_signed(length - 1);
if (bounds_present)
{
// So lower_bound/upper_bound are set. Let's set them rather
// than assume that mind_bound is zero.
min_bound.set_signed(lower_bound);
max_bound.set_signed(upper_bound);
}
array_type_def::subrange_sptr p
(new array_type_def::subrange_type(ctxt.get_environment(),
name, min_bound, max_bound,

View File

@ -2783,6 +2783,16 @@ write_array_subrange_type(const array_type_def::subrange_sptr& decl,
o << "'";
if (decl->get_lower_bound())
{
ABG_ASSERT(decl->is_infinite()
|| (decl->get_length() ==
(uint64_t) (decl->get_upper_bound()
- decl->get_lower_bound())));
o << " lower-bound='" << decl->get_lower_bound() << "' upper-bound='"
<< decl->get_upper_bound() << "'";
}
type_base_sptr underlying_type = decl->get_underlying_type();
if (underlying_type)
{

View File

@ -1763,6 +1763,9 @@ test-diff-pkg/PR24690/flatpak-libs-debuginfo-1.4.0-1.fc30.x86_64.rpm \
test-diff-pkg/mesa-libGLU-9.0.1-3.fc33.x86_64.rpm \
test-diff-pkg/mesa-libGLU-debuginfo-9.0.1-3.fc33.x86_64.rpm \
test-diff-pkg/mesa-libGLU-9.0.1-3.fc33.x86_64.self-check-report-0.txt \
test-diff-pkg/hdf5-1.10.6-2.fc33.x86_64.rpm \
test-diff-pkg/hdf5-1.10.6-2.fc33.x86_64.self-check-report-0.txt \
test-diff-pkg/hdf5-debuginfo-1.10.6-2.fc33.x86_64.rpm \
\
test-fedabipkgdiff/dbus-glib-0.104-3.fc23.x86_64.rpm \
test-fedabipkgdiff/dbus-glib-debuginfo-0.104-3.fc23.x86_64.rpm \

Binary file not shown.

View File

@ -0,0 +1,24 @@
==== SELF CHECK SUCCEEDED for 'libhdf5.so.103.2.0' ====
==== SELF CHECK SUCCEEDED for 'libhdf5_cpp.so.103.2.0' ====
==== SELF CHECK SUCCEEDED for 'libhdf5_fortran.so.102.0.1' ====
==== SELF CHECK SUCCEEDED for 'h5diff' ====
==== SELF CHECK SUCCEEDED for 'h5dump' ====
==== SELF CHECK SUCCEEDED for 'h5repack' ====
==== SELF CHECK SUCCEEDED for 'h5import' ====
==== SELF CHECK SUCCEEDED for 'h5ls' ====
==== SELF CHECK SUCCEEDED for 'h5perf_serial' ====
==== SELF CHECK SUCCEEDED for 'h5stat' ====
==== SELF CHECK SUCCEEDED for 'gif2h5' ====
==== SELF CHECK SUCCEEDED for 'h5watch' ====
==== SELF CHECK SUCCEEDED for 'h52gif' ====
==== SELF CHECK SUCCEEDED for 'h5jam' ====
==== SELF CHECK SUCCEEDED for 'h5format_convert' ====
==== SELF CHECK SUCCEEDED for 'h5copy' ====
==== SELF CHECK SUCCEEDED for 'libhdf5hl_fortran.so.100.0.5' ====
==== SELF CHECK SUCCEEDED for 'h5clear' ====
==== SELF CHECK SUCCEEDED for 'h5unjam' ====
==== SELF CHECK SUCCEEDED for 'h5mkgrp' ====
==== SELF CHECK SUCCEEDED for 'libhdf5_hl.so.100.1.3' ====
==== SELF CHECK SUCCEEDED for 'h5debug' ====
==== SELF CHECK SUCCEEDED for 'h5repart' ====
==== SELF CHECK SUCCEEDED for 'libhdf5_hl_cpp.so.100.1.4' ====

View File

@ -634,6 +634,18 @@ static InOutSpec in_out_specs[] =
"data/test-diff-pkg/mesa-libGLU-9.0.1-3.fc33.x86_64.self-check-report-0.txt",
"output/test-diff-pkg/mesa-libGLU-9.0.1-3.fc33.x86_64.self-check-report-0.txt"
},
{
"data/test-diff-pkg/hdf5-1.10.6-2.fc33.x86_64.rpm",
"data/test-diff-pkg/hdf5-1.10.6-2.fc33.x86_64.rpm",
"--self-check",
"",
"data/test-diff-pkg/hdf5-debuginfo-1.10.6-2.fc33.x86_64.rpm",
"data/test-diff-pkg/hdf5-debuginfo-1.10.6-2.fc33.x86_64.rpm",
"",
"",
"data/test-diff-pkg/hdf5-1.10.6-2.fc33.x86_64.self-check-report-0.txt",
"output/test-diff-pkg/hdf5-1.10.6-2.fc33.x86_64.self-check-report-0.txt"
},
#endif // WITH_RPM_4_15
#endif //WITH_RPM