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)
#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
/* 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.
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)
{
/* 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 _
# 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 */