]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
libctf, hash: add support for freeing functions taking an arg
authorNick Alcock <nick.alcock@oracle.com>
Mon, 13 Jan 2025 11:34:56 +0000 (11:34 +0000)
committerNick Alcock <nick.alcock@oracle.com>
Fri, 28 Feb 2025 15:13:23 +0000 (15:13 +0000)
commit6a6a3cc9c209d55494f8688c3cfe8ccf8aa209b5
treeede71f8272cf48dd8708e865bed852ea6a5973c1
parentd996ca5e85002263d5f0013519fcdeafccd85561
libctf, hash: add support for freeing functions taking an arg

There are a bunch of places in libctf where the code is complicated
by the fact that freeing a hash key or value requires access to the
dict: more generally, they want an arg pointer to *something*.

But for the sake of being able to use free() as a freeing function,
we can't do this at all times.  We also don't want to bloat up the
hash itself with an arg value unless necessary (in the same way we
already avoid storing the key or value freeing functions unless at
least one of them is specified).

So from the outside this change is simple: add a new
ctf_dynhash_create_arg which takes a new sort of freeing function
which takes an argument.  Internally, we store the arg only when
the key or owner is set, and cast from the one freeing function
to the other iff the arg is non-NULL.  This means it's impossible
to pass a value that may or may not be NULL to the freeing
function, but that's harmless for all current uses, and allows
significant simplifications elsewhere.
libctf/ctf-hash.c
libctf/ctf-impl.h
libctf/ctf-open.c