From patchwork Fri Oct 31 00:38:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 3509 Received: (qmail 12482 invoked by alias); 31 Oct 2014 00:38:45 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 12472 invoked by uid 89); 31 Oct 2014 00:38:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pd0-f169.google.com X-Received: by 10.68.98.196 with SMTP id ek4mr8092708pbb.150.1414715921442; Thu, 30 Oct 2014 17:38:41 -0700 (PDT) Date: Fri, 31 Oct 2014 11:08:33 +1030 From: Alan Modra To: Roland McGrath Cc: libc-alpha@sourceware.org, bug-gnulib@gnu.org Subject: Re: [PATCH 3/5] 64-bit obstack support, part 1 Message-ID: <20141031003833.GT4267@bubble.grove.modra.org> References: <20141029033231.GL4267@bubble.grove.modra.org> <20141030195229.3304E2C3B15@topped-with-meat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20141030195229.3304E2C3B15@topped-with-meat.com> User-Agent: Mutt/1.5.23 (2014-03-12) On Thu, Oct 30, 2014 at 12:52:29PM -0700, Roland McGrath wrote: > It would be easier to review if you separated the very trivial changes from > the others. The size_t change is clearly fine and can be approved quickly. > The refactoring requires more attention. Split as requested and attached. From cc881bf50b127aef86c8550bb2b12affbae8f5c5 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Fri, 31 Oct 2014 11:01:49 +1030 Subject: [PATCH 2/2] 64-bit obstack support, part 1b Consolidate _obstack_begin and _obstack_begin1 code. * lib/obstack.c (chunkfun_type, freefun_type): New typdefs. (_obstack_begin_worker): Split out from .. (_obstack_begin, _obstack_begin_1): ..here. --- lib/obstack.c | 73 +++++++++++++++++++++-------------------------------------- 1 file changed, 26 insertions(+), 47 deletions(-) diff --git a/lib/obstack.c b/lib/obstack.c index dfdb664..d9beb9b 100644 --- a/lib/obstack.c +++ b/lib/obstack.c @@ -113,11 +113,13 @@ compat_symbol (libc, _obstack_compat, _obstack, GLIBC_2_0); Return nonzero if successful, calls obstack_alloc_failed_handler if allocation fails. */ -int -_obstack_begin (struct obstack *h, - int size, int alignment, - void *(*chunkfun) (size_t), - void (*freefun) (void *)) +typedef struct _obstack_chunk * (*chunkfun_type) (void *, size_t); +typedef void (*freefun_type) (void *, struct _obstack_chunk *); + +static int +_obstack_begin_worker (struct obstack *h, + int size, int alignment, + chunkfun_type chunkfun, freefun_type freefun) { struct _obstack_chunk *chunk; /* points to new chunk */ @@ -140,11 +142,10 @@ _obstack_begin (struct obstack *h, size = 4096 - extra; } - h->chunkfun = (struct _obstack_chunk * (*) (void *, size_t)) chunkfun; - h->freefun = (void (*) (void *, struct _obstack_chunk *)) freefun; + h->chunkfun = chunkfun; + h->freefun = freefun; h->chunk_size = size; h->alignment_mask = alignment - 1; - h->use_extra_arg = 0; chunk = h->chunk = CALL_CHUNKFUN (h, h->chunk_size); if (!chunk) @@ -160,51 +161,29 @@ _obstack_begin (struct obstack *h, } int -_obstack_begin_1 (struct obstack *h, int size, int alignment, +_obstack_begin (struct obstack *h, + int size, int alignment, + void *(*chunkfun) (size_t), + void (*freefun) (void *)) +{ + h->use_extra_arg = 0; + return _obstack_begin_worker (h, size, alignment, + (chunkfun_type) chunkfun, + (freefun_type) freefun); +} + +int +_obstack_begin_1 (struct obstack *h, + int size, int alignment, void *(*chunkfun) (void *, size_t), void (*freefun) (void *, void *), void *arg) { - struct _obstack_chunk *chunk; /* points to new chunk */ - - if (alignment == 0) - alignment = DEFAULT_ALIGNMENT; - if (size == 0) - /* Default size is what GNU malloc can fit in a 4096-byte block. */ - { - /* 12 is sizeof (mhead) and 4 is EXTRA from GNU malloc. - Use the values for range checking, because if range checking is off, - the extra bytes won't be missed terribly, but if range checking is on - and we used a larger request, a whole extra 4096 bytes would be - allocated. - - These number are irrelevant to the new GNU malloc. I suspect it is - less sensitive to the size of the request. */ - int extra = ((((12 + DEFAULT_ROUNDING - 1) & ~(DEFAULT_ROUNDING - 1)) - + 4 + DEFAULT_ROUNDING - 1) - & ~(DEFAULT_ROUNDING - 1)); - size = 4096 - extra; - } - - h->chunkfun = (struct _obstack_chunk * (*)(void *,size_t)) chunkfun; - h->freefun = (void (*) (void *, struct _obstack_chunk *)) freefun; - h->chunk_size = size; - h->alignment_mask = alignment - 1; h->extra_arg = arg; h->use_extra_arg = 1; - - chunk = h->chunk = CALL_CHUNKFUN (h, h->chunk_size); - if (!chunk) - (*obstack_alloc_failed_handler) (); - h->next_free = h->object_base = __PTR_ALIGN ((char *) chunk, chunk->contents, - alignment - 1); - h->chunk_limit = chunk->limit - = (char *) chunk + h->chunk_size; - chunk->prev = 0; - /* The initial chunk now contains no empty object. */ - h->maybe_empty_object = 0; - h->alloc_failed = 0; - return 1; + return _obstack_begin_worker (h, size, alignment, + (chunkfun_type) chunkfun, + (freefun_type) freefun); } /* Allocate a new current chunk for the obstack *H