Use std::string in maybe_expand
authorTom Tromey <tom@tromey.com>
Tue, 6 Feb 2018 19:11:21 +0000 (12:11 -0700)
committerTom Tromey <tom@tromey.com>
Thu, 8 Feb 2018 18:46:56 +0000 (11:46 -0700)
This patch changes maybe_expand to use std::string rather than an
explicit malloc and a cleanup.

2018-02-08  Tom Tromey  <tom@tromey.com>

* macroexp.c (maybe_expand): Use std::string.

gdb/ChangeLog
gdb/macroexp.c

index 2a989cc1153efdce1eaef3267c516aa5e951da48..cf0dfc31b3313b1178d40071cc41f71605f2306a 100644 (file)
@@ -1,3 +1,7 @@
+2018-02-08  Tom Tromey  <tom@tromey.com>
+
+       * macroexp.c (maybe_expand): Use std::string.
+
 2018-02-08  Tom Tromey  <tom@tromey.com>
 
        * macroexp.c (struct macro_buffer): Add initializers for some
index 02cf26ff7398f71b841bb8da2603169a054ed4d8..1fa37d2875b8467925c5c3f654be372c2b5b5711 100644 (file)
@@ -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;
This page took 0.027448 seconds and 4 git commands to generate.