public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@gmail.com>
To: libc-alpha@sourceware.org, bug-gnulib@gnu.org
Subject: [PATCH 1/5] obstack tidy part 1
Date: Wed, 29 Oct 2014 03:32:00 -0000	[thread overview]
Message-ID: <20141029033213.GJ4267@bubble.grove.modra.org> (raw)
In-Reply-To: <cover.1414461460.git.amodra@gmail.com>

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 <temp>): 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 <stdlib.h>
 # include <stdint.h>
 
 /* 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 <stdlib.h>
-# 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 <libintl.h>
 # 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__ */
 

-- 
Alan Modra
Australia Development Lab, IBM

  parent reply	other threads:[~2014-10-29  3:32 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1414461460.git.amodra@gmail.com>
2014-10-29  3:32 ` [PATCH 2/5] obstack tidy part 2 Alan Modra
2014-10-30 19:51   ` Roland McGrath
2014-10-30 23:54     ` Alan Modra
2014-10-29  3:32 ` Alan Modra [this message]
2014-10-30 19:43   ` [PATCH 1/5] obstack tidy part 1 Roland McGrath
2014-10-29  3:32 ` [PATCH 3/5] 64-bit obstack support, " Alan Modra
2014-10-30 19:52   ` Roland McGrath
2014-10-31  0:38     ` Alan Modra
2014-10-29  3:32 ` [PATCH 4/5] 64-bit obstack support, part 2 Alan Modra
2014-10-29  3:33 ` [PATCH 5/5] 64-bit obstack support, part 3 Alan Modra
2014-10-29  3:35 ` [PATCH] 64-bit obstack support Alan Modra
2014-10-29 18:34   ` Joseph S. Myers
2014-10-30  1:53     ` Alan Modra

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=20141029033213.GJ4267@bubble.grove.modra.org \
    --to=amodra@gmail.com \
    --cc=bug-gnulib@gnu.org \
    --cc=libc-alpha@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).