libctf: simplify ctf_txlate

Before now, this critical internal structure was an array mapping from a
type ID to the type index of the type with that ID.  This was critical for
the old world in which ctf_update() reserialized the entire dict, so things
moved around in memory all the time: but these days, a ctf_type_t * never
moves after creation, so we can just make ctf_txlate an array of ctf_type_t *
and be done with it.

This lets us point type indexes anywhere in memory, not just to entries
in the ctf_buf, which means we can have synthetic ones for various purposes.
And we will.
This commit is contained in:
Nick Alcock
2025-04-03 15:21:47 +01:00
parent 1d70873382
commit a80b903b45
2 changed files with 5 additions and 6 deletions

View File

@@ -696,7 +696,7 @@ init_static_types (ctf_dict_t *fp, ctf_header_t *cth)
because later-added types will call grow_ptrtab() automatically, as
needed. */
fp->ctf_txlate = calloc (typemax + 1, sizeof (uint32_t));
fp->ctf_txlate = calloc (typemax + 1, sizeof (ctf_type_t *));
fp->ctf_ptrtab = calloc (typemax + 1, sizeof (uint32_t));
fp->ctf_ptrtab_len = typemax + 1;
fp->ctf_stypes = typemax;
@@ -773,8 +773,7 @@ init_static_types_names_internal (ctf_dict_t *fp, ctf_header_t *cth,
assert (!(fp->ctf_flags & LCTF_NO_STR));
xp = fp->ctf_txlate;
*xp++ = 0; /* Type id 0 is used as a sentinel value. */
xp = &fp->ctf_txlate[1];
/* In this second pass through the types, we fill in each entry of the type
and pointer tables and add names to the appropriate hashes.