getrandom: Fix compilation error in C++ mode on FreeBSD 12
On FreeBSD 12, in C++ mode, the getrandom() function is declared with C++ linkage. This leads to a compilation error in test-sys_random-c++: In file included from ../../gltests/test-sys_random-c++.cc:22: ../gllib/sys/random.h:594:19: error: declaration of 'getrandom' has a different language linkage _GL_CXXALIASWARN (getrandom); ^ /usr/include/sys/random.h:160:9: note: previous declaration is here ssize_t getrandom(void *buf, size_t buflen, unsigned int flags); ^ This patch fixes it. 2022-09-02 Bruno Haible getrandom: Fix compilation error in C++ mode on FreeBSD 12. * lib/sys_random.in.h (getrandom): Enable the C++ alias warning only on glibc ≥ 2.25 systems. diff --git a/lib/sys_random.in.h b/lib/sys_random.in.h index e730e6139f..c91bcd2cd0 100644 --- a/lib/sys_random.in.h +++ b/lib/sys_random.in.h @@ -84,7 +84,9 @@ _GL_FUNCDECL_SYS (getrandom, ssize_t, _GL_CXXALIAS_SYS (getrandom, ssize_t, (void *buffer, size_t length, unsigned int flags)); # endif +# if __GLIBC__ + (__GLIBC_MINOR__ >= 25) > 2 _GL_CXXALIASWARN (getrandom); +# endif #elif defined GNULIB_POSIXCHECK # undef getrandom # if HAVE_RAW_DECL_GETRANDOM
math C++ tests: Fix compilation error with clang on FreeBSD 13
On FreeBSD 13.0, I get this compilation error: In file included from ../../gltests/test-math-c++2.cc:20: /usr/include/c++/v1/cmath:325:7: error: no member named 'rpl_isnan' in the global namespace; did you mean 'gnulib::rpl_isnan'? using ::isnan; ^~ ../gllib/math.h:3104:43: note: 'gnulib::rpl_isnan' declared here _GL_MATH_CXX_REAL_FLOATING_DECL_2 (isnan, rpl_isnan, bool) ^ 1 error generated. *** Error code 1 The fix is to revert the change from 2020-12-09, that was done for FreeBSD 12.2, for versions of FreeBSD ≥ 13. 2022-09-02 Bruno Haible math C++ tests: Fix compilation error with clang on FreeBSD 13. * lib/math.in.h (isnan): For clang >= 11 on FreeBSD, declare 'isnan', not 'rpl_isnan'. diff --git a/lib/math.in.h b/lib/math.in.h index a74a95da3e..270e71f414 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -2591,7 +2591,7 @@ _GL_EXTERN_C int rpl_isnanl (long double x) _GL_ATTRIBUTE_CONST; # if defined isnan || defined GNULIB_NAMESPACE _GL_MATH_CXX_REAL_FLOATING_DECL_1 (isnan) # undef isnan -# if __GNUC__ >= 6 || (defined __clang__ && !((defined __APPLE__ && defined __MACH__ && __clang_major__ < 12) || (defined __FreeBSD__ && __clang_major__ < 7) || defined __OpenBSD__ || (defined _WIN32 && !defined __CYGWIN__))) +# if __GNUC__ >= 6 || (defined __clang__ && !((defined __APPLE__ && defined __MACH__ && __clang_major__ < 12) || (defined __FreeBSD__ && (__clang_major__ < 7 || __clang_major__ >= 11)) || defined __OpenBSD__ || (defined _WIN32 && !defined __CYGWIN__))) /* This platform's possibly defines isnan through a set of inline functions. */ _GL_MATH_CXX_REAL_FLOATING_DECL_2 (isnan, rpl_isnan, bool)
strerror_r-posix: Fix for Hurd
On Hurd, I'm seeing this test failure: test-strerror_r.c:112: assertion 'ret == ERANGE || ret == EINVAL' failed FAIL test-strerror_r (exit status: 134) This patch fixes it. 2022-09-02 Bruno Haible strerror_r-posix: Fix for Hurd. * lib/strerror_r.c (strerror_r): Interpret return value of __xpg_strerror_r correctly. Remove assumption about how strerror_r behaves. diff --git a/lib/strerror_r.c b/lib/strerror_r.c index 85a218935c..b154c292b4 100644 --- a/lib/strerror_r.c +++ b/lib/strerror_r.c @@ -166,16 +166,19 @@ strerror_r (int errnum, char *buf, size_t buflen) # if HAVE___XPG_STRERROR_R ret = __xpg_strerror_r (errnum, buf, buflen); - if (ret < 0) -ret = errno; + /* ret is 0 upon success, or EINVAL or ERANGE upon failure. */ # endif if (!*buf) { - /* glibc 2.13 would not touch buf on err, so we have to fall - back to GNU strerror_r which always returns a thread-safe - untruncated string to (partially) copy into our buf. */ - char *errstring = strerror_r (errnum, buf, buflen); + /* glibc 2.13 ... 2.34 (at least) don't touch buf upon failure. + Therefore we have to fall back to strerror_r which, for valid + errnum, returns a thread-safe untruncated string. For invalid + errnum, though, it returns a truncated string, which does not + allow us to determine whether to return ERANGE or 0. Thus we + need to pass a sufficiently large buffer. */ + char stackbuf[80]; + char *errstring = strerror_r (errnum, stackbuf, sizeof stackbuf); ret = errstring ? safe_copy (buf, buflen, errstring) : errno; } }
Re: strtol, strtoul: Fix compilation error in C++ mode on Solaris 11
Paul Eggert wrote: > > +# if __GLIBC__ >= 2 > > _GL_CXXALIASWARN (strtol); > > +# endif > > Would it make sense to move the __GLIBC__ >= 2 check into > _GL_CXXALIASWARN so that we needn't worry about making these sorts of > patches? How much benefit to non-glibc ports do we obtain from requiring > each _GL_CXXALIASWARN caller to decide whether to worry about __GLIBC__? It would save us a a few patches occasionally. But it's only a minority of the C++ related compilation failures. Looking in the ChangeLog, C++ compilation failures have different causes: - _GL_CXXALIASWARN with undefined functions, - _GL_CXXALIASWARN with differences in 'restrict', - _GL_CXXALIASWARN with slightly different function signature, - exception specifications, - overloaded functions (w.r.t. 'const'), - linkage. Not all developers develop on glibc systems. Just read a comment by a user today [1]: "My phone runs Linux. My GF's phone runs Linux. My TV runs Linux, too. So does the TV box-set (cable provider), And I say this as a desktop OpenBSD user." So, unless it's really too much effort to keep most of these _GL_CXXALIASWARN invocations enabled almost everywhere, I'd like to keep them. Bruno [1] https://news.ycombinator.com/item?id=26451540
ptsname tests, ptsname_r tests: Fix test failures on Hurd
On Debian GNU/Hurd, the test-ptsname and test-ptsname_r programs no longer terminate the current tty session. They merely fail now. And it's easy to fix the failures. 2022-09-02 Bruno Haible ptsname tests, ptsname_r tests: Fix test failures on Hurd. * tests/test-ptsname.c (main): On Hurd, test only the BSD ptys that actually exist on Hurd. * tests/test-ptsname_r.c (main): Likewise. diff --git a/tests/test-ptsname.c b/tests/test-ptsname.c index 33d561b877..b300a03a26 100644 --- a/tests/test-ptsname.c +++ b/tests/test-ptsname.c @@ -155,6 +155,36 @@ main (void) close (fd); } +#elif defined __GNU__ /* Hurd */ + + /* Try various master names of Hurd: /dev/pty[p-q][0-9a-v] */ + { +int char1; +int char2; + +for (char1 = 'p'; char1 <= 'q'; char1++) + for (char2 = '0'; char2 <= 'v'; (char2 == '9' ? char2 = 'a' : char2++)) +{ + char master_name[32]; + int fd; + + sprintf (master_name, "/dev/pty%c%c", char1, char2); + fd = open (master_name, O_RDONLY); + if (fd >= 0) +{ + char *result; + char slave_name[32]; + + result = ptsname (fd); + ASSERT (result != NULL); + sprintf (slave_name, "/dev/tty%c%c", char1, char2); + ASSERT (same_slave (result, slave_name)); + + close (fd); +} +} + } + #else /* Try various master names of Mac OS X: /dev/pty[p-w][0-9a-f] */ diff --git a/tests/test-ptsname_r.c b/tests/test-ptsname_r.c index 4d299234f9..4987d17680 100644 --- a/tests/test-ptsname_r.c +++ b/tests/test-ptsname_r.c @@ -210,6 +210,39 @@ main (void) close (fd); } +#elif defined __GNU__ /* Hurd */ + + /* Try various master names of Hurd: /dev/pty[p-q][0-9a-v] */ + { +int char1; +int char2; + +for (char1 = 'p'; char1 <= 'q'; char1++) + for (char2 = '0'; char2 <= 'v'; (char2 == '9' ? char2 = 'a' : char2++)) +{ + char master_name[32]; + int fd; + + sprintf (master_name, "/dev/pty%c%c", char1, char2); + fd = open (master_name, O_RDONLY); + if (fd >= 0) +{ + char buffer[256]; + int result; + char slave_name[32]; + + result = ptsname_r (fd, buffer, sizeof buffer); + ASSERT (result == 0); + sprintf (slave_name, "/dev/tty%c%c", char1, char2); + ASSERT (same_slave (buffer, slave_name)); + + test_errors (fd, buffer); + + close (fd); +} +} + } + #else /* Try various master names of Mac OS X: /dev/pty[p-w][0-9a-f] */
Re: strtol, strtoul: Fix compilation error in C++ mode on Solaris 11
On 9/2/22 13:37, Bruno Haible wrote: +# if __GLIBC__ >= 2 _GL_CXXALIASWARN (strtol); +# endif Would it make sense to move the __GLIBC__ >= 2 check into _GL_CXXALIASWARN so that we needn't worry about making these sorts of patches? How much benefit to non-glibc ports do we obtain from requiring each _GL_CXXALIASWARN caller to decide whether to worry about __GLIBC__?
strtol, strtoul: Fix compilation error in C++ mode on Solaris 11
A gnulib testdir also produces these compilation errors on Solaris 11 OmniOS: ../gllib/stdlib.h:1918:1: error: 'long int strtol(const char*, char**, int)' conflicts with a previous declaration 1918 | _GL_CXXALIASWARN (strtol); | ^~~~ In file included from /usr/include/stdlib.h:40, from /opt/gcc-9/include/c++/9.3.0/cstdlib:75, from /opt/gcc-9/include/c++/9.3.0/stdlib.h:36, from ../gllib/stdlib.h:36, from ../gllib/malloc.h:35, from ../../gltests/test-malloc-h-c++.cc:22: /usr/include/iso/stdlib_iso.h:157:17: note: previous declaration 'long int std::strtol(const char*, char**, int)' 157 | extern long int strtol(const char *_RESTRICT_KYWD, char **_RESTRICT_KYWD, int); | ^~ In file included from /usr/include/sys/time.h:489, from ../gllib/sys/time.h:39, from /usr/include/sys/select.h:53, from ../gllib/sys/select.h:36, from /usr/include/sys/types.h:640, from ../gllib/sys/types.h:39, from /usr/include/malloc.h:31, from ../gllib/malloc.h:27, from ../../gltests/test-malloc-h-c++.cc:22: ../gllib/stdlib.h:1999:1: error: 'long unsigned int strtoul(const char*, char**, int)' conflicts with a previous declaration 1999 | _GL_CXXALIASWARN (strtoul); | ^~~~ In file included from /usr/include/stdlib.h:40, from /opt/gcc-9/include/c++/9.3.0/cstdlib:75, from /opt/gcc-9/include/c++/9.3.0/stdlib.h:36, from ../gllib/stdlib.h:36, from ../gllib/malloc.h:35, from ../../gltests/test-malloc-h-c++.cc:22: /usr/include/iso/stdlib_iso.h:158:26: note: previous declaration 'long unsigned int std::strtoul(const char*, char**, int)' 158 | extern unsigned long int strtoul(const char *_RESTRICT_KYWD, | ^~~ gmake[4]: *** [Makefile:23194: test-malloc-h-c++.o] Error 1 It looks like 'restrict' in the declaration makes a difference in C++. This patch fixes it. 2022-09-02 Bruno Haible strtol, strtoul: Fix compilation error in C++ mode on Solaris 11. * lib/stdlib.in.h (strtol, strtoul): Enable the C++ alias warning only on glibc systems. diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h index 010875803c..8e0a609f1f 100644 --- a/lib/stdlib.in.h +++ b/lib/stdlib.in.h @@ -1363,7 +1363,9 @@ _GL_CXXALIAS_SYS (strtol, long, (const char *restrict string, char **restrict endptr, int base)); # endif +# if __GLIBC__ >= 2 _GL_CXXALIASWARN (strtol); +# endif #elif defined GNULIB_POSIXCHECK # undef strtol # if HAVE_RAW_DECL_STRTOL @@ -1444,7 +1446,9 @@ _GL_CXXALIAS_SYS (strtoul, unsigned long, (const char *restrict string, char **restrict endptr, int base)); # endif +# if __GLIBC__ >= 2 _GL_CXXALIASWARN (strtoul); +# endif #elif defined GNULIB_POSIXCHECK # undef strtoul # if HAVE_RAW_DECL_STRTOUL
aligned_alloc: Fix compilation error in C++ mode on Solaris 11
A gnulib testdir produces a compilation error on Solaris 11 OmniOS: In file included from /usr/include/sys/time.h:489, from ../gllib/sys/time.h:39, from /usr/include/sys/select.h:53, from ../gllib/sys/select.h:36, from /usr/include/sys/types.h:640, from ../gllib/sys/types.h:39, from /usr/include/malloc.h:31, from ../gllib/malloc.h:27, from ../../gltests/test-malloc-h-c++.cc:22: ../gllib/stdlib.h:782:1: error: 'aligned_alloc' was not declared in this scope 782 | _GL_CXXALIASWARN (aligned_alloc); | ^~~~ ../gllib/stdlib.h:782:1: note: suggested alternatives: In file included from /usr/include/stdlib.h:42, from /opt/gcc-9/include/c++/9.3.0/cstdlib:75, from /opt/gcc-9/include/c++/9.3.0/stdlib.h:36, from ../gllib/stdlib.h:36, from ../gllib/malloc.h:35, from ../../gltests/test-malloc-h-c++.cc:22: /usr/include/iso/stdlib_c11.h:60:14: note: 'std::aligned_alloc' 60 | extern void *aligned_alloc(size_t, size_t); | ^ In file included from /usr/include/sys/time.h:489, from ../gllib/sys/time.h:39, from /usr/include/sys/select.h:53, from ../gllib/sys/select.h:36, from /usr/include/sys/types.h:640, from ../gllib/sys/types.h:39, from /usr/include/malloc.h:31, from ../gllib/malloc.h:27, from ../../gltests/test-malloc-h-c++.cc:22: ../gllib/stdlib.h:769:1: note: 'gnulib::aligned_alloc' 769 | _GL_CXXALIAS_RPL (aligned_alloc, void *, (size_t alignment, size_t size)); | ^~~~ The reason is that aligned_alloc is not declared in C++ mode, only in ISO C11 mode. This patch fixes the error: 2022-09-02 Bruno Haible aligned_alloc: Fix compilation error in C++ mode on Solaris 11. * lib/stdlib.in.h (aligned_alloc): Enable the C++ alias warning only on glibc systems. diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h index a86643c3ca..010875803c 100644 --- a/lib/stdlib.in.h +++ b/lib/stdlib.in.h @@ -226,7 +226,7 @@ _GL_FUNCDECL_SYS (aligned_alloc, void *, _GL_CXXALIAS_SYS (aligned_alloc, void *, (size_t alignment, size_t size)); # endif # endif -# if @HAVE_ALIGNED_ALLOC@ +# if (__GLIBC__ >= 2) && @HAVE_ALIGNED_ALLOC@ _GL_CXXALIASWARN (aligned_alloc); # endif #else
getdomainname: Fix compilation error in C++ mode on Solaris 11
A gnulib testdir produces a compilation error on Solaris 11 OmniOS and Solaris 11 OpenIndiana: In file included from /usr/include/sys/time.h:489, from ../gllib/sys/time.h:39, from /usr/include/sys/select.h:53, from ../gllib/sys/select.h:36, from /usr/include/sys/types.h:640, from ../gllib/sys/types.h:39, from ../gllib/fcntl.h:56, from ../../gltests/test-fcntl-h-c++.cc:22: ../gllib/unistd.h:1653:1: error: 'getdomainname' was not declared in this scope; did you mean 'gnulib::getdomainname'? 1653 | _GL_CXXALIASWARN (getdomainname); | ^~~~ ../gllib/unistd.h:1645:1: note: 'gnulib::getdomainname' declared here 1645 | _GL_CXXALIAS_RPL (getdomainname, int, (char *name, size_t len)); | ^~~~ gmake[4]: *** [Makefile:23125: test-fcntl-h-c++.o] Error 1 The reason is that on these platforms (and also on AIX, Android, and native Windows) this function is not declared, therefore one cannot attach a warning to it. This patch fixes it. 2022-09-02 Bruno Haible getdomainname: Fix compilation error in C++ mode on Solaris 11. * lib/unistd.in.h (getdomainname): Enable the C++ alias warning only on glibc systems. diff --git a/lib/unistd.in.h b/lib/unistd.in.h index 57df09ecdf..ef3e68fcd2 100644 --- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -1143,7 +1143,9 @@ _GL_FUNCDECL_SYS (getdomainname, int, (char *name, size_t len) # endif _GL_CXXALIAS_SYS (getdomainname, int, (char *name, size_t len)); # endif +# if __GLIBC__ >= 2 _GL_CXXALIASWARN (getdomainname); +# endif #elif defined GNULIB_POSIXCHECK # undef getdomainname # if HAVE_RAW_DECL_GETDOMAINNAME
terminfo: Don't disturb the termcap module
A testdir that contains both the 'termcap' and 'terminfo' modules fails to build on systems that don't have libncurses nor libtermcap: gcc-10 -Wno-error -g -O2 -L/home/bruno/inst-x86_64-64/lib -o test-termcap test-termcap.o libtests.a ../gllib/libgnu.a libtests.a ../gllib/libgnu.a libtests.a -ltermcap /usr/bin/ld: cannot find -ltermcap collect2: error: ld returned 1 exit status make[5]: *** [Makefile:1373: test-termcap] Error 1 The cause is that while running configure, gl_TERMCAP_BODY sets LIBTERMCAP to empty, and then later gl_TERMINFO_BODY sets LIBTERMCAP='-ltermcap'. gl_TERMINFO_BODY needs LIBTERMCAP only for internal purposes, whereas for gl_TERMCAP_BODY it is one of the documented output variables. This patch fixes it. 2022-09-02 Bruno Haible terminfo: Don't disturb the termcap module. * m4/terminfo.m4 (gl_TERMINFO_BODY): Save and restore the variables determined by the gl_TERMCAP_BODY macro. diff --git a/m4/terminfo.m4 b/m4/terminfo.m4 index e923518540..7daa4d5513 100644 --- a/m4/terminfo.m4 +++ b/m4/terminfo.m4 @@ -1,4 +1,4 @@ -# terminfo.m4 serial 4 +# terminfo.m4 serial 5 dnl Copyright (C) 2000-2022 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -45,6 +45,11 @@ AC_DEFUN([gl_TERMINFO_BODY], AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) AC_REQUIRE([AC_LIB_RPATH]) + dnl Avoid disturbing the gl_TERMCAP_BODY macro. + gl_save_LIBTERMCAP="$LIBTERMCAP" + gl_save_LTLIBTERMCAP="$LTLIBTERMCAP" + gl_save_INCTERMCAP="$INCTERMCAP" + if test "$gl_curses_allowed" != no; then dnl Search for libncurses and define LIBNCURSES, LTLIBNCURSES and INCNCURSES @@ -398,4 +403,9 @@ AC_DEFUN([gl_TERMINFO_BODY], LIBS="$gl_save_LIBS" ]) fi + + dnl Avoid disturbing the gl_TERMCAP_BODY macro. + LIBTERMCAP="$gl_save_LIBTERMCAP" + LTLIBTERMCAP="$gl_save_LTLIBTERMCAP" + INCTERMCAP="$gl_save_INCTERMCAP" ])