From patchwork Wed Oct 29 03:32:13 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 3453 Received: (qmail 31386 invoked by alias); 29 Oct 2014 03:32:25 -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 31328 invoked by uid 89); 29 Oct 2014 03:32:25 -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-pa0-f50.google.com X-Received: by 10.70.128.176 with SMTP id np16mr7884070pdb.118.1414553540986; Tue, 28 Oct 2014 20:32:20 -0700 (PDT) Date: Wed, 29 Oct 2014 14:02:13 +1030 From: Alan Modra To: libc-alpha@sourceware.org, bug-gnulib@gnu.org Subject: [PATCH 1/5] obstack tidy part 1 Message-ID: <20141029033213.GJ4267@bubble.grove.modra.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) a) Rename temp fields. temp.tempint and temp.tempptr just looks ugly to me, and result in overlong lines after later patches. b) Move error handling code, to avoid a forward declaration and to simplify later patches in this series. * lib/obstack.h (struct obstack ): Rename fields of union and update all uses. * lib/obstack.c: Include stdlib.h earlier. (obstack_exit_failure, obstack_alloc_failed_handler): Move later in file. (print_and_abort): Remove now redundant forward declaration. --- lib/obstack.c | 35 +++++++++++++++++------------------ lib/obstack.h | 52 ++++++++++++++++++++++++++-------------------------- 2 files changed, 43 insertions(+), 44 deletions(-) diff --git a/lib/obstack.c b/lib/obstack.c index 598f6aa..66573df 100644 --- a/lib/obstack.c +++ b/lib/obstack.c @@ -52,6 +52,7 @@ #ifndef ELIDE_CODE +# include # include /* Determine default alignment. */ @@ -84,24 +85,6 @@ enum # endif -/* The functions allocating more room by calling 'obstack_chunk_alloc' - jump to the handler pointed to by 'obstack_alloc_failed_handler'. - This can be set to a user defined function which should either - abort gracefully or use longjump - but shouldn't return. This - variable by default points to the internal function - 'print_and_abort'. */ -static _Noreturn void print_and_abort (void); -void (*obstack_alloc_failed_handler) (void) = print_and_abort; - -/* Exit value used when 'print_and_abort' is used. */ -# include -# ifdef _LIBC -int obstack_exit_failure = EXIT_FAILURE; -# else -# include "exitfail.h" -# define obstack_exit_failure exit_failure -# endif - # ifdef _LIBC # if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_3_4) /* A looong time ago (before 1994, anyway; we're not sure) this global variable @@ -391,6 +374,15 @@ _obstack_memory_used (struct obstack *h) } /* Define the error handler. */ + +/* Exit value used when 'print_and_abort' is used. */ +# ifdef _LIBC +int obstack_exit_failure = EXIT_FAILURE; +# else +# include "exitfail.h" +# define obstack_exit_failure exit_failure +# endif + # ifdef _LIBC # include # else @@ -420,4 +412,11 @@ print_and_abort (void) exit (obstack_exit_failure); } +/* The functions allocating more room by calling 'obstack_chunk_alloc' + jump to the handler pointed to by 'obstack_alloc_failed_handler'. + This can be set to a user defined function which should either + abort gracefully or use longjump - but shouldn't return. This + variable by default points to the internal function + 'print_and_abort'. */ +void (*obstack_alloc_failed_handler) (void) = print_and_abort; #endif /* !ELIDE_CODE */ diff --git a/lib/obstack.h b/lib/obstack.h index f92492f..cd90e4e 100644 --- a/lib/obstack.h +++ b/lib/obstack.h @@ -159,8 +159,8 @@ struct obstack /* control current object in current chunk */ char *chunk_limit; /* address of char after current chunk */ union { - PTR_INT_TYPE tempint; - void *tempptr; + PTR_INT_TYPE i; + void *p; } temp; /* Temporary for some macros. */ int alignment_mask; /* Mask of alignment for each object. */ /* These prototypes vary based on 'use_extra_arg', and we use @@ -429,23 +429,23 @@ extern int obstack_exit_failure; but some compilers won't accept it. */ # define obstack_make_room(h, length) \ - ((h)->temp.tempint = (length), \ - (((h)->next_free + (h)->temp.tempint > (h)->chunk_limit) \ - ? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0)) + ((h)->temp.i = (length), \ + (((h)->next_free + (h)->temp.i > (h)->chunk_limit) \ + ? (_obstack_newchunk ((h), (h)->temp.i), 0) : 0)) # define obstack_grow(h, where, length) \ - ((h)->temp.tempint = (length), \ - (((h)->next_free + (h)->temp.tempint > (h)->chunk_limit) \ - ? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0), \ - memcpy ((h)->next_free, where, (h)->temp.tempint), \ - (h)->next_free += (h)->temp.tempint) + ((h)->temp.i = (length), \ + (((h)->next_free + (h)->temp.i > (h)->chunk_limit) \ + ? (_obstack_newchunk ((h), (h)->temp.i), 0) : 0), \ + memcpy ((h)->next_free, where, (h)->temp.i), \ + (h)->next_free += (h)->temp.i) # define obstack_grow0(h, where, length) \ - ((h)->temp.tempint = (length), \ - (((h)->next_free + (h)->temp.tempint + 1 > (h)->chunk_limit) \ - ? (_obstack_newchunk ((h), (h)->temp.tempint + 1), 0) : 0), \ - memcpy ((h)->next_free, where, (h)->temp.tempint), \ - (h)->next_free += (h)->temp.tempint, \ + ((h)->temp.i = (length), \ + (((h)->next_free + (h)->temp.i + 1 > (h)->chunk_limit) \ + ? (_obstack_newchunk ((h), (h)->temp.i + 1), 0) : 0), \ + memcpy ((h)->next_free, where, (h)->temp.i), \ + (h)->next_free += (h)->temp.i, \ *((h)->next_free)++ = 0) # define obstack_1grow(h, datum) \ @@ -470,10 +470,10 @@ extern int obstack_exit_failure; (((int *) ((h)->next_free += sizeof (int)))[-1] = (aint)) # define obstack_blank(h, length) \ - ((h)->temp.tempint = (length), \ - (((h)->chunk_limit - (h)->next_free < (h)->temp.tempint) \ - ? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0), \ - obstack_blank_fast (h, (h)->temp.tempint)) + ((h)->temp.i = (length), \ + (((h)->chunk_limit - (h)->next_free < (h)->temp.i) \ + ? (_obstack_newchunk ((h), (h)->temp.i), 0) : 0), \ + obstack_blank_fast (h, (h)->temp.i)) # define obstack_alloc(h, length) \ (obstack_blank ((h), (length)), obstack_finish ((h))) @@ -488,7 +488,7 @@ extern int obstack_exit_failure; (((h)->next_free == (h)->object_base \ ? (((h)->maybe_empty_object = 1), 0) \ : 0), \ - (h)->temp.tempptr = (h)->object_base, \ + (h)->temp.p = (h)->object_base, \ (h)->next_free \ = __PTR_ALIGN ((h)->object_base, (h)->next_free, \ (h)->alignment_mask), \ @@ -496,15 +496,15 @@ extern int obstack_exit_failure; > (h)->chunk_limit - (char *) (h)->chunk) \ ? ((h)->next_free = (h)->chunk_limit) : 0), \ (h)->object_base = (h)->next_free, \ - (h)->temp.tempptr) + (h)->temp.p) # define obstack_free(h, obj) \ - ((h)->temp.tempint = (char *) (obj) - (char *) (h)->chunk, \ - ((((h)->temp.tempint > 0 \ - && (h)->temp.tempint < (h)->chunk_limit - (char *) (h)->chunk)) \ + ((h)->temp.i = (char *) (obj) - (char *) (h)->chunk, \ + ((((h)->temp.i > 0 \ + && (h)->temp.i < (h)->chunk_limit - (char *) (h)->chunk)) \ ? (void) ((h)->next_free = (h)->object_base \ - = (h)->temp.tempint + (char *) (h)->chunk) \ - : (__obstack_free) (h, (h)->temp.tempint + (char *) (h)->chunk))) + = (h)->temp.i + (char *) (h)->chunk) \ + : (__obstack_free) (h, (h)->temp.i + (char *) (h)->chunk))) #endif /* not __GNUC__ */