2025-05-05 Paul Eggert <eggert@cs.ucla.edu>
+ obstack: merge better with glibc
+ When compiled for glibc, keep the fake array content size at 4,
+ for API compatibility with older glibc.
+ * lib/obstack.in.h (__FLEXIBLE_ARRAY_MEMBER): Remove.
+ (_OBSTACK_CHUNK_CONTENTS_SIZE): New macro.
+ (struct _obstack_chunk): Use it for contents size.
+ * modules/obstack (Depends-on): Add flexmember.
+
obstack: stop depending on alignof
* lib/obstack.c (__alignof__) [!__GNUC__]:
Default to alignof, not to alignof_type.
#define _OBSTACK_H 1
#if defined __GL_GNULIB_HEADER
-/* Gnulib usage. */
-/* This file uses _GL_ATTRIBUTE_PURE. */
+/* This file uses _GL_ATTRIBUTE_PURE, FLEXIBLE_ARRAY_MEMBER. */
# if !_GL_CONFIG_H_INCLUDED
#error "Please include config.h first."
# endif
#include <stdint.h> /* For uintptr_t. */
#include <string.h> /* For memcpy. */
-#if __STDC_VERSION__ < 199901L || defined __HP_cc
-# define __FLEXIBLE_ARRAY_MEMBER 1
-#else
-# define __FLEXIBLE_ARRAY_MEMBER
-#endif
-
/* These macros highlight the places where this implementation
is different from the one in GNU libc. */
#if defined __GL_GNULIB_HEADER
# define _OBSTACK_SIZE_T size_t
# define _CHUNK_SIZE_T size_t
# define _OBSTACK_CAST(type, expr) (expr)
+# define _OBSTACK_CHUNK_CONTENTS_SIZE FLEXIBLE_ARRAY_MEMBER
#else
/* glibc usage. */
# define _OBSTACK_SIZE_T unsigned int
# define _CHUNK_SIZE_T unsigned long
# define _OBSTACK_CAST(type, expr) ((type) (expr))
+# define _OBSTACK_CHUNK_CONTENTS_SIZE 4
#endif
/* __PTR_ALIGN(B, P, A) returns the result of aligning P to the next multiple
{
char *limit; /* 1 past end of this chunk */
struct _obstack_chunk *prev; /* address of prior chunk or NULL */
- char contents[__FLEXIBLE_ARRAY_MEMBER]; /* objects begin here */
+ char contents[_OBSTACK_CHUNK_CONTENTS_SIZE]; /* objects begin here */
};
struct obstack /* control current object in current chunk */
Depends-on:
gen-header
alignasof [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]
exitfail [test $HAVE_OBSTACK = 0 || test $REPLACE_OBSTACK = 1]