aboutsummaryrefslogtreecommitdiff
path: root/libctf/ctf-create.c
diff options
context:
space:
mode:
authorNick Alcock <nick.alcock@oracle.com>2023-12-18 17:47:48 +0000
committerNick Alcock <nick.alcock@oracle.com>2024-04-19 16:14:46 +0100
commit54a0219150d9dd2b0034e9682072900d4ec403b3 (patch)
treee27705e3a8e7045f642e26330bacb5020b415d79 /libctf/ctf-create.c
parentca019227843f62f5ac0a1c432680e3ca05c4377b (diff)
downloadbinutils-54a0219150d9dd2b0034e9682072900d4ec403b3.zip
binutils-54a0219150d9dd2b0034e9682072900d4ec403b3.tar.gz
binutils-54a0219150d9dd2b0034e9682072900d4ec403b3.tar.bz2
libctf: remove static/dynamic name lookup distinction
libctf internally maintains a set of hash tables for type name lookups, one for each valid C type namespace (struct, union, enum, and everything else). Or, rather, it maintains *two* sets of hash tables: one, a ctf_hash *, is meant for lookups in ctf_(buf)open()ed dicts with fixed content; the other, a ctf_dynhash *, is meant for lookups in ctf_create()d dicts. This distinction was somewhat valuable in the far pre-binutils past when two different hashtable implementations were used (one expanding, the other fixed-size), but those days are long gone: the hash table implementations are almost identical, both wrappers around the libiberty hashtab. The ctf_dynhash has many more capabilities than the ctf_hash (iteration, deletion, etc etc) and has no downsides other than starting at a fixed, arbitrary small size. That limitation is easy to lift (via a new ctf_dynhash_create_sized()), following which we can throw away nearly all the ctf_hash implementation, and all the code to choose between readable and writable hashtabs; the few convenience functions that are still useful (for insertion of name -> type mappings) can also be generalized a bit so that the extra string verification they do is potentially available to other string lookups as well. (libctf still has two hashtable implementations, ctf_dynhash, above, and ctf_dynset, which is a key-only hashtab that can avoid a great many malloc()s, used for high-volume applications in the deduplicator.) libctf/ * ctf-create.c (ctf_create): Eliminate ctn_writable. (ctf_dtd_insert): Likewise. (ctf_dtd_delete): Likewise. (ctf_rollback): Likewise. (ctf_name_table): Eliminate ctf_names_t. * ctf-hash.c (ctf_dynhash_create): Comment update. Reimplement in terms of... (ctf_dynhash_create_sized): ... this new function. (ctf_hash_create): Remove. (ctf_hash_size): Remove. (ctf_hash_define_type): Remove. (ctf_hash_destroy): Remove. (ctf_hash_lookup_type): Rename to... (ctf_dynhash_lookup_type): ... this. (ctf_hash_insert_type): Rename to... (ctf_dynhash_insert_type): ... this, moving validation to... * ctf-string.c (ctf_strptr_validate): ... this new function. * ctf-impl.h (struct ctf_names): Extirpate. (struct ctf_lookup.ctl_hash): Now a ctf_dynhash_t. (struct ctf_dict): All ctf_names_t fields are now ctf_dynhash_t. (ctf_name_table): Now returns a ctf_dynhash_t. (ctf_lookup_by_rawhash): Remove. (ctf_hash_create): Likewise. (ctf_hash_insert_type): Likewise. (ctf_hash_define_type): Likewise. (ctf_hash_lookup_type): Likewise. (ctf_hash_size): Likewise. (ctf_hash_destroy): Likewise. (ctf_dynhash_create_sized): New. (ctf_dynhash_insert_type): New. (ctf_dynhash_lookup_type): New. (ctf_strptr_validate): New. * ctf-lookup.c (ctf_lookup_by_name_internal): Adapt. * ctf-open.c (init_types): Adapt. (ctf_set_ctl_hashes): Adapt. (ctf_dict_close): Adapt. * ctf-serialize.c (ctf_serialize): Adapt. * ctf-types.c (ctf_lookup_by_rawhash): Remove.
Diffstat (limited to 'libctf/ctf-create.c')
-rw-r--r--libctf/ctf-create.c26
1 files changed, 12 insertions, 14 deletions
diff --git a/libctf/ctf-create.c b/libctf/ctf-create.c
index 21fbad7..240f3da 100644
--- a/libctf/ctf-create.c
+++ b/libctf/ctf-create.c
@@ -154,10 +154,10 @@ ctf_create (int *errp)
if ((fp = ctf_bufopen_internal (&cts, NULL, NULL, NULL, 1, errp)) == NULL)
goto err_dv;
- fp->ctf_structs.ctn_writable = structs;
- fp->ctf_unions.ctn_writable = unions;
- fp->ctf_enums.ctn_writable = enums;
- fp->ctf_names.ctn_writable = names;
+ fp->ctf_structs = structs;
+ fp->ctf_unions = unions;
+ fp->ctf_enums = enums;
+ fp->ctf_names = names;
fp->ctf_objthash = objthash;
fp->ctf_funchash = funchash;
fp->ctf_dthash = dthash;
@@ -203,19 +203,19 @@ ctf_update (ctf_dict_t *fp)
return 0;
}
-ctf_names_t *
+ctf_dynhash_t *
ctf_name_table (ctf_dict_t *fp, int kind)
{
switch (kind)
{
case CTF_K_STRUCT:
- return &fp->ctf_structs;
+ return fp->ctf_structs;
case CTF_K_UNION:
- return &fp->ctf_unions;
+ return fp->ctf_unions;
case CTF_K_ENUM:
- return &fp->ctf_enums;
+ return fp->ctf_enums;
default:
- return &fp->ctf_names;
+ return fp->ctf_names;
}
}
@@ -230,7 +230,7 @@ ctf_dtd_insert (ctf_dict_t *fp, ctf_dtdef_t *dtd, int flag, int kind)
if (flag == CTF_ADD_ROOT && dtd->dtd_data.ctt_name
&& (name = ctf_strraw (fp, dtd->dtd_data.ctt_name)) != NULL)
{
- if (ctf_dynhash_insert (ctf_name_table (fp, kind)->ctn_writable,
+ if (ctf_dynhash_insert (ctf_name_table (fp, kind),
(char *) name, (void *) (uintptr_t)
dtd->dtd_type) < 0)
{
@@ -287,8 +287,7 @@ ctf_dtd_delete (ctf_dict_t *fp, ctf_dtdef_t *dtd)
&& (name = ctf_strraw (fp, dtd->dtd_data.ctt_name)) != NULL
&& LCTF_INFO_ISROOT (fp, dtd->dtd_data.ctt_info))
{
- ctf_dynhash_remove (ctf_name_table (fp, name_kind)->ctn_writable,
- name);
+ ctf_dynhash_remove (ctf_name_table (fp, name_kind), name);
ctf_str_remove_ref (fp, name, &dtd->dtd_data.ctt_name);
}
@@ -410,8 +409,7 @@ ctf_rollback (ctf_dict_t *fp, ctf_snapshot_id_t id)
&& (name = ctf_strraw (fp, dtd->dtd_data.ctt_name)) != NULL
&& LCTF_INFO_ISROOT (fp, dtd->dtd_data.ctt_info))
{
- ctf_dynhash_remove (ctf_name_table (fp, kind)->ctn_writable,
- name);
+ ctf_dynhash_remove (ctf_name_table (fp, kind), name);
ctf_str_remove_ref (fp, name, &dtd->dtd_data.ctt_name);
}