public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix inttypes.h
@ 2014-09-22  7:10 Sebastian Huber
  2014-10-08 21:52 ` Joel Sherrill
  0 siblings, 1 reply; 4+ messages in thread
From: Sebastian Huber @ 2014-09-22  7:10 UTC (permalink / raw)
  To: newlib; +Cc: Sebastian Huber

Do not rely on Newlib <stdint.h> provided __have_longlong64,
__have_long64 and __have_long32 since in case GCC <stdint.h> is used
these defines are not available.

newlib/ChangeLog
2014-09-22  Sebastian Huber  <sebastian.huber@embedded-brains.de>

	* libc/include/inttypes.h: Add and
	use __INTTYPES_HAVE_LONGLONG64, __INTTYPES_HAVE_LONG64 and
	__INTTYPES_HAVE_LONG32.
---
 newlib/libc/include/inttypes.h | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/newlib/libc/include/inttypes.h b/newlib/libc/include/inttypes.h
index 1631e21..bfa5c9d 100644
--- a/newlib/libc/include/inttypes.h
+++ b/newlib/libc/include/inttypes.h
@@ -27,6 +27,19 @@
   #include <limits.h>
 #endif
 
+/* Check if "long long" is 64bit wide */
+#if ( defined(__LONG_LONG_MAX__) && (__LONG_LONG_MAX__ > 0x7fffffff) ) \
+  || ( defined(LLONG_MAX) && (LLONG_MAX > 0x7fffffff) )
+#define __INTTYPES_HAVE_LONGLONG64 1
+#endif
+
+/* Check if "long" is 64bit or 32bit wide */
+#if __INTTYPES_EXP(LONG_MAX) > 0x7fffffff
+#define __INTTYPES_HAVE_LONG64 1
+#elif __INTTYPES_EXP(LONG_MAX) == 0x7fffffff && !defined(__SPU__)
+#define __INTTYPES_HAVE_LONG32 1
+#endif
+
 #define __STRINGIFY(a) #a
 
 /* 8-bit types */
@@ -122,7 +135,7 @@
 #define SCNxFAST16	__SCN16(x)
 
 /* 32-bit types */
-#if __have_long32
+#if __INTTYPES_HAVE_LONG32
 #define __PRI32(x) __STRINGIFY(l##x)
 #define __SCN32(x) __STRINGIFY(l##x)
 #else
@@ -173,10 +186,10 @@
 
 
 /* 64-bit types */
-#if __have_long64
+#if __INTTYPES_HAVE_LONG64
 #define __PRI64(x) __STRINGIFY(l##x)
 #define __SCN64(x) __STRINGIFY(l##x)
-#elif __have_longlong64
+#elif __INTTYPES_HAVE_LONGLONG64
 #define __PRI64(x) __STRINGIFY(ll##x)
 #define __SCN64(x) __STRINGIFY(ll##x)
 #else
@@ -227,10 +240,10 @@
 #endif
 
 /* max-bit types */
-#if __have_long64
+#if __INTTYPES_HAVE_LONG64
 #define __PRIMAX(x) __STRINGIFY(l##x)
 #define __SCNMAX(x) __STRINGIFY(l##x)
-#elif __have_longlong64
+#elif __INTTYPES_HAVE_LONGLONG64
 #define __PRIMAX(x) __STRINGIFY(ll##x)
 #define __SCNMAX(x) __STRINGIFY(ll##x)
 #else
@@ -255,7 +268,8 @@
 #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)
+#elif PTRDIFF_MAX <= __INTTYPES_EXP(LONG_MAX) \
+  || !defined(__INTTYPES_HAVE_LONGLONG64)
 # define __PRIPTR(x) __STRINGIFY(l##x)
 # define __SCNPTR(x) __STRINGIFY(l##x)
 #else
-- 
1.8.4.5

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix inttypes.h
  2014-09-22  7:10 [PATCH] Fix inttypes.h Sebastian Huber
@ 2014-10-08 21:52 ` Joel Sherrill
  2014-10-09 12:43   ` Corinna Vinschen
  0 siblings, 1 reply; 4+ messages in thread
From: Joel Sherrill @ 2014-10-08 21:52 UTC (permalink / raw)
  To: Sebastian Huber, newlib

Polite Ping now that Jeff appears to be back. :)


On 9/22/2014 2:09 AM, Sebastian Huber wrote:
> Do not rely on Newlib <stdint.h> provided __have_longlong64,
> __have_long64 and __have_long32 since in case GCC <stdint.h> is used
> these defines are not available.
>
> newlib/ChangeLog
> 2014-09-22  Sebastian Huber  <sebastian.huber@embedded-brains.de>
>
> 	* libc/include/inttypes.h: Add and
> 	use __INTTYPES_HAVE_LONGLONG64, __INTTYPES_HAVE_LONG64 and
> 	__INTTYPES_HAVE_LONG32.
> ---
>  newlib/libc/include/inttypes.h | 26 ++++++++++++++++++++------
>  1 file changed, 20 insertions(+), 6 deletions(-)
>
> diff --git a/newlib/libc/include/inttypes.h b/newlib/libc/include/inttypes.h
> index 1631e21..bfa5c9d 100644
> --- a/newlib/libc/include/inttypes.h
> +++ b/newlib/libc/include/inttypes.h
> @@ -27,6 +27,19 @@
>    #include <limits.h>
>  #endif
>  
> +/* Check if "long long" is 64bit wide */
> +#if ( defined(__LONG_LONG_MAX__) && (__LONG_LONG_MAX__ > 0x7fffffff) ) \
> +  || ( defined(LLONG_MAX) && (LLONG_MAX > 0x7fffffff) )
> +#define __INTTYPES_HAVE_LONGLONG64 1
> +#endif
> +
> +/* Check if "long" is 64bit or 32bit wide */
> +#if __INTTYPES_EXP(LONG_MAX) > 0x7fffffff
> +#define __INTTYPES_HAVE_LONG64 1
> +#elif __INTTYPES_EXP(LONG_MAX) == 0x7fffffff && !defined(__SPU__)
> +#define __INTTYPES_HAVE_LONG32 1
> +#endif
> +
>  #define __STRINGIFY(a) #a
>  
>  /* 8-bit types */
> @@ -122,7 +135,7 @@
>  #define SCNxFAST16	__SCN16(x)
>  
>  /* 32-bit types */
> -#if __have_long32
> +#if __INTTYPES_HAVE_LONG32
>  #define __PRI32(x) __STRINGIFY(l##x)
>  #define __SCN32(x) __STRINGIFY(l##x)
>  #else
> @@ -173,10 +186,10 @@
>  
>  
>  /* 64-bit types */
> -#if __have_long64
> +#if __INTTYPES_HAVE_LONG64
>  #define __PRI64(x) __STRINGIFY(l##x)
>  #define __SCN64(x) __STRINGIFY(l##x)
> -#elif __have_longlong64
> +#elif __INTTYPES_HAVE_LONGLONG64
>  #define __PRI64(x) __STRINGIFY(ll##x)
>  #define __SCN64(x) __STRINGIFY(ll##x)
>  #else
> @@ -227,10 +240,10 @@
>  #endif
>  
>  /* max-bit types */
> -#if __have_long64
> +#if __INTTYPES_HAVE_LONG64
>  #define __PRIMAX(x) __STRINGIFY(l##x)
>  #define __SCNMAX(x) __STRINGIFY(l##x)
> -#elif __have_longlong64
> +#elif __INTTYPES_HAVE_LONGLONG64
>  #define __PRIMAX(x) __STRINGIFY(ll##x)
>  #define __SCNMAX(x) __STRINGIFY(ll##x)
>  #else
> @@ -255,7 +268,8 @@
>  #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)
> +#elif PTRDIFF_MAX <= __INTTYPES_EXP(LONG_MAX) \
> +  || !defined(__INTTYPES_HAVE_LONGLONG64)
>  # define __PRIPTR(x) __STRINGIFY(l##x)
>  # define __SCNPTR(x) __STRINGIFY(l##x)
>  #else

-- 
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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix inttypes.h
  2014-10-08 21:52 ` Joel Sherrill
@ 2014-10-09 12:43   ` Corinna Vinschen
  2014-10-09 12:49     ` Sebastian Huber
  0 siblings, 1 reply; 4+ messages in thread
From: Corinna Vinschen @ 2014-10-09 12:43 UTC (permalink / raw)
  To: newlib

[-- Attachment #1: Type: text/plain, Size: 451 bytes --]

On Oct  8 16:52, Joel Sherrill wrote:
> Polite Ping now that Jeff appears to be back. :)

I'm not Jeff, but I'm wondering... rather than doing these checks
in two places, stdint.h and inttypes.h, wouldn't it be funny to have
a private header, only consisting of these tests, and including them
from stdint.h and inttypes.h?  The inttypes.h checks could be left
unchanged then.


Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat

[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix inttypes.h
  2014-10-09 12:43   ` Corinna Vinschen
@ 2014-10-09 12:49     ` Sebastian Huber
  0 siblings, 0 replies; 4+ messages in thread
From: Sebastian Huber @ 2014-10-09 12:49 UTC (permalink / raw)
  To: newlib

On 09/10/14 14:42, Corinna Vinschen wrote:
> On Oct  8 16:52, Joel Sherrill wrote:
>> >Polite Ping now that Jeff appears to be back.:)
> I'm not Jeff, but I'm wondering... rather than doing these checks
> in two places, stdint.h and inttypes.h, wouldn't it be funny to have
> a private header, only consisting of these tests, and including them
> from stdint.h and inttypes.h?  The inttypes.h checks could be left
> unchanged then.

Ok, I will update the patch.  A similar issue exists with __INTTYPES_EXP().

-- 
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : sebastian.huber@embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-10-09 12:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-22  7:10 [PATCH] Fix inttypes.h Sebastian Huber
2014-10-08 21:52 ` Joel Sherrill
2014-10-09 12:43   ` Corinna Vinschen
2014-10-09 12:49     ` Sebastian Huber

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).