inttypes. uintptr_t patch v1

Joel Sherrill joel.sherrill@oarcorp.com
Thu Sep 18 20:58:00 GMT 2014


Hi

Attached is a first cut at the changes we discussed last week
to determine if uintptr_t is unsigned long long, unsigned long,
or simply unsigned int (default).

I haven't tested this extensively and am a bit concerned that
on the m68k uintptr_t is typedef'ed to "unsigned int" but the
probe detects it as "unsigned long". I haven't gotten far enough
to see if this makes the printf() checking happy with my test
case but wanted feedback.

I will need to build a bunch of toolsets to test this properly and
would rather get feedback before I invest a lot of time in this.

Thanks.

2014-09-18  Joel Sherrill <joel.sherrill>

        * configure.in: Add probes to determine if uintptr_t is
        unsigned long (define _UINTPTR_EQ_ULONG) or unsigned long long
        (define _UINTPTR_EQ_ULONGLONG).
        * configure: Regenerated.
        * newlib.him: Add new probe macros.
        * libc/include/inttypes.h: Use new probe macros.


-- 
Joel Sherrill, Ph.D.             Director of Research & Development
joel.sherrill@OARcorp.com        On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
Support Available                (256) 722-9985

-------------- next part --------------
Index: configure.in
===================================================================
RCS file: /cvs/src/src/newlib/configure.in,v
retrieving revision 1.58
diff -u -r1.58 configure.in
--- configure.in	7 Jul 2014 13:15:55 -0000	1.58
+++ configure.in	18 Sep 2014 19:41:49 -0000
@@ -617,6 +617,47 @@
   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],
Index: newlib.hin
===================================================================
RCS file: /cvs/src/src/newlib/newlib.hin,v
retrieving revision 1.29
diff -u -r1.29 newlib.hin
--- newlib.hin	4 Jul 2014 17:21:42 -0000	1.29
+++ newlib.hin	18 Sep 2014 19:41:49 -0000
@@ -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
 
Index: libc/include/inttypes.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/inttypes.h,v
retrieving revision 1.6
diff -u -r1.6 inttypes.h
--- libc/include/inttypes.h	26 Nov 2012 16:26:06 -0000	1.6
+++ libc/include/inttypes.h	18 Sep 2014 19:41:49 -0000
@@ -252,15 +252,15 @@
 #define SCNxMAX		__SCNMAX(x)
 
 /* ptr types */
-#if PTRDIFF_MAX <= __INTTYPES_EXP(INT_MAX)
-# define __PRIPTR(x) __STRINGIFY(x)
-# define __SCNPTR(x) __STRINGIFY(x)
-#elif PTRDIFF_MAX <= __INTTYPES_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)


More information about the Newlib mailing list