From 7738ad6840d85506f49b42cd1597d854f433c01f Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Wed, 30 Apr 2025 11:57:34 +0200 Subject: [PATCH] obstack: Make it easier to sync back with glibc. * lib/obstack.in.h: Use __GL_GNULIB_HEADER to delimit sections that are for Gnulib usage. Test __GL_SMALL_PTRDIFF_T__ instead of @SMALL_PTRDIFF_T@. Test __GL_REPLACE_OBSTACK__ instead of @REPLACE_OBSTACK@. * modules/obstack (Makefile.am): Substitute __GL_GNULIB_HEADER. Substitute __GL_SMALL_PTRDIFF_T__ instead of @SMALL_PTRDIFF_T@. Substitute __GL_REPLACE_OBSTACK__ instead of @REPLACE_OBSTACK@. --- ChangeLog | 11 +++++++++++ lib/obstack.in.h | 24 ++++++++++++++---------- modules/obstack | 5 +++-- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2d0f93e33d..fc772d1f95 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2025-04-30 Bruno Haible + + obstack: Make it easier to sync back with glibc. + * lib/obstack.in.h: Use __GL_GNULIB_HEADER to delimit sections that are + for Gnulib usage. + Test __GL_SMALL_PTRDIFF_T__ instead of @SMALL_PTRDIFF_T@. + Test __GL_REPLACE_OBSTACK__ instead of @REPLACE_OBSTACK@. + * modules/obstack (Makefile.am): Substitute __GL_GNULIB_HEADER. + Substitute __GL_SMALL_PTRDIFF_T__ instead of @SMALL_PTRDIFF_T@. + Substitute __GL_REPLACE_OBSTACK__ instead of @REPLACE_OBSTACK@. + 2025-04-29 Bruno Haible hash: Rename an internal function. diff --git a/lib/obstack.in.h b/lib/obstack.in.h index b5791ee294..39eb3a030f 100644 --- a/lib/obstack.in.h +++ b/lib/obstack.in.h @@ -105,9 +105,12 @@ #ifndef _OBSTACK_H #define _OBSTACK_H 1 -/* This file uses _Noreturn, _GL_ATTRIBUTE_PURE. */ -#if !_GL_CONFIG_H_INCLUDED - #error "Please include config.h first." +#if defined __GL_GNULIB_HEADER +/* Gnulib usage. */ +/* This file uses _GL_ATTRIBUTE_PURE. */ +# if !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +# endif #endif #include /* For size_t and ptrdiff_t. */ @@ -122,15 +125,16 @@ /* These macros highlight the places where this implementation is different from the one in GNU libc. */ -#ifdef _LIBC -# define _OBSTACK_SIZE_T unsigned int -# define _CHUNK_SIZE_T unsigned long -# define _OBSTACK_CAST(type, expr) ((type) (expr)) -#else +#if defined __GL_GNULIB_HEADER /* In Gnulib, we use sane types, especially for 64-bit hosts. */ # define _OBSTACK_SIZE_T size_t # define _CHUNK_SIZE_T size_t # define _OBSTACK_CAST(type, expr) (expr) +#else +/* glibc usage. */ +# define _OBSTACK_SIZE_T unsigned int +# define _CHUNK_SIZE_T unsigned long +# define _OBSTACK_CAST(type, expr) ((type) (expr)) #endif /* __PTR_ALIGN(B, P, A) returns the result of aligning P to the next multiple @@ -139,7 +143,7 @@ If ptrdiff_t is narrower than a pointer (e.g., the AS/400), play it safe and compute the alignment relative to B. Otherwise, use the faster strategy of computing the alignment through uintptr_t. */ -#if @SMALL_PTRDIFF_T@ +#if defined __GL_SMALL_PTRDIFF_T__ # define __PTR_ALIGN(B, P, A) \ ((B) + (((P) - (B) + (A)) & ~(A))) #else @@ -210,7 +214,7 @@ struct obstack /* control current object in current chunk */ /* Declare the external functions we use; they are in obstack.c. */ -#if @REPLACE_OBSTACK@ +#if defined __GL_REPLACE_OBSTACK__ # define _obstack_newchunk rpl_obstack_newchunk # define _obstack_free rpl_obstack_free # define _obstack_begin rpl_obstack_begin diff --git a/modules/obstack b/modules/obstack index 77b81f9e44..5065a693cc 100644 --- a/modules/obstack +++ b/modules/obstack @@ -31,8 +31,9 @@ if GL_GENERATE_OBSTACK_H obstack.h: obstack.in.h $(top_builddir)/config.status @NMD@ $(AM_V_GEN)$(MKDIR_P) '%reldir%' $(gl_V_at)$(SED_HEADER_STDOUT) \ - -e 's|@''REPLACE_OBSTACK''@|$(REPLACE_OBSTACK)|g' \ - -e 's|@''SMALL_PTRDIFF_T''@|$(SMALL_PTRDIFF_T)|g' \ + -e 's/defined __GL_GNULIB_HEADER/1/g' \ + -e 's|defined __GL_REPLACE_OBSTACK__|$(REPLACE_OBSTACK)|g' \ + -e 's|defined __GL_SMALL_PTRDIFF_T__|$(SMALL_PTRDIFF_T)|g' \ $(srcdir)/obstack.in.h > $@-t $(AM_V_at)mv $@-t $@ else -- 2.39.5