Discussion:
imaxdiv: Fix compilation error on Android
Bruno Haible
2018-05-13 21:24:12 UTC
Permalink
When compiling to Android 4.3, the Android headers define the imaxdiv_t type
but the 'imaxdiv' function is not available. Gnulib so far assumed that this
situation does not occur, leading to compilation errors such as

In file included from test-imaxabs.c:19:0:
../gllib/inttypes.h:1524:49: error: conflicting types for 'imaxdiv_t'
typedef struct { intmax_t quot; intmax_t rem; } imaxdiv_t;
^

This patch fixes it.


2018-05-13 Bruno Haible <***@clisp.org>

imaxdiv: Fix compilation error on Android.
* m4/imaxdiv.m4 (gl_FUNC_IMAXDIV): Set HAVE_IMAXDIV_T to 0 if imaxdiv_t
is not defined.
* lib/inttypes.in.h (imaxdiv_t): Define if HAVE_IMAXDIV_T, not
HAVE_DECL_IMAXDIV, is 0.
* m4/inttypes.m4 (gl_INTTYPES_H_DEFAULTS): Initialize HAVE_IMAXDIV_T.
* modules/inttypes-incomplete (Makefile.am): Substitute HAVE_IMAXDIV_T.

diff --git a/lib/inttypes.in.h b/lib/inttypes.in.h
index 1e303cb..c7d7968 100644
--- a/lib/inttypes.in.h
+++ b/lib/inttypes.in.h
@@ -1067,11 +1067,13 @@ _GL_WARN_ON_USE (imaxabs, "imaxabs is unportable - "
#endif

#if @GNULIB_IMAXDIV@
-# if !@HAVE_DECL_IMAXDIV@
+# if !@HAVE_IMAXDIV_T@
# if !GNULIB_defined_imaxdiv_t
typedef struct { intmax_t quot; intmax_t rem; } imaxdiv_t;
# define GNULIB_defined_imaxdiv_t 1
# endif
+# endif
+# if !@HAVE_DECL_IMAXDIV@
extern imaxdiv_t imaxdiv (intmax_t, intmax_t);
# endif
#elif defined GNULIB_POSIXCHECK
diff --git a/m4/imaxdiv.m4 b/m4/imaxdiv.m4
index 4539493..33931fa 100644
--- a/m4/imaxdiv.m4
+++ b/m4/imaxdiv.m4
@@ -1,4 +1,4 @@
-# imaxdiv.m4 serial 4
+# imaxdiv.m4 serial 5
dnl Copyright (C) 2006, 2009-2018 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -14,6 +14,26 @@ AC_DEFUN([gl_FUNC_IMAXDIV],
if test "$ac_cv_have_decl_imaxdiv" != yes; then
HAVE_DECL_IMAXDIV=0
fi
+
+ AC_CACHE_CHECK([whether <inttypes.h> defines imaxdiv_t],
+ [gl_cv_type_imaxdiv_t],
+ [dnl Assume that if imaxdiv is declared, imaxdiv_t is defined.
+ if test $ac_cv_have_decl_imaxdiv = yes; then
+ gl_cv_type_imaxdiv_t=yes
+ else
+ AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[#include <inttypes.h>
+ imaxdiv_t x;
+ ]])
+ ],
+ [gl_cv_type_imaxdiv_t=yes],
+ [gl_cv_type_imaxdiv_t=no])
+ fi
+ ])
+ if test $gl_cv_type_imaxdiv_t = no; then
+ HAVE_IMAXDIV_T=0
+ fi
])

# Prerequisites of lib/imaxdiv.c.
diff --git a/m4/inttypes.m4 b/m4/inttypes.m4
index 8069493..d756f01 100644
--- a/m4/inttypes.m4
+++ b/m4/inttypes.m4
@@ -1,4 +1,4 @@
-# inttypes.m4 serial 26
+# inttypes.m4 serial 27
dnl Copyright (C) 2006-2018 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -147,6 +147,7 @@ AC_DEFUN([gl_INTTYPES_H_DEFAULTS],
HAVE_DECL_IMAXDIV=1; AC_SUBST([HAVE_DECL_IMAXDIV])
HAVE_DECL_STRTOIMAX=1; AC_SUBST([HAVE_DECL_STRTOIMAX])
HAVE_DECL_STRTOUMAX=1; AC_SUBST([HAVE_DECL_STRTOUMAX])
+ HAVE_IMAXDIV_T=1; AC_SUBST([HAVE_IMAXDIV_T])
REPLACE_STRTOIMAX=0; AC_SUBST([REPLACE_STRTOIMAX])
REPLACE_STRTOUMAX=0; AC_SUBST([REPLACE_STRTOUMAX])
INT32_MAX_LT_INTMAX_MAX=1; AC_SUBST([INT32_MAX_LT_INTMAX_MAX])
diff --git a/modules/inttypes-incomplete b/modules/inttypes-incomplete
index 8c29a29..394d48f 100644
--- a/modules/inttypes-incomplete
+++ b/modules/inttypes-incomplete
@@ -42,6 +42,7 @@ inttypes.h: inttypes.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_U
-e 's/@''HAVE_DECL_IMAXDIV''@/$(HAVE_DECL_IMAXDIV)/g' \
-e 's/@''HAVE_DECL_STRTOIMAX''@/$(HAVE_DECL_STRTOIMAX)/g' \
-e 's/@''HAVE_DECL_STRTOUMAX''@/$(HAVE_DECL_STRTOUMAX)/g' \
+ -e 's/@''HAVE_IMAXDIV_T''@/$(HAVE_IMAXDIV_T)/g' \
-e 's/@''REPLACE_STRTOIMAX''@/$(REPLACE_STRTOIMAX)/g' \
-e 's/@''REPLACE_STRTOUMAX''@/$(REPLACE_STRTOUMAX)/g' \
-e 's/@''INT32_MAX_LT_INTMAX_MAX''@/$(INT32_MAX_LT_INTMAX_MAX)/g' \
Loading...