public inbox for binutils-cvs@sourceware.org
 help / color / mirror / Atom feed
* [binutils-gdb] bfd/cache: change type used to track cached BFDs from int to unsigned
@ 2023-10-12 12:59 Andrew Burgess
  0 siblings, 0 replies; only message in thread
From: Andrew Burgess @ 2023-10-12 12:59 UTC (permalink / raw)
  To: bfd-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=241f29fba6ab4c584eeb4e7f53302aa92d2c11f4

commit 241f29fba6ab4c584eeb4e7f53302aa92d2c11f4
Author: Andrew Burgess <aburgess@redhat.com>
Date:   Wed Oct 11 14:39:37 2023 +0100

    bfd/cache: change type used to track cached BFDs from int to unsigned
    
    Within bfd/cache.c change the type for max_open_files and open_files
    variables from int to unsigned.  As a consequence of this, the return
    type for bfd_cache_max_open() is also changed from int to unsigned.
    
    Within bfd_cache_max_open I've left the local 'max' variable as an
    int, this should ensure that if the sysconf call fails, and returns
    -1, then the computed max value will be less than 10, which means
    max_open_files will be set to 10.  If 'max' was changed to unsigned
    then, should the sysconf call fail, we'd end up with max becoming a
    very large positive number ... which is clearly not what we want.
    
    And, while I was auditing how open_files is used, I added an assert
    within bfd_cache_delete to ensure that we don't try to reduce
    open_files below zero.
    
    There should be no user visible change with this commit.

Diff:
---
 bfd/cache.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/bfd/cache.c b/bfd/cache.c
index 357a38da599..87c4bcd3148 100644
--- a/bfd/cache.c
+++ b/bfd/cache.c
@@ -67,11 +67,11 @@ enum cache_flag {
 /* The maximum number of files which the cache will keep open at
    one time.  When needed call bfd_cache_max_open to initialize.  */
 
-static int max_open_files = 0;
+static unsigned max_open_files = 0;
 
 /* Set max_open_files, if not already set, to 12.5% of the allowed open
    file descriptors, but at least 10, and return the value.  */
-static int
+static unsigned
 bfd_cache_max_open (void)
 {
   if (max_open_files == 0)
@@ -115,7 +115,7 @@ bfd_cache_max_open (void)
 
 /* The number of BFD files we have open.  */
 
-static int open_files;
+static unsigned open_files;
 
 /* Zero, or a pointer to the topmost BFD on the chain.  This is
    used by the <<bfd_cache_lookup>> macro in @file{libbfd.h} to
@@ -176,6 +176,7 @@ bfd_cache_delete (bfd *abfd)
   snip (abfd);
 
   abfd->iostream = NULL;
+  BFD_ASSERT (open_files > 0);
   --open_files;
   abfd->flags |= BFD_CLOSED_BY_CACHE;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-10-12 12:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-12 12:59 [binutils-gdb] bfd/cache: change type used to track cached BFDs from int to unsigned Andrew Burgess

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).