]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
obstack: merge better with glibc
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 5 May 2025 21:02:12 +0000 (14:02 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 5 May 2025 21:16:19 +0000 (14:16 -0700)
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
lib/obstack.in.h
modules/obstack

index cdef5a8973c490fc3af62e12dc8967c50f33e761..5c78f4dac4b854f1f2a22db158a5758b9754377b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 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.
index 1d6ff923b48317c8ae6bdad3f40e1b8b46faa5ea..2013ecd317172a355393ba454d3b1e7fec51bd33 100644 (file)
 #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
@@ -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 */
index 6b9ab181342a5aaf54e8f902f2059ed0fe5c4658..4f62f64bba77e2280f44e85c0165b409b749cad7 100644 (file)
@@ -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]