diff options
author | Joel Brobecker <brobecker@adacore.com> | 2020-11-23 21:45:35 -0500 |
---|---|---|
committer | Joel Brobecker <brobecker@adacore.com> | 2020-11-23 21:45:35 -0500 |
commit | 987b670356322ba4d493f441855bf5dc8d946e9f (patch) | |
tree | 50b180ece0ac5d200979b6edefa31fff29cb8adb /gdb/gmp-utils.h | |
parent | 4fbb7ccebe1fdcbae762e8fed6af7a810c81f85c (diff) | |
download | binutils-gdb-987b670356322ba4d493f441855bf5dc8d946e9f.tar.gz |
change and rename gmp_string_asprintf to return an std::string
This was suggested by Simon during a code review of this package upstream.
The upside is that this makes the function's API more natural and C++.
The downside is an extra malloc, which might be the reason why we went
for using a unique_xmalloc_ptr in the first place. Since this function
is not expected to be called frequently, the API improvement might be
worth the performance impact.
gdb/ChangeLog:
* gmp-utils.h (gmp_string_printf): Rename from gmp_string_asprintf.
Change return type to std::string. Update all callers.
* gmp-utils.c (gmp_string_printf): Likewise.
Diffstat (limited to 'gdb/gmp-utils.h')
-rw-r--r-- | gdb/gmp-utils.h | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/gdb/gmp-utils.h b/gdb/gmp-utils.h index 1214b645367..59965e504c5 100644 --- a/gdb/gmp-utils.h +++ b/gdb/gmp-utils.h @@ -29,9 +29,9 @@ #include <gmp.h> #include "gdbsupport/traits.h" -/* Same as gmp_asprintf, but returning a convenient wrapper type. */ +/* Same as gmp_asprintf, but returning an std::string. */ -gdb::unique_xmalloc_ptr<char> gmp_string_asprintf (const char *fmt, ...); +std::string gmp_string_printf (const char *fmt, ...); /* A class to make it easier to use GMP's mpz_t values within GDB. */ @@ -110,8 +110,7 @@ struct gdb_mpz bool unsigned_p) const; /* Return a string containing VAL. */ - gdb::unique_xmalloc_ptr<char> str () const - { return gmp_string_asprintf ("%Zd", val); } + std::string str () const { return gmp_string_printf ("%Zd", val); } /* The destructor. */ ~gdb_mpz () { mpz_clear (val); } @@ -163,8 +162,7 @@ struct gdb_mpq } /* Return a string representing VAL as "<numerator> / <denominator>". */ - gdb::unique_xmalloc_ptr<char> str () const - { return gmp_string_asprintf ("%Qd", val); } + std::string str () const { return gmp_string_printf ("%Qd", val); } /* Return VAL rounded to the nearest integer. */ gdb_mpz get_rounded () const; |