On a new Haiku/x86_64 system, a gnulib testdir shows these compilation errors:

../../gllib/mbrtoc32.c:86:1: error: redefinition of 'mbrtoc32'
 mbrtoc32 (char32_t *pwc, const char *s, size_t n, mbstate_t *ps)
 ^~~~~~~~
In file included from ./uchar.h:32,
                 from ../../gllib/mbrtoc32.c:22:
/boot/system/develop/headers/posix/uchar.h:37:1: note: previous definition of 
'mbrtoc32' was here
 mbrtoc32(char32_t *dest, const char *src, size_t srcLength, mbstate_t *mbState)
 ^~~~~~~~

../../gllib/c32rtomb.c:39:1: error: redefinition of 'c32rtomb'
 c32rtomb (char *s, char32_t wc, mbstate_t *ps)
 ^~~~~~~~
In file included from ./uchar.h:32,
                 from ../../gllib/c32rtomb.c:22:
/boot/system/develop/headers/posix/uchar.h:32:1: note: previous definition of 
'c32rtomb' was here
 c32rtomb(char *dest, char32_t wc, mbstate_t *mbState)
 ^~~~~~~~

The reason is that these functions are defined as static inline functions,
thus AC_CHECK_FUNCS reports that these function were not defined.

These two patches fix the problems.


2020-05-08  Bruno Haible  <br...@clisp.org>

        c32rtomb: Avoid compilation failure on Haiku.
        * m4/c32rtomb.m4 (gl_FUNC_C32RTOMB): Test for c32rtomb without excluding
        inline definitions.
        * doc/posix-functions/c32rtomb.texi: Mention the Haiku problem.

2020-05-08  Bruno Haible  <br...@clisp.org>

        mbrtoc32: Avoid compilation failure on Haiku.
        * m4/mbrtoc32.m4 (gl_CHECK_FUNC_MBRTOC32): New macro.
        (gl_FUNC_MBRTOC32, gl_MBRTOC32_SANITYCHECK): Use it instead of
        AC_CHECK_FUNCS_ONCE.
        * doc/posix-functions/mbrtoc32.texi: Mention the Haiku problem.

>From 6351ed01c42899191155e2b6dd74f077f1cff193 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Sat, 9 May 2020 02:52:48 +0200
Subject: [PATCH 1/2] mbrtoc32: Avoid compilation failure on Haiku.

* m4/mbrtoc32.m4 (gl_CHECK_FUNC_MBRTOC32): New macro.
(gl_FUNC_MBRTOC32, gl_MBRTOC32_SANITYCHECK): Use it instead of
AC_CHECK_FUNCS_ONCE.
* doc/posix-functions/mbrtoc32.texi: Mention the Haiku problem.
---
 ChangeLog                         |  8 ++++++++
 doc/posix-functions/mbrtoc32.texi |  3 +++
 m4/mbrtoc32.m4                    | 29 ++++++++++++++++++++++++-----
 3 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 0a9cca9..53a672a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2020-05-08  Bruno Haible  <br...@clisp.org>
 
+	mbrtoc32: Avoid compilation failure on Haiku.
+	* m4/mbrtoc32.m4 (gl_CHECK_FUNC_MBRTOC32): New macro.
+	(gl_FUNC_MBRTOC32, gl_MBRTOC32_SANITYCHECK): Use it instead of
+	AC_CHECK_FUNCS_ONCE.
+	* doc/posix-functions/mbrtoc32.texi: Mention the Haiku problem.
+
+2020-05-08  Bruno Haible  <br...@clisp.org>
+
 	limits-h: Define LONG_BIT correctly on Haiku/x86_64.
 	* lib/limits.in.h: Define and test _GL_ALREADY_INCLUDING_LIMITS_H.
 
diff --git a/doc/posix-functions/mbrtoc32.texi b/doc/posix-functions/mbrtoc32.texi
index 3151a09..647beb9 100644
--- a/doc/posix-functions/mbrtoc32.texi
+++ b/doc/posix-functions/mbrtoc32.texi
@@ -25,4 +25,7 @@ FreeBSD 12, Solaris 11.4, mingw, MSVC 14.
 
 Portability problems not fixed by Gnulib:
 @itemize
+@item
+This function is only defined as an inline function on some platforms:
+Haiku 2020.
 @end itemize
diff --git a/m4/mbrtoc32.m4 b/m4/mbrtoc32.m4
index a5dc51a..991bbc8 100644
--- a/m4/mbrtoc32.m4
+++ b/m4/mbrtoc32.m4
@@ -1,4 +1,4 @@
-# mbrtoc32.m4 serial 3
+# mbrtoc32.m4 serial 4
 dnl Copyright (C) 2014-2020 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -13,8 +13,8 @@ AC_DEFUN([gl_FUNC_MBRTOC32],
 
   AC_REQUIRE([gl_MBRTOC32_SANITYCHECK])
 
-  AC_CHECK_FUNCS_ONCE([mbrtoc32])
-  if test $ac_cv_func_mbrtoc32 = no; then
+  AC_REQUIRE([gl_CHECK_FUNC_MBRTOC32])
+  if test $gl_cv_func_mbrtoc32 = no; then
     HAVE_MBRTOC32=0
   else
     if test $REPLACE_MBSTATE_T = 1; then
@@ -43,6 +43,25 @@ AC_DEFUN([gl_FUNC_MBRTOC32],
   fi
 ])
 
+dnl We can't use AC_CHECK_FUNC here, because mbrtoc32() is defined as a
+dnl static inline function on Haiku 2020.
+AC_DEFUN([gl_CHECK_FUNC_MBRTOC32],
+[
+  AC_CACHE_CHECK([for mbrtoc32], [gl_cv_func_mbrtoc32],
+    [AC_LINK_IFELSE(
+       [AC_LANG_PROGRAM(
+          [[#include <stdlib.h>
+            #include <uchar.h>
+          ]],
+          [[char32_t c;
+            return mbrtoc32 (&c, "", 1, NULL) == 0;
+          ]])
+       ],
+       [gl_cv_func_mbrtoc32=yes],
+       [gl_cv_func_mbrtoc32=no])
+    ])
+])
+
 AC_DEFUN([gl_MBRTOC32_EMPTY_INPUT],
 [
   AC_REQUIRE([AC_PROG_CC])
@@ -122,11 +141,11 @@ dnl Result is HAVE_WORKING_MBRTOC32.
 AC_DEFUN([gl_MBRTOC32_SANITYCHECK],
 [
   AC_REQUIRE([AC_PROG_CC])
-  AC_CHECK_FUNCS_ONCE([mbrtoc32])
+  AC_REQUIRE([gl_CHECK_FUNC_MBRTOC32])
   AC_REQUIRE([gt_LOCALE_FR])
   AC_REQUIRE([gt_LOCALE_ZH_CN])
   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
-  if test $ac_cv_func_mbrtoc32 = no; then
+  if test $gl_cv_func_mbrtoc32 = no; then
     HAVE_WORKING_MBRTOC32=0
   else
     AC_CACHE_CHECK([whether mbrtoc32 works as well as mbrtowc],
-- 
2.7.4

>From c8eb1af611279eaebff505dbfe176885ca3b0fdc Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Sat, 9 May 2020 02:55:06 +0200
Subject: [PATCH 2/2] c32rtomb: Avoid compilation failure on Haiku.

* m4/c32rtomb.m4 (gl_FUNC_C32RTOMB): Test for c32rtomb without excluding
inline definitions.
* doc/posix-functions/c32rtomb.texi: Mention the Haiku problem.
---
 ChangeLog                         |  7 +++++++
 doc/posix-functions/c32rtomb.texi |  3 +++
 m4/c32rtomb.m4                    | 20 +++++++++++++++++---
 3 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 53a672a..c22d515 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2020-05-08  Bruno Haible  <br...@clisp.org>
 
+	c32rtomb: Avoid compilation failure on Haiku.
+	* m4/c32rtomb.m4 (gl_FUNC_C32RTOMB): Test for c32rtomb without excluding
+	inline definitions.
+	* doc/posix-functions/c32rtomb.texi: Mention the Haiku problem.
+
+2020-05-08  Bruno Haible  <br...@clisp.org>
+
 	mbrtoc32: Avoid compilation failure on Haiku.
 	* m4/mbrtoc32.m4 (gl_CHECK_FUNC_MBRTOC32): New macro.
 	(gl_FUNC_MBRTOC32, gl_MBRTOC32_SANITYCHECK): Use it instead of
diff --git a/doc/posix-functions/c32rtomb.texi b/doc/posix-functions/c32rtomb.texi
index 4a1a617..fd4ada6 100644
--- a/doc/posix-functions/c32rtomb.texi
+++ b/doc/posix-functions/c32rtomb.texi
@@ -16,4 +16,7 @@ AIX 7.2.
 
 Portability problems not fixed by Gnulib:
 @itemize
+@item
+This function is only defined as an inline function on some platforms:
+Haiku 2020.
 @end itemize
diff --git a/m4/c32rtomb.m4 b/m4/c32rtomb.m4
index 4cf0e4d..f55ce31 100644
--- a/m4/c32rtomb.m4
+++ b/m4/c32rtomb.m4
@@ -1,4 +1,4 @@
-# c32rtomb.m4 serial 1
+# c32rtomb.m4 serial 2
 dnl Copyright (C) 2020 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -10,8 +10,22 @@ AC_DEFUN([gl_FUNC_C32RTOMB],
 
   AC_REQUIRE([gl_MBRTOC32_SANITYCHECK])
 
-  AC_CHECK_FUNCS_ONCE([c32rtomb])
-  if test $ac_cv_func_c32rtomb = no; then
+  dnl We can't use AC_CHECK_FUNC here, because c32rtomb() is defined as a
+  dnl static inline function on Haiku 2020.
+  AC_CACHE_CHECK([for c32rtomb], [gl_cv_func_c32rtomb],
+    [AC_LINK_IFELSE(
+       [AC_LANG_PROGRAM(
+          [[#include <stdlib.h>
+            #include <uchar.h>
+          ]],
+          [[char buf[8];
+            return c32rtomb (buf, 0, NULL) == 0;
+          ]])
+       ],
+       [gl_cv_func_c32rtomb=yes],
+       [gl_cv_func_c32rtomb=no])
+    ])
+  if test $gl_cv_func_c32rtomb = no; then
     HAVE_C32RTOMB=0
   else
     dnl When we override mbrtoc32, redefining the meaning of the char32_t
-- 
2.7.4

Reply via email to