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.
---
 ChangeLog        |  8 ++++++++
 lib/obstack.in.h | 13 ++++---------
 modules/obstack  |  1 +
 3 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index cdef5a8973..5c78f4dac4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2025-05-05  Paul Eggert  <egg...@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.
diff --git a/lib/obstack.in.h b/lib/obstack.in.h
index 1d6ff923b4..2013ecd317 100644
--- a/lib/obstack.in.h
+++ b/lib/obstack.in.h
@@ -106,8 +106,7 @@
 #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
@@ -117,12 +116,6 @@
 #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
@@ -130,11 +123,13 @@
 # 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
@@ -172,7 +167,7 @@ struct _obstack_chunk           /* Lives at front of each 
chunk. */
 {
   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 */
diff --git a/modules/obstack b/modules/obstack
index 6b9ab18134..4f62f64bba 100644
--- a/modules/obstack
+++ b/modules/obstack
@@ -9,6 +9,7 @@ m4/obstack.m4
 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]
-- 
2.49.0


Reply via email to