[PATCH 2/2] Add autoconf detection of size of uintptr_t
Jeff Johnston
jjohnstn@redhat.com
Tue Oct 28 19:23:00 GMT 2014
One minor nit. Might as well put the ulong check in an else block after the
check for if test $newlib_cv_uintptr_eq_ulonglong = yes and avoid the extra compile test
when appropriate.
Other than that, looks good.
-- Jeff J.
----- Original Message -----
From: "Joel Sherrill" <joel.sherrill@oarcorp.com>
To: newlib@sourceware.org
Cc: "Joel Sherrill" <joel.sherrill@oarcorp.com>
Sent: Friday, October 24, 2014 6:41:27 PM
Subject: [PATCH 2/2] Add autoconf detection of size of uintptr_t
2014-10-24 Joel Sherrill <joel.sherrill@oarcorp.com>
* configure.in: Add autoconf test to determine size of uintptr_t.
* newlib.hin: Add new autoconf feature variables.
* libc/include/inttypes.h: Use new feature variables.
* configure: Regenerate.
---
newlib/configure.in | 41 +++++++++++++++++++++++++++++++++++++++++
newlib/libc/include/inttypes.h | 12 ++++++------
newlib/newlib.hin | 6 ++++++
3 files changed, 53 insertions(+), 6 deletions(-)
diff --git a/newlib/configure.in b/newlib/configure.in
index 9465787..88886f7 100644
--- a/newlib/configure.in
+++ b/newlib/configure.in
@@ -617,6 +617,47 @@ if test $newlib_cv_ldbl_eq_dbl = yes; then
AC_DEFINE_UNQUOTED(_LDBL_EQ_DBL)
fi
+#### Determine if uintptr_t is unsigned long long
+AC_CACHE_CHECK(whether uintptr_t equals unsigned long long,
+ newlib_cv_uintptr_eq_ulonglong, [dnl
+cat > conftest.c <<EOF
+#include <inttypes.h>
+extern int foo(uintptr_t);
+extern int foo(unsigned long long);
+EOF
+if AC_TRY_COMMAND([${CC} $CFLAGS $CPPFLAGS -c -o conftest.o conftest.c
+ 1>&AS_MESSAGE_LOG_FD])
+then
+ newlib_cv_uintptr_eq_ulonglong=yes;
+else
+ newlib_cv_uintptr_eq_ulonglong=no;
+fi
+rm -f conftest*])
+if test $newlib_cv_uintptr_eq_ulonglong = yes; then
+ AC_DEFINE_UNQUOTED(_UINTPTR_EQ_ULONGLONG)
+fi
+
+#### Determine if uintptr_t is unsigned long
+AC_CACHE_CHECK(whether uintptr_t equals unsigned long,
+ newlib_cv_uintptr_eq_ulong, [dnl
+cat > conftest.c <<EOF
+#include <inttypes.h>
+extern int foo(uintptr_t);
+extern int foo(unsigned long);
+EOF
+if AC_TRY_COMMAND([${CC} $CFLAGS $CPPFLAGS -c -o conftest.o conftest.c
+ 1>&AS_MESSAGE_LOG_FD])
+then
+ newlib_cv_uintptr_eq_ulong=yes;
+else
+ newlib_cv_uintptr_eq_ulong=no;
+fi
+rm -f conftest*])
+if test $newlib_cv_uintptr_eq_ulong = yes; then
+ AC_DEFINE_UNQUOTED(_UINTPTR_EQ_ULONG)
+fi
+
+
AC_SUBST(CFLAGS)
AC_CONFIG_FILES([Makefile],
diff --git a/newlib/libc/include/inttypes.h b/newlib/libc/include/inttypes.h
index 2470b09..5a8770b 100644
--- a/newlib/libc/include/inttypes.h
+++ b/newlib/libc/include/inttypes.h
@@ -243,15 +243,15 @@
#define SCNxMAX __SCNMAX(x)
/* ptr types */
-#if PTRDIFF_MAX <= __STDINT_EXP(INT_MAX)
-# define __PRIPTR(x) __STRINGIFY(x)
-# define __SCNPTR(x) __STRINGIFY(x)
-#elif PTRDIFF_MAX <= __STDINT_EXP(LONG_MAX) || !defined(__have_longlong64)
+#if defined(_UINTPTR_EQ_ULONGLONG)
+# define __PRIPTR(x) __STRINGIFY(ll##x)
+# define __SCNPTR(x) __STRINGIFY(ll##x)
+#elif defined(_UINTPTR_EQ_ULONG)
# define __PRIPTR(x) __STRINGIFY(l##x)
# define __SCNPTR(x) __STRINGIFY(l##x)
#else
-# define __PRIPTR(x) __STRINGIFY(ll##x)
-# define __SCNPTR(x) __STRINGIFY(ll##x)
+# define __PRIPTR(x) __STRINGIFY(x)
+# define __SCNPTR(x) __STRINGIFY(x)
#endif
#define PRIdPTR __PRIPTR(d)
diff --git a/newlib/newlib.hin b/newlib/newlib.hin
index eadafc8..64aa9b3 100644
--- a/newlib/newlib.hin
+++ b/newlib/newlib.hin
@@ -61,6 +61,12 @@
/* True if long double supported and it is equal to double. */
#undef _LDBL_EQ_DBL
+/* Define if uintptr_t is unsigned long on this architecture */
+#undef _UINTPTR_EQ_ULONG
+
+/* Define if uintptr_t is unsigned long long on this architecture */
+#undef _UINTPTR_EQ_ULONGLONG
+
/* Define if ivo supported in streamio. */
#undef _FVWRITE_IN_STREAMIO
--
1.9.3
More information about the Newlib
mailing list