obstack: pacify HP C
[gnulib.git] / lib / obstack.h
index 7a65bac..67c0b55 100644 (file)
@@ -1,20 +1,20 @@
 /* obstack.h - object stack macros
 /* obstack.h - object stack macros
-   Copyright (C) 1988-1994,1996-1999,2003,2004,2005,2006
-        Free Software Foundation, Inc.
+   Copyright (C) 1988-2013 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    This file is part of the GNU C Library.
 
-   This program is free software: you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3 of the License, or
-   (at your option) any later version.
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
 
 
-   You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+   You should have received a copy of the GNU Lesser General Public
+   License along with this program; if not, see
+   <http://www.gnu.org/licenses/>.  */
 
 /* Summary:
 
 
 /* Summary:
 
@@ -32,11 +32,11 @@ stack" is typically an immature growing object, while the rest of the
 stack is of mature, fixed size and fixed address objects.
 
 These routines grab large chunks of memory, using a function you
 stack is of mature, fixed size and fixed address objects.
 
 These routines grab large chunks of memory, using a function you
-supply, called `obstack_chunk_alloc'.  On occasion, they free chunks,
-by calling `obstack_chunk_free'.  You must define them and declare
+supply, called 'obstack_chunk_alloc'.  On occasion, they free chunks,
+by calling 'obstack_chunk_free'.  You must define them and declare
 them before using any obstack macros.
 
 them before using any obstack macros.
 
-Each independent stack is represented by a `struct obstack'.
+Each independent stack is represented by a 'struct obstack'.
 Each of the obstack macros expects a pointer to such a structure
 as the first argument.
 
 Each of the obstack macros expects a pointer to such a structure
 as the first argument.
 
@@ -93,7 +93,7 @@ Summary:
         Exactly one object is growing in an obstack at any one time.
         You can run one obstack per control block.
         You may have as many control blocks as you dare.
         Exactly one object is growing in an obstack at any one time.
         You can run one obstack per control block.
         You may have as many control blocks as you dare.
-        Because of the way we do it, you can `unwind' an obstack
+        Because of the way we do it, you can "unwind" an obstack
           back to a previous state. (You may remove objects much
           as you would with a stack.)
 */
           back to a previous state. (You may remove objects much
           as you would with a stack.)
 */
@@ -103,10 +103,6 @@ Summary:
 
 #ifndef _OBSTACK_H
 #define _OBSTACK_H 1
 
 #ifndef _OBSTACK_H
 #define _OBSTACK_H 1
-
-#ifdef __cplusplus
-extern "C" {
-#endif
 \f
 /* We need the type of a pointer subtraction.  If __PTRDIFF_TYPE__ is
    defined, as with GNU C, use that; that way we don't pollute the
 \f
 /* We need the type of a pointer subtraction.  If __PTRDIFF_TYPE__ is
    defined, as with GNU C, use that; that way we don't pollute the
@@ -126,7 +122,7 @@ extern "C" {
 
 #define __BPTR_ALIGN(B, P, A) ((B) + (((P) - (B) + (A)) & ~(A)))
 
 
 #define __BPTR_ALIGN(B, P, A) ((B) + (((P) - (B) + (A)) & ~(A)))
 
-/* Similiar to _BPTR_ALIGN (B, P, A), except optimize the common case
+/* Similar to _BPTR_ALIGN (B, P, A), except optimize the common case
    where pointers can be converted to integers, aligned as integers,
    and converted back again.  If PTR_INT_TYPE is narrower than a
    pointer (e.g., the AS/400), play it safe and compute the alignment
    where pointers can be converted to integers, aligned as integers,
    and converted back again.  If PTR_INT_TYPE is narrower than a
    pointer (e.g., the AS/400), play it safe and compute the alignment
@@ -139,6 +135,10 @@ extern "C" {
 
 #include <string.h>
 
 
 #include <string.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 struct _obstack_chunk           /* Lives at front of each chunk. */
 {
   char  *limit;                 /* 1 past end of this chunk */
 struct _obstack_chunk           /* Lives at front of each chunk. */
 {
   char  *limit;                 /* 1 past end of this chunk */
@@ -159,7 +159,7 @@ struct obstack          /* control current object in current chunk */
     void *tempptr;
   } temp;                       /* Temporary for some macros.  */
   int   alignment_mask;         /* Mask of alignment for each object. */
     void *tempptr;
   } 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
+  /* These prototypes vary based on 'use_extra_arg', and we use
      casts to the prototypeless function type in all assignments,
      but having prototypes here quiets -Wstrict-prototypes.  */
   struct _obstack_chunk *(*chunkfun) (void *, long);
      casts to the prototypeless function type in all assignments,
      but having prototypes here quiets -Wstrict-prototypes.  */
   struct _obstack_chunk *(*chunkfun) (void *, long);
@@ -183,7 +183,7 @@ extern int _obstack_begin (struct obstack *, int, int,
 extern int _obstack_begin_1 (struct obstack *, int, int,
                              void *(*) (void *, long),
                              void (*) (void *, void *), void *);
 extern int _obstack_begin_1 (struct obstack *, int, int,
                              void *(*) (void *, long),
                              void (*) (void *, void *), void *);
-extern int _obstack_memory_used (struct obstack *);
+extern int _obstack_memory_used (struct obstack *) _GL_ATTRIBUTE_PURE;
 
 /* The default name of the function for freeing a chunk is 'obstack_free',
    but gnulib users can override this by defining '__obstack_free'.  */
 
 /* The default name of the function for freeing a chunk is 'obstack_free',
    but gnulib users can override this by defining '__obstack_free'.  */
@@ -193,13 +193,13 @@ extern int _obstack_memory_used (struct obstack *);
 extern void __obstack_free (struct obstack *obstack, void *block);
 
 \f
 extern void __obstack_free (struct obstack *obstack, void *block);
 
 \f
-/* Error handler called when `obstack_chunk_alloc' failed to allocate
+/* Error handler called when 'obstack_chunk_alloc' failed to allocate
    more memory.  This can be set to a user defined function which
    should either abort gracefully or use longjump - but shouldn't
    return.  The default action is to print a message and abort.  */
 extern void (*obstack_alloc_failed_handler) (void);
 
    more memory.  This can be set to a user defined function which
    should either abort gracefully or use longjump - but shouldn't
    return.  The default action is to print a message and abort.  */
 extern void (*obstack_alloc_failed_handler) (void);
 
-/* Exit value used when `print_and_abort' is used.  */
+/* Exit value used when 'print_and_abort' is used.  */
 extern int obstack_exit_failure;
 \f
 /* Pointer to beginning of object being allocated or to be allocated next.
 extern int obstack_exit_failure;
 \f
 /* Pointer to beginning of object being allocated or to be allocated next.
@@ -253,7 +253,7 @@ extern int obstack_exit_failure;
 
 #define obstack_memory_used(h) _obstack_memory_used (h)
 \f
 
 #define obstack_memory_used(h) _obstack_memory_used (h)
 \f
-#if defined __GNUC__ && defined __STDC__ && __STDC__
+#if defined __GNUC__
 /* NextStep 2.0 cc is really gcc 1.93 but it defines __GNUC__ = 2 and
    does not implement __extension__.  But that compiler doesn't define
    __GNUC_MINOR__.  */
 /* NextStep 2.0 cc is really gcc 1.93 but it defines __GNUC__ = 2 and
    does not implement __extension__.  But that compiler doesn't define
    __GNUC_MINOR__.  */
@@ -264,7 +264,7 @@ extern int obstack_exit_failure;
 /* For GNU C, if not -traditional,
    we can define these macros to compute all args only once
    without using a global variable.
 /* For GNU C, if not -traditional,
    we can define these macros to compute all args only once
    without using a global variable.
-   Also, we can avoid using the `temp' slot, to make faster code.  */
+   Also, we can avoid using the 'temp' slot, to make faster code.  */
 
 # define obstack_object_size(OBSTACK)                                   \
   __extension__                                                         \
 
 # define obstack_object_size(OBSTACK)                                   \
   __extension__                                                         \
@@ -342,14 +342,16 @@ __extension__                                                           \
 # define obstack_ptr_grow_fast(OBSTACK,aptr)                            \
 __extension__                                                           \
 ({ struct obstack *__o1 = (OBSTACK);                                    \
 # define obstack_ptr_grow_fast(OBSTACK,aptr)                            \
 __extension__                                                           \
 ({ struct obstack *__o1 = (OBSTACK);                                    \
-   *(const void **) __o1->next_free = (aptr);                           \
+   void *__p1 = __o1->next_free;                                        \
+   *(const void **) __p1 = (aptr);                                      \
    __o1->next_free += sizeof (const void *);                            \
    (void) 0; })
 
 # define obstack_int_grow_fast(OBSTACK,aint)                            \
 __extension__                                                           \
 ({ struct obstack *__o1 = (OBSTACK);                                    \
    __o1->next_free += sizeof (const void *);                            \
    (void) 0; })
 
 # define obstack_int_grow_fast(OBSTACK,aint)                            \
 __extension__                                                           \
 ({ struct obstack *__o1 = (OBSTACK);                                    \
-   *(int *) __o1->next_free = (aint);                                   \
+   void *__p1 = __o1->next_free;                                        \
+   *(int *) __p1 = (aint);                                              \
    __o1->next_free += sizeof (int);                                     \
    (void) 0; })
 
    __o1->next_free += sizeof (int);                                     \
    (void) 0; })
 
@@ -405,7 +407,7 @@ __extension__                                                           \
      __o->next_free = __o->object_base = (char *)__obj;                 \
    else (__obstack_free) (__o, __obj); })
 \f
      __o->next_free = __o->object_base = (char *)__obj;                 \
    else (__obstack_free) (__o, __obj); })
 \f
-#else /* not __GNUC__ or not __STDC__ */
+#else /* not __GNUC__ */
 
 # define obstack_object_size(h) \
  (unsigned) ((h)->next_free - (h)->object_base)
 
 # define obstack_object_size(h) \
  (unsigned) ((h)->next_free - (h)->object_base)
@@ -499,11 +501,11 @@ __extension__                                                           \
 ( (h)->temp.tempint = (char *) (obj) - (char *) (h)->chunk,             \
   ((((h)->temp.tempint > 0                                              \
     && (h)->temp.tempint < (h)->chunk_limit - (char *) (h)->chunk))     \
 ( (h)->temp.tempint = (char *) (obj) - (char *) (h)->chunk,             \
   ((((h)->temp.tempint > 0                                              \
     && (h)->temp.tempint < (h)->chunk_limit - (char *) (h)->chunk))     \
-   ? (int) ((h)->next_free = (h)->object_base                           \
-            = (h)->temp.tempint + (char *) (h)->chunk)                  \
-   : (((__obstack_free) ((h), (h)->temp.tempint + (char *) (h)->chunk), 0), 0)))
+   ? (void) ((h)->next_free = (h)->object_base                          \
+             = (h)->temp.tempint + (char *) (h)->chunk)                 \
+   : (__obstack_free) (h, (h)->temp.tempint + (char *) (h)->chunk)))
 
 
-#endif /* not __GNUC__ or not __STDC__ */
+#endif /* not __GNUC__ */
 
 #ifdef __cplusplus
 }       /* C++ */
 
 #ifdef __cplusplus
 }       /* C++ */