This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[RFA 5/9] Use std::string in maybe_expand
- From: Tom Tromey <tom at tromey dot com>
- To: gdb-patches at sourceware dot org
- Cc: Tom Tromey <tom at tromey dot com>
- Date: Wed, 7 Feb 2018 15:04:30 -0700
- Subject: [RFA 5/9] Use std::string in maybe_expand
- Authentication-results: sourceware.org; auth=none
- References: <20180207220434.6045-1-tom@tromey.com>
This patch changes maybe_expand to use std::string rather than an
explicit malloc and a cleanup.
2018-02-07 Tom Tromey <tom@tromey.com>
* macroexp.c (maybe_expand): Use std::string.
---
gdb/ChangeLog | 4 ++++
gdb/macroexp.c | 20 ++++++--------------
2 files changed, 10 insertions(+), 14 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 33f7e5f3d0..f33e3a6f7f 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,9 @@
2018-02-07 Tom Tromey <tom@tromey.com>
+ * macroexp.c (maybe_expand): Use std::string.
+
+2018-02-07 Tom Tromey <tom@tromey.com>
+
* macroexp.c (struct macro_buffer): Add initializers for some
members.
(init_buffer, init_shared_buffer, free_buffer)
diff --git a/gdb/macroexp.c b/gdb/macroexp.c
index 02cf26ff73..1fa37d2875 100644
--- a/gdb/macroexp.c
+++ b/gdb/macroexp.c
@@ -1347,28 +1347,20 @@ maybe_expand (struct macro_buffer *dest,
{
/* Make a null-terminated copy of it, since that's what our
lookup function expects. */
- char *id = (char *) xmalloc (src_first->len + 1);
- struct cleanup *back_to = make_cleanup (xfree, id);
+ std::string id (src_first->text, src_first->len);
- memcpy (id, src_first->text, src_first->len);
- id[src_first->len] = 0;
-
/* If we're currently re-scanning the result of expanding
this macro, don't expand it again. */
- if (! currently_rescanning (no_loop, id))
+ if (! currently_rescanning (no_loop, id.c_str ()))
{
/* Does this identifier have a macro definition in scope? */
- struct macro_definition *def = lookup_func (id, lookup_baton);
+ struct macro_definition *def = lookup_func (id.c_str (),
+ lookup_baton);
- if (def && expand (id, def, dest, src_rest, no_loop,
+ if (def && expand (id.c_str (), def, dest, src_rest, no_loop,
lookup_func, lookup_baton))
- {
- do_cleanups (back_to);
- return 1;
- }
+ return 1;
}
-
- do_cleanups (back_to);
}
return 0;
--
2.13.6