diff options
author | Keith Seitz <keiths@redhat.com> | 2018-08-10 10:53:47 -0700 |
---|---|---|
committer | Keith Seitz <keiths@redhat.com> | 2018-08-10 11:14:25 -0700 |
commit | 0cfbf43085c4191f3f4b4b4a834f1e19bf42d4a9 (patch) | |
tree | 3ce376cc5de9974010c884076fdb127014aeed28 /gdb | |
parent | 946d3d10e7609e074be30db8662cb9c4a3d8961d (diff) | |
download | gdb-0cfbf43085c4191f3f4b4b4a834f1e19bf42d4a9.zip gdb-0cfbf43085c4191f3f4b4b4a834f1e19bf42d4a9.tar.gz gdb-0cfbf43085c4191f3f4b4b4a834f1e19bf42d4a9.tar.bz2 |
Use unique_ptr for htabs
This patch updates the type-conversion caching in C compile to use
unique pointers. This patch also removes the on-demand allocation of the
symbol error map in favor of initialization, simplifying the code.
gdb/ChangeLog
* compile/compile-internal.h (compile_instance::~compile_instance):
Remove calls to htab_delete.
<m_type_map, m_symbol_err_map>: Switch type to htab_up.
* compile.c (compile_instance::compile_instance): Initialize
htab unique pointers.
(compile_instance::get_cached_type, compile_instance::insert_type)
(compile_instance::error_symbol_once): Update for unique_ptr.
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/ChangeLog | 10 | ||||
-rw-r--r-- | gdb/compile/compile-internal.h | 7 | ||||
-rw-r--r-- | gdb/compile/compile.c | 28 |
3 files changed, 22 insertions, 23 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 50adfcf..d6f002d 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,15 @@ 2018-08-10 Keith Seitz <keiths@redhat.com> + * compile/compile-internal.h (compile_instance::~compile_instance): + Remove calls to htab_delete. + <m_type_map, m_symbol_err_map>: Switch type to htab_up. + * compile.c (compile_instance::compile_instance): Initialize + htab unique pointers. + (compile_instance::get_cached_type, compile_instance::insert_type) + (compile_instance::error_symbol_once): Update for unique_ptr. + +2018-08-10 Keith Seitz <keiths@redhat.com> + * compile/compile-c-symbols.c (struct symbol_error) (hash_symbol_error, eq_symbol_error, del_symbol_error) (compile_instance::insert_symbol_error) diff --git a/gdb/compile/compile-internal.h b/gdb/compile/compile-internal.h index 3916f84..c8d2d2f 100644 --- a/gdb/compile/compile-internal.h +++ b/gdb/compile/compile-internal.h @@ -49,9 +49,6 @@ public: virtual ~compile_instance () { m_gcc_fe->ops->destroy (m_gcc_fe); - htab_delete (m_type_map); - if (m_symbol_err_map != NULL) - htab_delete (m_symbol_err_map); } /* Returns the GCC options to be passed during compilation. */ @@ -148,10 +145,10 @@ protected: std::string m_gcc_target_options; /* Map from gdb types to gcc types. */ - htab_t m_type_map; + htab_up m_type_map; /* Map from gdb symbols to gcc error messages to emit. */ - htab_t m_symbol_err_map; + htab_up m_symbol_err_map; }; /* Define header and footers for different scopes. */ diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c index 308c82e..31ae597 100644 --- a/gdb/compile/compile.c +++ b/gdb/compile/compile.c @@ -129,11 +129,13 @@ del_symbol_error (void *a) compile_instance::compile_instance (struct gcc_base_context *gcc_fe, const char *options) : m_gcc_fe (gcc_fe), m_gcc_target_options (options), - m_symbol_err_map (NULL) + m_type_map (htab_create_alloc (10, hash_type_map_instance, + eq_type_map_instance, + xfree, xcalloc, xfree)), + m_symbol_err_map (htab_create_alloc (10, hash_symbol_error, + eq_symbol_error, del_symbol_error, + xcalloc, xfree)) { - m_type_map = htab_create_alloc (10, hash_type_map_instance, - eq_type_map_instance, - xfree, xcalloc, xfree); } /* See compile-internal.h. */ @@ -144,7 +146,7 @@ compile_instance::get_cached_type (struct type *type, gcc_type &ret) const struct type_map_instance inst, *found; inst.type = type; - found = (struct type_map_instance *) htab_find (m_type_map, &inst); + found = (struct type_map_instance *) htab_find (m_type_map.get (), &inst); if (found != NULL) { ret = found->gcc_type_handle; @@ -164,7 +166,7 @@ compile_instance::insert_type (struct type *type, gcc_type gcc_type) inst.type = type; inst.gcc_type_handle = gcc_type; - slot = htab_find_slot (m_type_map, &inst, INSERT); + slot = htab_find_slot (m_type_map.get (), &inst, INSERT); add = (struct type_map_instance *) *slot; /* The type might have already been inserted in order to handle @@ -189,18 +191,8 @@ compile_instance::insert_symbol_error (const struct symbol *sym, struct symbol_error e; void **slot; - if (m_symbol_err_map == NULL) - { - m_symbol_err_map = htab_create_alloc (10, - hash_symbol_error, - eq_symbol_error, - del_symbol_error, - xcalloc, - xfree); - } - e.sym = sym; - slot = htab_find_slot (m_symbol_err_map, &e, INSERT); + slot = htab_find_slot (m_symbol_err_map.get (), &e, INSERT); if (*slot == NULL) { struct symbol_error *e = XNEW (struct symbol_error); @@ -223,7 +215,7 @@ compile_instance::error_symbol_once (const struct symbol *sym) return; search.sym = sym; - err = (struct symbol_error *) htab_find (m_symbol_err_map, &search); + err = (struct symbol_error *) htab_find (m_symbol_err_map.get (), &search); if (err == NULL || err->message == NULL) return; |