From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10887 invoked by alias); 27 Jul 2011 13:20:22 -0000 Received: (qmail 10868 invoked by uid 22791); 27 Jul 2011 13:20:20 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (194.98.77.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 27 Jul 2011 13:20:03 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id EE195CB0395; Wed, 27 Jul 2011 15:20:01 +0200 (CEST) Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id o5b4Renk9NPt; Wed, 27 Jul 2011 15:19:51 +0200 (CEST) Received: from ulanbator.act-europe.fr (ulanbator.act-europe.fr [10.10.1.67]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by mel.act-europe.fr (Postfix) with ESMTP id 607B8CB035D; Wed, 27 Jul 2011 15:19:51 +0200 (CEST) Subject: [patch v2/gas]: simplify frag_grow Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=us-ascii From: Tristan Gingold In-Reply-To: Date: Wed, 27 Jul 2011 16:08:00 -0000 Cc: Steve Ellcey , Hans-Peter Nilsson , Alan Modra Content-Transfer-Encoding: quoted-printable Message-Id: <28DCFF4C-A0AC-474C-BF84-BFC8683C081A@adacore.com> References: <201107262013.p6QKDg308492@sapph05.cup.hp.com> To: binutils Development X-IsSubscribed: yes Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org X-SW-Source: 2011-07/txt/msg00235.txt.bz2 Hi, the issue in the first version of the patch is that frag_new() doesn't nece= ssary allocates memory as it can reuse the current chunk. So this patch keeps the while loop around frag_new(). So this second version of the patch is less radical than the first one, and= I still find the loop unpleasant as it can create empty frags. But I think this patch makes the code easier to read, still remove unused v= ariables, use obstack_chunk_size instead of accessing directly private fiel= ds, avoids an useless 'if' when there is enough room and finally add some c= omments. No regressions for cris-elf (which has some nice testcases for broken-words= ). Ok for trunk ? Tristan. 2011-07-05 Tristan Gingold * frags.c (frag_grow): Simplify the code. diff --git a/gas/frags.c b/gas/frags.c index 17110bb..0457f66 100644 --- a/gas/frags.c +++ b/gas/frags.c @@ -85,31 +85,38 @@ frag_grow (unsigned int nchars) { if (obstack_room (&frchain_now->frch_obstack) < nchars) { - unsigned int n; long oldc; + long newc; =20 - frag_wane (frag_now); - frag_new (0); - oldc =3D 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. */ + for extremely big (like 2GB initialized) frags. */ if (nchars < 0x10000) - frchain_now->frch_obstack.chunk_size =3D 2 * nchars; + newc =3D 2 * nchars; else - frchain_now->frch_obstack.chunk_size =3D nchars + 0x10000; - frchain_now->frch_obstack.chunk_size +=3D SIZEOF_STRUCT_FRAG; - if (frchain_now->frch_obstack.chunk_size > 0) - while ((n =3D 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 =3D oldc; + newc =3D nchars + 0x10000; + newc +=3D SIZEOF_STRUCT_FRAG; + + /* Check for possible overflow. */ + if (newc < 0) + as_fatal (_("can't extend frag %u chars"), nchars); + + /* Force to allocate at least NEWC bytes. */ + oldc =3D obstack_chunk_size (&frchain_now->frch_obstack); + obstack_chunk_size (&frchain_now->frch_obstack) =3D newc; + + while (obstack_room (&frchain_now->frch_obstack) < nchars) + { + /* Not enough room in this frag. Close it and start a new one. + This must be done in a loop because the created frag may not + be big enough if the current obstack chunk is used. */ + frag_wane (frag_now); + frag_new (0); + } + + /* Restore the old chunk size. */ + obstack_chunk_size (&frchain_now->frch_obstack) =3D oldc; } - if (obstack_room (&frchain_now->frch_obstack) < nchars) - as_fatal (_("can't extend frag %u chars"), nchars); } =20 /* Call this to close off a completed frag, and start up a new (empty)