Return unique_xmalloc_ptr for generate_c_for_variable_locations
authorKeith Seitz <keiths@redhat.com>
Fri, 10 Aug 2018 17:38:56 +0000 (10:38 -0700)
committerKeith Seitz <keiths@redhat.com>
Fri, 10 Aug 2018 18:14:25 +0000 (11:14 -0700)
This patch eliminates two cleanups in compile/ by changing
generate_c_for_variable_locations so that it returns a unique_ptr.

gdb/ChangeLog:
        * compile/compile-c-support.c (c_compute_program): Use
        unique_xmalloc_ptr to eliminate cleanup.
        * compile/compile-c-symbols.c (generate_c_for_variable_locations):
        Return a unique_xmalloc_ptr and eliminate cleanup.
        * compile/compile-internal.h (generate_c_for_variable_locations):
        Return unique_xmalloc_ptr and update description.

gdb/ChangeLog
gdb/compile/compile-c-support.c
gdb/compile/compile-c-symbols.c
gdb/compile/compile-internal.h

index bc685193736331136fa9e207602411aeed02d643..7414f0e5428649053ef4862cd43a70e952c135b3 100644 (file)
@@ -1,3 +1,12 @@
+2018-08-10  Keith Seitz  <keiths@redhat.com>
+
+       * compile/compile-c-support.c (c_compute_program): Use
+       unique_xmalloc_ptr to eliminate cleanup.
+       * compile/compile-c-symbols.c (generate_c_for_variable_locations):
+       Return a unique_xmalloc_ptr and eliminate cleanup.
+       * compile/compile-internal.h (generate_c_for_variable_locations):
+       Return unique_xmalloc_ptr and update description.
+
 2018-08-10  Alan Hayward  <alan.hayward@arm.com>
 
        * corelow.c (core_target::get_core_register_section): Rename
index e6946482880eb6f7ab0c0871c942c7534c92eab3..696bb9fced92f2bc58137e0f7e48f19c2b047b57 100644 (file)
@@ -351,17 +351,15 @@ c_compute_program (struct compile_instance *inst,
      and the user's code may only refer to globals.  */
   if (inst->scope != COMPILE_I_RAW_SCOPE)
     {
-      unsigned char *registers_used;
       int i;
 
       /* Generate the code to compute variable locations, but do it
         before generating the function header, so we can define the
         register struct before the function body.  This requires a
         temporary stream.  */
-      registers_used = generate_c_for_variable_locations (context,
-                                                         var_stream, gdbarch,
-                                                         expr_block, expr_pc);
-      make_cleanup (xfree, registers_used);
+      gdb::unique_xmalloc_ptr<unsigned char> registers_used
+       = generate_c_for_variable_locations (context, var_stream, gdbarch,
+                                            expr_block, expr_pc);
 
       buf.puts ("typedef unsigned int"
                " __attribute__ ((__mode__(__pointer__)))"
@@ -382,7 +380,7 @@ c_compute_program (struct compile_instance *inst,
                      mode, mode);
        }
 
-      generate_register_struct (&buf, gdbarch, registers_used);
+      generate_register_struct (&buf, gdbarch, registers_used.get ());
     }
 
   add_code_header (inst->scope, &buf);
index 43de7df0248659c1ce0c9eb6649e777d4fc09b61..6987fa375ec1c24995fb2fa9c35035c8b62650c2 100644 (file)
@@ -708,24 +708,22 @@ generate_c_for_for_one_variable (struct compile_c_instance *compiler,
 
 /* See compile-internal.h.  */
 
-unsigned char *
+gdb::unique_xmalloc_ptr<unsigned char>
 generate_c_for_variable_locations (struct compile_c_instance *compiler,
                                   string_file &stream,
                                   struct gdbarch *gdbarch,
                                   const struct block *block,
                                   CORE_ADDR pc)
 {
-  struct cleanup *outer;
   const struct block *static_block = block_static_block (block);
-  unsigned char *registers_used;
 
   /* If we're already in the static or global block, there is nothing
      to write.  */
   if (static_block == NULL || block == static_block)
     return NULL;
 
-  registers_used = XCNEWVEC (unsigned char, gdbarch_num_regs (gdbarch));
-  outer = make_cleanup (xfree, registers_used);
+  gdb::unique_xmalloc_ptr<unsigned char> registers_used
+    (XCNEWVEC (unsigned char, gdbarch_num_regs (gdbarch)));
 
   /* Ensure that a given name is only entered once.  This reflects the
      reality of shadowing.  */
@@ -745,7 +743,7 @@ generate_c_for_variable_locations (struct compile_c_instance *compiler,
        {
          if (!symbol_seen (symhash.get (), sym))
            generate_c_for_for_one_variable (compiler, stream, gdbarch,
-                                            registers_used, pc, sym);
+                                            registers_used.get (), pc, sym);
        }
 
       /* If we just finished the outermost block of a function, we're
@@ -755,6 +753,5 @@ generate_c_for_variable_locations (struct compile_c_instance *compiler,
       block = BLOCK_SUPERBLOCK (block);
     }
 
-  discard_cleanups (outer);
   return registers_used;
 }
index c92cb645f6f0c6b99254d3ae0ee49eed4f8f63f5..01beb1dddd82c78b7b20b46638038027e2fce78c 100644 (file)
@@ -128,11 +128,12 @@ extern gcc_c_symbol_address_function gcc_symbol_address;
 extern struct compile_instance *new_compile_instance (struct gcc_c_context *fe);
 
 /* Emit code to compute the address for all the local variables in
-   scope at PC in BLOCK.  Returns a malloc'd vector, indexed by gdb
-   register number, where each element indicates if the corresponding
-   register is needed to compute a local variable.  */
+   scope at PC in BLOCK.  Returns a vector, indexed by gdb register
+   number, where each element indicates if the corresponding register
+   is needed to compute a local variable.  */
 
-extern unsigned char *generate_c_for_variable_locations
+extern gdb::unique_xmalloc_ptr<unsigned char>
+  generate_c_for_variable_locations
      (struct compile_c_instance *compiler,
       string_file &stream,
       struct gdbarch *gdbarch,