C++-ify bcache

This somewhat C++-ifies bcache.  It replaces bcache_xmalloc and
bcache_xfree with constructors; changes some functions into methods;
and changes various structures to include a bcache directly (as
opposed to a pointer to a bcache).

Tested by the buildbot.

gdb/ChangeLog
2019-03-07  Tom Tromey  <tom@tromey.com>

	* symmisc.c (print_symbol_bcache_statistics): Update.
	(print_objfile_statistics): Update.
	* symfile.c (allocate_symtab): Update.
	* stabsread.c: Don't include bcache.h.
	* psymtab.h (struct psymbol_bcache): Don't declare.
	(class psymtab_storage) <psymbol_cache>: Now a bcache.
	(psymbol_bcache_init, psymbol_bcache_free)
	(psymbol_bcache_get_bcache): Don't declare.
	* psymtab.c (struct psymbol_bcache): Remove.
	(psymtab_storage::psymtab_storage): Update.
	(psymtab_storage::~psymtab_storage): Update.
	(psymbol_bcache_init, psymbol_bcache_free)
	(psymbol_bcache_get_bcache, psymbol_bcache_full): Remove.
	(add_psymbol_to_bcache): Update.
	(allocate_psymtab): Update.
	* objfiles.h (struct objfile_per_bfd_storage) <filename_cache,
	macro_cache>: No longer pointers.
	* objfiles.c (get_objfile_bfd_data): Don't call bcache_xmalloc.
	(free_objfile_per_bfd_storage): Don't call bcache_xfree.
	* macrotab.c (macro_bcache): Update.
	* macroexp.c: Don't include bcache.h.
	* gdbtypes.c (check_types_worklist): Update.
	(types_deeply_equal): Remove TRY/CATCH.  Update.
	* elfread.c (elf_symtab_read): Update.
	* dwarf2read.c: Don't include bcache.h.
	* buildsym.c (buildsym_compunit::get_macro_table): Update.
	* bcache.h (bcache, bcache_full, bcache_xffree, bcache_xmalloc)
	(print_bcache_statistics, bcache_memory_used): Don't declare.
	(struct bcache): Move from bcache.c.  Add constructor, destructor,
	methods.  Rename all data members.
	* bcache.c (struct bcache): Move to bcache.h.
	(bcache::expand_hash_table): Rename from expand_hash_table.
	(bcache): Remove.
	(bcache::insert): Rename from bcache_full.
	(bcache::compare): Rename from bcache_compare.
	(bcache_xmalloc): Remove.
	(bcache::~bcache): Rename from bcache_xfree.
	(bcache::print_statistics): Rename from print_bcache_statistics.
	(bcache::memory_used): Rename from bcache_memory_used.
This commit is contained in:
Tom Tromey
2019-03-07 04:20:19 -07:00
parent fe72666741
commit 25629dfdb4
16 changed files with 228 additions and 316 deletions

View File

@@ -3732,7 +3732,7 @@ check_types_worklist (std::vector<type_equality_entry> *worklist,
/* If the type pair has already been visited, we know it is
ok. */
bcache_full (&entry, sizeof (entry), cache, &added);
cache->insert (&entry, sizeof (entry), &added);
if (!added)
continue;
@@ -3749,9 +3749,6 @@ check_types_worklist (std::vector<type_equality_entry> *worklist,
bool
types_deeply_equal (struct type *type1, struct type *type2)
{
struct gdb_exception except = exception_none;
bool result = false;
struct bcache *cache;
std::vector<type_equality_entry> worklist;
gdb_assert (type1 != NULL && type2 != NULL);
@@ -3760,31 +3757,9 @@ types_deeply_equal (struct type *type1, struct type *type2)
if (type1 == type2)
return true;
cache = bcache_xmalloc (NULL, NULL);
struct bcache cache (nullptr, nullptr);
worklist.emplace_back (type1, type2);
/* check_types_worklist calls several nested helper functions, some
of which can raise a GDB exception, so we just check and rethrow
here. If there is a GDB exception, a comparison is not capable
(or trusted), so exit. */
TRY
{
result = check_types_worklist (&worklist, cache);
}
CATCH (ex, RETURN_MASK_ALL)
{
except = ex;
}
END_CATCH
bcache_xfree (cache);
/* Rethrow if there was a problem. */
if (except.reason < 0)
throw_exception (except);
return result;
return check_types_worklist (&worklist, &cache);
}
/* Allocated status of type TYPE. Return zero if type TYPE is allocated.