public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Tristan Gingold <gingold@adacore.com>
To: Alan Modra <amodra@gmail.com>
Cc: binutils Development <binutils@sourceware.org>
Subject: Re: [patch/gas]: simplify frag_grow
Date: Mon, 25 Jul 2011 14:49:00 -0000	[thread overview]
Message-ID: <61340859-9B00-46B5-B702-92FE873A9D74@adacore.com> (raw)
In-Reply-To: <20110711020551.GJ26365@bubble.grove.modra.org>


On Jul 11, 2011, at 4:05 AM, Alan Modra wrote:

> On Wed, Jul 06, 2011 at 09:00:29AM +0200, Tristan Gingold wrote:
>> +      if (newc <= 0)
>> +        as_fatal (_("can't extend frag to %u chars"), nchars);
> 
> Watch out for proliferation of messages.  There isn't any reason for a
> difference between this error and the later one.  (In fact this
> message isn't correct since we are extending the frag *by* nchars, not
> to a total size of nchars.)
> 
>> +      /* Force to allocate at least NEWC bytes.  */
>> +      oldc = obstack_chunk_size (&frchain_now->frch_obstack);
>> +      obstack_chunk_size (&frchain_now->frch_obstack) = newc;
>> +
>> +      /* Do the real work: create a new frag.  */
>> +      frag_new (0);
>> +
>> +      /* Restore the old chunk size.  */
>> +      obstack_chunk_size (&frchain_now->frch_obstack) = oldc;
> 
> An alternative to fixing the error message would be to wrap the above
> all in "if (newc > 0){}" and dispense with the first as_fatal call.
> Your choice.  Either way is OK to commit.

Thanks.  Here is what I am committing (using the later suggestion).

Tristan.

Index: frags.c
===================================================================
RCS file: /cvs/src/src/gas/frags.c,v
retrieving revision 1.26
diff -c -r1.26 frags.c
*** frags.c	11 Sep 2009 15:27:33 -0000	1.26
--- frags.c	25 Jul 2011 13:32:47 -0000
***************
*** 75,115 ****
    return ptr;
  }
  

! /* Try to augment current frag by nchars chars.
     If there is no room, close of the current frag with a ".fill 0"
!    and begin a new frag. Unless the new frag has nchars chars available
!    do not return. Do not set up any fields of *now_frag.  */
  
  void
  frag_grow (unsigned int nchars)
  {
    if (obstack_room (&frchain_now->frch_obstack) < nchars)
      {
-       unsigned int n;
        long oldc;
  
        frag_wane (frag_now);
!       frag_new (0);
!       oldc = frchain_now->frch_obstack.chunk_size;
        /* Try to allocate a bit more than needed right now.  But don't do
           this if we would waste too much memory.  Especially necessary
! 	 for extremely big (like 2GB initialized) frags.  */
        if (nchars < 0x10000)
! 	frchain_now->frch_obstack.chunk_size = 2 * nchars;
        else
!         frchain_now->frch_obstack.chunk_size = nchars + 0x10000;
!       frchain_now->frch_obstack.chunk_size += SIZEOF_STRUCT_FRAG;
!       if (frchain_now->frch_obstack.chunk_size > 0)
! 	while ((n = obstack_room (&frchain_now->frch_obstack)) < nchars
! 	       && (unsigned long) frchain_now->frch_obstack.chunk_size > nchars)
! 	  {
! 	    frag_wane (frag_now);
! 	    frag_new (0);
! 	  }
!       frchain_now->frch_obstack.chunk_size = oldc;
      }
-   if (obstack_room (&frchain_now->frch_obstack) < nchars)
-     as_fatal (_("can't extend frag %u chars"), nchars);
  }
  

  /* Call this to close off a completed frag, and start up a new (empty)
--- 75,121 ----
    return ptr;
  }
  

! /* Try to augment current frag by NCHARS chars.
     If there is no room, close of the current frag with a ".fill 0"
!    and begin a new frag.  Do not set up any fields of *now_frag.  */
  
  void
  frag_grow (unsigned int nchars)
  {
    if (obstack_room (&frchain_now->frch_obstack) < nchars)
      {
        long oldc;
+       long newc;
  
+       /* Not enough room in this frag.  Close it.  */
        frag_wane (frag_now);
! 
        /* Try to allocate a bit more than needed right now.  But don't do
           this if we would waste too much memory.  Especially necessary
!          for extremely big (like 2GB initialized) frags.  */
        if (nchars < 0x10000)
!         newc = 2 * nchars;
        else
!         newc = nchars + 0x10000;
!       newc += SIZEOF_STRUCT_FRAG;
! 
!       if (newc > 0)
!         {
!           /* Force to allocate at least NEWC bytes.  */
!           oldc = obstack_chunk_size (&frchain_now->frch_obstack);
!           obstack_chunk_size (&frchain_now->frch_obstack) = newc;
! 
!           /* Do the real work: create a new frag.  */
!           frag_new (0);
! 
!           /* Restore the old chunk size.  */
!           obstack_chunk_size (&frchain_now->frch_obstack) = oldc;
!         }
! 
!       /* Check for success (also handles negative values of NEWC).  */
!       if (obstack_room (&frchain_now->frch_obstack) < nchars)
!         as_fatal (_("can't extend frag %u chars"), nchars);
      }
  }
  

  /* Call this to close off a completed frag, and start up a new (empty)

  reply	other threads:[~2011-07-25 13:35 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-05 17:49 Tristan Gingold
2011-07-06  4:45 ` Alan Modra
2011-07-06  7:25   ` Tristan Gingold
2011-07-11 12:05     ` Alan Modra
2011-07-25 14:49       ` Tristan Gingold [this message]
2011-07-26 20:14         ` Steve Ellcey
2011-07-26 21:14 ` Steve Ellcey
2011-07-27  6:56   ` Hans-Peter Nilsson
2011-07-27  7:39     ` Tristan Gingold
2011-07-27 10:06     ` Tristan Gingold
2011-07-27 16:08     ` [patch v2/gas]: " Tristan Gingold
2011-07-29  6:01       ` Alan Modra
2011-08-01  8:06         ` Tristan Gingold
2011-07-27 11:42   ` [patch/gas]: " Tristan Gingold

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=61340859-9B00-46B5-B702-92FE873A9D74@adacore.com \
    --to=gingold@adacore.com \
    --cc=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).