]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
obstack: match obstack.c with glibc
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 5 May 2025 21:02:21 +0000 (14:02 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 5 May 2025 21:16:23 +0000 (14:16 -0700)
Make this file easier to compare with glibc obstack.c.
* lib/obstack.c: Include shlib-compat.h or libc-config.h.
Move some !_OBSTACK_NO_ERROR_HANDLER declarations up.
Add _LIBC-only compatibility decls.
* modules/obstack (Depends-on): Add libc-config.

ChangeLog
lib/obstack.c
modules/obstack

index 20f9e7bc3c944759edf7c5f1b78b414b2172330a..f9da2b846b003d6bc4be49340786bcc33a41dcc6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2025-05-05  Paul Eggert  <eggert@cs.ucla.edu>
 
+       obstack: match obstack.c with glibc
+       Make this file easier to compare with glibc obstack.c.
+       * lib/obstack.c: Include shlib-compat.h or libc-config.h.
+       Move some !_OBSTACK_NO_ERROR_HANDLER declarations up.
+       Add _LIBC-only compatibility decls.
+       * modules/obstack (Depends-on): Add libc-config.
+
        obstack: simplify default size, alignment
        * lib/obstack.c (MAX, DEFAULT_ALIGNMENT, DEFAULT_ROUNDING): Remove.
        (_obstack_begin_worker): Use __alignof__ (max_align_t)
index 1fac1cd404b97d6e8bd6d22040245bc4a350b606..9c158867174655e6cac5fdb9d03d34bf7b8aeea7 100644 (file)
@@ -19,8 +19,9 @@
 
 #ifdef _LIBC
 # include <obstack.h>
+# include <shlib-compat.h>
 #else
-# include <config.h>
+# include <libc-config.h>
 # include "obstack.h"
 #endif
 
  #error "SIZE_MAX <= INT_MAX"
 #endif
 
+#ifndef _OBSTACK_NO_ERROR_HANDLER
+
+/* 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 __attribute_noreturn__ void print_and_abort (void);
+__attribute_noreturn__ void (*obstack_alloc_failed_handler) (void)
+  = print_and_abort;
+
+/* 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
+
+#endif /* !_OBSTACK_NO_ERROR_HANDLER */
+
+#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
+   was used by non-GNU-C macros to avoid multiple evaluation.  The GNU C
+   library still exports it because somebody might use it.  */
+struct obstack *_obstack_compat = NULL;
+compat_symbol (libc, _obstack_compat, _obstack, GLIBC_2_0);
+#endif
+
 /* Return the least multiple of MASK + 1 that is not less than SIZE.
    MASK + 1 must be a power of 2.  On overflow, return zero.  */
 static size_t
@@ -226,6 +257,7 @@ _obstack_newchunk (struct obstack *h, _OBSTACK_INDEX_T length)
   /* The new chunk certainly contains no empty object yet.  */
   h->maybe_empty_object = 0;
 }
+libc_hidden_def (_obstack_newchunk)
 
 /* Return nonzero if object OBJ has been allocated from obstack H.
    This is here for debugging.
@@ -288,6 +320,10 @@ __obstack_free (struct obstack *h, void *obj)
     abort ();
 }
 
+/* Older versions of libc used a function _obstack_free intended to be
+   called by non-GCC compilers.  */
+strong_alias (obstack_free, _obstack_free)
+
 _OBSTACK_INDEX_T
 _obstack_memory_used (struct obstack *h)
 {
@@ -305,14 +341,6 @@ _obstack_memory_used (struct obstack *h)
 /* Define the error handler.  */
 # include <stdio.h>
 
-/* 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>
 #  ifndef _
@@ -344,13 +372,4 @@ print_and_abort (void)
 # endif
   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'.  */
-__attribute_noreturn__ void (*obstack_alloc_failed_handler) (void)
-  = print_and_abort;
 #endif /* !_OBSTACK_NO_ERROR_HANDLER */
index f22a7a1cc48d0826717b513e110f81fdee26fa8e..4c292556697f5f4837074633f59c80b58208b839 100644 (file)
@@ -9,6 +9,7 @@ m4/obstack.m4
 Depends-on:
 gen-header
 alignasof       [test $HAVE_OBSTACK = 0 || test $REPLACE_OBSTACK = 1]
+libc-config     [test $HAVE_OBSTACK = 0 || test $REPLACE_OBSTACK = 1]
 flexmember      [test $HAVE_OBSTACK = 0 || test $REPLACE_OBSTACK = 1]
 gettext-h       [test $HAVE_OBSTACK = 0 || test $REPLACE_OBSTACK = 1]
 gnulib-i18n     [test $HAVE_OBSTACK = 0 || test $REPLACE_OBSTACK = 1]