[PATCH] bfd: add new bfd_cache_size() function

Nick Clifton nickc@redhat.com
Mon Oct 9 14:01:33 GMT 2023


Hi Andrew,

> And so, to support this, I would like to add a new bfd_cache_size
> function.  This function returns an integer, which is the number of
> open files in the cache.  I can then start adding:
> 
>    gdb_assert (bfd_cache_size() == 0);
> 
> to GDB in some strategic spots, and start fixing all of the missing
> bfd_cache_close_all calls that crop up as a result.

Patch approved - please apply.

If you are feeling motivated then there is an associated change
that it would be nice to see made:

> +/*
> +FUNCTION
> +	bfd_cache_size
> +
> +SYNOPSIS
> +	int bfd_cache_size (void);
> +
> +DESCRIPTION
> +	Return the number of open files in the cache.
> +*/

It does not make sense for this function to return a negative
value.  (Or maybe it does - a negative value would indicate that
the cache does not exist, whereas 0 would indicate that it does
exist, but it is empty ?).

So if bfd_cache_size() returns an unsigned int then bfd_cache_max_open()
should as well, and the files_open and max_files_open variables should
be changed as well.

Of course in practice we should never see negative values or large values
for any of these variables/function-results, so using an "int" should be
just fine.  But it bugs me that functions and variables which should never
have negative values are being typed as if they could have them.

Cheers
   Nick



More information about the Binutils mailing list