aboutsummaryrefslogtreecommitdiff
path: root/gdb/gmp-utils.h
diff options
context:
space:
mode:
authorJoel Brobecker <brobecker@adacore.com>2020-11-23 21:46:38 -0500
committerJoel Brobecker <brobecker@adacore.com>2020-11-23 21:46:38 -0500
commitc9f0b43fe46f473e4de3494f95b11ffb3d5a42a8 (patch)
tree3413d683bf1843314a98ca795a8ee8ec849de3ee /gdb/gmp-utils.h
parent987b670356322ba4d493f441855bf5dc8d946e9f (diff)
downloadgdb-c9f0b43fe46f473e4de3494f95b11ffb3d5a42a8.zip
gdb-c9f0b43fe46f473e4de3494f95b11ffb3d5a42a8.tar.gz
gdb-c9f0b43fe46f473e4de3494f95b11ffb3d5a42a8.tar.bz2
gmp-utils: Convert the read/write methods to using gdb::array_view
This commit changes the interfaces of some of the methods declared in gmp-utils to take a gdb::array_view of gdb_byte instead of a (gdb_byte *, size) couple. This makes these methods' API probably more C++-idiomatic. * gmp-utils.h (gdb_mpz::read): Change buf and len parameters into one single gdb::array_view parameter. (gdb_mpz::write): Likewise. (gdb_mpq::read_fixed_point, gdb_mpq::write_fixed_point): Likewise. * gmp-utils.c (gdb_mpz::read): Change buf and len parameters into one single gdb::array_view parameter. Adjust implementation accordingly. (gdb_mpz::write): Likewise. (gdb_mpq::read_fixed_point, gdb_mpq::write_fixed_point): Likewise. * unittests/gmp-utils-selftests.c: Adapt following changes above. * valarith.c, valops.c, valprint.c, value.c: Likewise.
Diffstat (limited to 'gdb/gmp-utils.h')
-rw-r--r--gdb/gmp-utils.h32
1 files changed, 18 insertions, 14 deletions
diff --git a/gdb/gmp-utils.h b/gdb/gmp-utils.h
index 59965e5..12e4f8e 100644
--- a/gdb/gmp-utils.h
+++ b/gdb/gmp-utils.h
@@ -96,17 +96,19 @@ struct gdb_mpz
The return type can signed or unsigned, with no size restriction. */
template<typename T> T as_integer () const;
- /* Set VAL by importing the number stored in the byte buffer (BUF),
- given its size (LEN) and BYTE_ORDER.
+ /* Set VAL by importing the number stored in the byte array (BUF),
+ using the given BYTE_ORDER. The size of the data to read is
+ the byte array's size.
UNSIGNED_P indicates whether the number has an unsigned type. */
- void read (const gdb_byte *buf, int len, enum bfd_endian byte_order,
+ void read (gdb::array_view<const gdb_byte> buf, enum bfd_endian byte_order,
bool unsigned_p);
- /* Write VAL into BUF as a LEN-bytes number with the given BYTE_ORDER.
+ /* Write VAL into BUF as a number whose byte size is the size of BUF,
+ using the given BYTE_ORDER.
UNSIGNED_P indicates whether the number has an unsigned type. */
- void write (gdb_byte *buf, int len, enum bfd_endian byte_order,
+ void write (gdb::array_view<gdb_byte> buf, enum bfd_endian byte_order,
bool unsigned_p) const;
/* Return a string containing VAL. */
@@ -167,24 +169,26 @@ struct gdb_mpq
/* Return VAL rounded to the nearest integer. */
gdb_mpz get_rounded () const;
- /* Set VAL from the contents of the given buffer (BUF), which
- contains the unscaled value of a fixed point type object
- with the given size (LEN) and byte order (BYTE_ORDER).
+ /* Set VAL from the contents of the given byte array (BUF), which
+ contains the unscaled value of a fixed point type object.
+ The byte size of the data is the size of BUF.
+
+ BYTE_ORDER provides the byte_order to use when reading the data.
UNSIGNED_P indicates whether the number has an unsigned type.
SCALING_FACTOR is the scaling factor to apply after having
read the unscaled value from our buffer. */
- void read_fixed_point (const gdb_byte *buf, int len,
+ void read_fixed_point (gdb::array_view<const gdb_byte> buf,
enum bfd_endian byte_order, bool unsigned_p,
const gdb_mpq &scaling_factor);
- /* Write VAL into BUF as a LEN-bytes fixed point value following
- the given BYTE_ORDER.
+ /* Write VAL into BUF as fixed point value following the given BYTE_ORDER.
+ The size of BUF is used as the length to write the value into.
UNSIGNED_P indicates whether the number has an unsigned type.
SCALING_FACTOR is the scaling factor to apply before writing
the unscaled value to our buffer. */
- void write_fixed_point (gdb_byte *buf, int len,
+ void write_fixed_point (gdb::array_view<gdb_byte> buf,
enum bfd_endian byte_order, bool unsigned_p,
const gdb_mpq &scaling_factor) const;
@@ -213,13 +217,13 @@ struct gdb_mpf
UNSIGNED_P indicates whether the number has an unsigned type.
SCALING_FACTOR is the scaling factor to apply after having
read the unscaled value from our buffer. */
- void read_fixed_point (const gdb_byte *buf, int len,
+ void read_fixed_point (gdb::array_view<const gdb_byte> buf,
enum bfd_endian byte_order, bool unsigned_p,
const gdb_mpq &scaling_factor)
{
gdb_mpq tmp_q;
- tmp_q.read_fixed_point (buf, len, byte_order, unsigned_p, scaling_factor);
+ tmp_q.read_fixed_point (buf, byte_order, unsigned_p, scaling_factor);
mpf_set_q (val, tmp_q.val);
}