[2/3] Remove string-related cleanup from c-exp.y

Message ID 20190105204112.26849-3-tom@tromey.com
State New
Headers show
Series
  • Remove cleanups from c-exp.y
Related show

Commit Message

Tom Tromey Jan. 5, 2019, 8:41 p.m.
This removes a string-related cleanup from c-exp.y, by adding a new
member to c_parse_state to store the strings.

gdb/ChangeLog
2019-01-05  Tom Tromey  <tom@tromey.com>

	* c-exp.y (struct c_parse_state) <strings>: New member.
	(operator_stoken): Update.
---
 gdb/ChangeLog | 5 +++++
 gdb/c-exp.y   | 5 ++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

-- 
2.17.2

Comments

Simon Marchi Jan. 6, 2019, 5 a.m. | #1
On 2019-01-05 15:41, Tom Tromey wrote:
> This removes a string-related cleanup from c-exp.y, by adding a new

> member to c_parse_state to store the strings.


LGTM.

Simon

Patch

diff --git a/gdb/c-exp.y b/gdb/c-exp.y
index eb6a6847cf..83b2aa3fdd 100644
--- a/gdb/c-exp.y
+++ b/gdb/c-exp.y
@@ -74,6 +74,9 @@  struct c_parse_state
      allocated during the parse.  */
   std::vector<std::unique_ptr<std::vector<struct type *>>> type_lists;
   std::vector<std::unique_ptr<struct type_stack>> type_stacks;
+
+  /* Storage for some strings allocated during the parse.  */
+  std::vector<gdb::unique_xmalloc_ptr<char>> strings;
 };
 
 /* This is set and cleared in c_parse.  */
@@ -1743,7 +1746,7 @@  operator_stoken (const char *op)
   st.ptr = buf;
 
   /* The toplevel (c_parse) will free the memory allocated here.  */
-  make_cleanup (free, buf);
+  cpstate->strings.emplace_back (buf);
   return st;
 };