bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: string-desc: Distinguish writable strings from read-only strings


From: Collin Funk
Subject: Re: string-desc: Distinguish writable strings from read-only strings
Date: Fri, 09 May 2025 21:22:47 -0700
User-agent: Gnus/5.13 (Gnus v5.13)

Bruno Haible via Gnulib discussion list <bug-gnulib@gnu.org> writes:

> This patch fixes this problem, by distinguishing read-only strings and
> writable strings.
>
> Obviously, I did not want to duplicate the functions, e.g. sd_length
> to sd_length and rwsd_length. A single function should be applicable
> to both read-only strings and writable strings. Unfortunately the C type
> system is not helpful in this direction. But I could make it work by using
> a combination of
>   - statement-expressions,
>   - _Generic,
>   - typeof,
>   - and inline functions.
> Thus the implementation is more complex than before, but the programs that
> use 'string-desc' get better type safety with fewer casts.

Thanks, I think that clearly differentiating the two is good as well.

However, when doing the following commands in gettext:

    $ ./autopull.sh
    $ ./autogen.sh
    $ ./configure && make

I see the following error:

    $ gcc --version | sed 1q
    gcc (GCC) 15.1.1 20250425 (Red Hat 15.1.1-1)
    $ make
    [...]
    gcc -DHAVE_CONFIG_H -DEXEEXT=\"\" -I. -I..  -I../intl 
-DDEPENDS_ON_LIBICONV=1 -DDEPENDS_ON_LIBINTL=1   -Wno-cast-qual -Wno-conversion 
-Wno-float-equal -Wno-sign-compare -Wno-undef -Wno-unused-function 
-Wno-unused-parameter -Wno-float-conversion -Wimplicit-fallthrough 
-Wno-pedantic -Wno-sign-conversion -Wno-type-limits -Wno-unused-const-variable 
-Wno-unsuffixed-float-constants -Wno-error -g -O2 -MT libgrt_a-xsize.o -MD -MP 
-MF .deps/libgrt_a-xsize.Tpo -c -o libgrt_a-xsize.o `test -f 'xsize.c' || echo 
'./'`xsize.c
    In file included from string-desc-contains.c:20:
    ../config.h:1218:21: error: attributes should be specified before the 
declarator in a function definition
     1218 | # define _GL_INLINE inline
          |                     ^~~~~~
    string-desc.h:48:32: note: in expansion of macro '_GL_INLINE'
       48 | # define GL_STRING_DESC_INLINE _GL_INLINE
          |                                ^~~~~~~~~~
    string-desc.h:319:1: note: in expansion of macro 'GL_STRING_DESC_INLINE'
      319 | GL_STRING_DESC_INLINE char
          | ^~~~~~~~~~~~~~~~~~~~~
    In file included from string-buffer.c:19:
    ../config.h:1218:21: error: attributes should be specified before the 
declarator in a function definition
     1218 | # define _GL_INLINE inline
          |                     ^~~~~~
    string-desc.h:48:32: note: in expansion of macro '_GL_INLINE'
       48 | # define GL_STRING_DESC_INLINE _GL_INLINE
          |                                ^~~~~~~~~~
    string-desc.h:319:1: note: in expansion of macro 'GL_STRING_DESC_INLINE'
      319 | GL_STRING_DESC_INLINE char
          | ^~~~~~~~~~~~~~~~~~~~~

It seems that doing this in a declaration is okay:

    GL_STRING_DESC_INLINE char
    _sd_char_at (idx_t s_nbytes, const char *s_data, idx_t i)
        _GL_ATTRIBUTE_NONNULL_IF_NONZERO (2, 1);

But in the function definition it will not work:

    GL_STRING_DESC_INLINE char
    _sd_char_at (idx_t s_nbytes, const char *s_data, idx_t i)
        _GL_ATTRIBUTE_NONNULL_IF_NONZERO (2, 1)
    {
      [...]
    }

The attributes must be placed before the return type.

I have attached two patches that seem to fix the issue, but have not
pushed them in case I am misunderstanding the error.

gettext still fails to build afterwards, but it seems like changing to
rw_string_desc_t where applicable will fix it. So not a bug.

Collin

Attachment: 0001-string-desc-Fix-compile-error.patch
Description: Text Data

Attachment: 0002-xstring-desc-Fix-compile-error.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]