Patchwork [1/5] obstack tidy part 1

login
register
mail settings
Submitter Alan Modra
Date Oct. 29, 2014, 3:32 a.m.
Message ID <20141029033213.GJ4267@bubble.grove.modra.org>
Download mbox | patch
Permalink /patch/3453/
State New
Headers show

Comments

Alan Modra - Oct. 29, 2014, 3:32 a.m.
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(-)
Roland McGrath - Oct. 30, 2014, 7:43 p.m.
Looks OK from the libc side.

Patch

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__ */