Use unique_xmalloc_ptr in fixup_go_packaging

This changes fixup_go_packaging to use unique_xmalloc_ptr.  I kept
this patch separate as it is slightly more complicated than the
previous changes.

gdb/ChangeLog
2020-01-08  Tom Tromey  <tromey@adacore.com>

	* dwarf2read.c (fixup_go_packaging): Use unique_xmalloc_ptr.

Change-Id: I0c553d0c6579db478c27bc40fc21133a61e1a4d9
This commit is contained in:
Tom Tromey 2019-10-31 10:34:40 -06:00
parent 43816ebc33
commit 421d161623
2 changed files with 11 additions and 9 deletions

View File

@ -1,3 +1,7 @@
2020-01-08 Tom Tromey <tromey@adacore.com>
* dwarf2read.c (fixup_go_packaging): Use unique_xmalloc_ptr.
2020-01-08 Tom Tromey <tromey@adacore.com>
* dwarf2read.c (add_partial_symbol): Use unique_xmalloc_ptr.

View File

@ -9892,7 +9892,7 @@ compute_delayed_physnames (struct dwarf2_cu *cu)
static void
fixup_go_packaging (struct dwarf2_cu *cu)
{
char *package_name = NULL;
gdb::unique_xmalloc_ptr<char> package_name;
struct pending *list;
int i;
@ -9907,24 +9907,24 @@ fixup_go_packaging (struct dwarf2_cu *cu)
if (sym->language () == language_go
&& SYMBOL_CLASS (sym) == LOC_BLOCK)
{
char *this_package_name = go_symbol_package_name (sym);
gdb::unique_xmalloc_ptr<char> this_package_name
(go_symbol_package_name (sym));
if (this_package_name == NULL)
continue;
if (package_name == NULL)
package_name = this_package_name;
package_name = std::move (this_package_name);
else
{
struct objfile *objfile
= cu->per_cu->dwarf2_per_objfile->objfile;
if (strcmp (package_name, this_package_name) != 0)
if (strcmp (package_name.get (), this_package_name.get ()) != 0)
complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
(symbol_symtab (sym) != NULL
? symtab_to_filename_for_display
(symbol_symtab (sym))
: objfile_name (objfile)),
this_package_name, package_name);
xfree (this_package_name);
this_package_name.get (), package_name.get ());
}
}
}
@ -9934,7 +9934,7 @@ fixup_go_packaging (struct dwarf2_cu *cu)
{
struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile;
const char *saved_package_name
= obstack_strdup (&objfile->per_bfd->storage_obstack, package_name);
= obstack_strdup (&objfile->per_bfd->storage_obstack, package_name.get ());
struct type *type = init_type (objfile, TYPE_CODE_MODULE, 0,
saved_package_name);
struct symbol *sym;
@ -9949,8 +9949,6 @@ fixup_go_packaging (struct dwarf2_cu *cu)
SYMBOL_TYPE (sym) = type;
add_symbol_to_list (sym, cu->get_builder ()->get_global_symbols ());
xfree (package_name);
}
}