[PATCH v2 10/28] argp: Expand argp_usage, _option_is_short, and _option_is_end
Collin Funk
collin.funk1@gmail.com
Wed Oct 29 03:06:35 GMT 2025
Adhemerval Zanella <adhemerval.zanella@linaro.org> writes:
> The argp code uses macro redefinitions to avoid duplicating static inline
> implementations for argp_usage, _option_is_short, and _option_is_end.
> However, this causes build issues with clang, as some function prototypes
> are redefined to add the hidden attribute with libc_hidden_proto.
>
> To avoid extensive changes to internal headers, just expand the function
> implementations and avoid the macro redefine tricks.
> ---
> argp/argp-xinl.c | 32 ++++++++++++++++++++++++--------
> argp/argp.h | 10 +++-------
> 2 files changed, 27 insertions(+), 15 deletions(-)
>
> diff --git a/argp/argp-xinl.c b/argp/argp-xinl.c
> index 37410c0eeb..49088bb851 100644
> --- a/argp/argp-xinl.c
> +++ b/argp/argp-xinl.c
> @@ -25,19 +25,35 @@
> # include <features.h>
> #endif
>
> -#ifndef __USE_EXTERN_INLINES
> -# define __USE_EXTERN_INLINES 1
> -#endif
> -#define ARGP_EI
> -#undef __OPTIMIZE__
> -#define __OPTIMIZE__ 1
> #include <argp.h>
>
> -/* Add weak aliases. */
> -#if _LIBC - 0 && defined (weak_alias)
> +#ifdef _LIBC
>
> +void
> +__argp_usage (const struct argp_state *__state)
> +{
> + __argp_state_help (__state, stderr, ARGP_HELP_STD_USAGE);
> +}
> weak_alias (__argp_usage, argp_usage)
> +
> +int
> +__option_is_short (const struct argp_option *__opt)
> +{
> + if (__opt->flags & OPTION_DOC)
> + return 0;
> + else
> + {
> + int __key = __opt->key;
> + return __key > 0 && __key <= UCHAR_MAX && isprint (__key);
> + }
> +}
> weak_alias (__option_is_short, _option_is_short)
> +
> +int
> +__option_is_end (const struct argp_option *__opt)
> +{
> + return !__opt->key && !__opt->name && !__opt->doc && !__opt->group;
> +}
> weak_alias (__option_is_end, _option_is_end)
>
> #endif
> diff --git a/argp/argp.h b/argp/argp.h
> index 4967c876a2..27391402fd 100644
> --- a/argp/argp.h
> +++ b/argp/argp.h
> @@ -518,17 +518,13 @@ extern void *__argp_input (const struct argp *__restrict __argp,
> # define __option_is_end _option_is_end
> # endif
>
> -# ifndef ARGP_EI
> -# define ARGP_EI __extern_inline
> -# endif
> -
> -ARGP_EI void
> +__extern_inline void
> __argp_usage (const struct argp_state *__state)
> {
> __argp_state_help (__state, stderr, ARGP_HELP_STD_USAGE);
> }
>
> -ARGP_EI int
> +__extern_inline int
> __NTH (__option_is_short (const struct argp_option *__opt))
> {
> if (__opt->flags & OPTION_DOC)
> @@ -540,7 +536,7 @@ __NTH (__option_is_short (const struct argp_option *__opt))
> }
> }
>
> -ARGP_EI int
> +__extern_inline int
> __NTH (__option_is_end (const struct argp_option *__opt))
> {
> return !__opt->key && !__opt->name && !__opt->doc && !__opt->group;
Thanks, as far as this patch goes it is pretty easy to sync to
Gnulib. We do extern inline like this.
In, for example, stdbit.in.h which is used to generate stdbit.h:
_GL_INLINE_HEADER_BEGIN
#ifndef _GL_STDBIT_INLINE
# define _GL_STDBIT_INLINE _GL_INLINE
#endif
/* Inline functions and other definitions. */
_GL_INLINE_HEADER_END
Then in stdbit.c:
#define _GL_STDBIT_INLINE _GL_EXTERN_INLINE
#include <config.h>
#include <stdbit.h>
Therefore, hiding the functions in argp-xinl.c behind _LIBC works
perfect.
Reviewed-by: Collin Funk <collin.funk1@gmail.com>
Collin
More information about the Libc-alpha
mailing list