This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Sebastian's Patches Committed


> From: Hans-Peter Nilsson <hp@axis.com>
> Date: Fri, 25 Oct 2013 21:19:02 +0200

> Maybe make use of those __INT<X>_TYPE__-like macros defined in
> recent gcc when defining the __int<x>_t-line macros in
> _default_types.h.  Perhaps it's even ok to just do that and, as
> a fallback only, cheat and include stdint.h, if
> e.g. __UINT32_TYPE__ isn't defined. ;)

No task being too simple, here's a patch to do that.  It also
doesn't define __*int_least*_t types for those optional types
unless they're provided, fixing a further buglet when including
stdint.h which would make a difference only if it's actually
possible to use a non-newlib-stdint.h from within newlib.  A gcc
build of cris-elf succeeds and has passed the earlier gcc
test-suite point of failure.  Assuming no regressions, is this
ok to check in?

Or would you prefer the other way, putting the corresponding
part of libc/include/stdint.h here and making
libc/include/stdint.h include <machine/_default_types.h>?

newlib:
	* libc/include/machine/_default_types.h: Prefer use of
	gcc-specific type-macros when defining namespace-safe types.
	Only define __-equivalent int-types mapping to existing
	types.  Use stdint.h only as a fallback.

Index: newlib/libc/include/machine/_default_types.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/machine/_default_types.h,v
retrieving revision 1.4
diff -u -p -r1.4 _default_types.h
--- newlib/libc/include/machine/_default_types.h	15 Oct 2013 17:35:38 -0000	1.4
+++ newlib/libc/include/machine/_default_types.h	25 Oct 2013 20:13:51 -0000
@@ -5,39 +5,88 @@
 #ifndef _MACHINE__DEFAULT_TYPES_H
 #define _MACHINE__DEFAULT_TYPES_H
 
+/* Let's try to be namespace-clean: recent GCC provides macros we can
+   use for the internal definitions, guaranteed to be identical with the
+   stdint.h definitions (tested by the gcc test-suite).  */
+
+#ifndef __INT8_TYPE__
+
+/* Fall back to stdint.h, but beware that this will leak identifiers,
+   making e.g. stdlib.h define everything in stdint.h, which is strictly
+   wrong but unlikely to affect correct and real programs.  */
+
 #include <stdint.h>
 
+#define __INT8_TYPE__ int8_t
+#define __UINT8_TYPE__ uint8_t
+#define __INT16_TYPE__ int16_t
+#define __UINT16_TYPE__ uint16_t
+#define __INT32_TYPE__ int32_t
+#define __UINT32_TYPE__ uint32_t
+#ifdef INT_LEAST8_MAX
+#define __INT_LEAST8_TYPE__ int_least8_t
+#endif
+#ifdef UINT_LEAST8_MAX
+#define __UINT_LEAST8_TYPE__ uint_least8_t
+#endif
+#ifdef INT_LEAST16_MAX
+#define __INT_LEAST16_TYPE__ int_least16_t
+#endif
+#ifdef UINT_LEAST16_MAX
+#define __UINT_LEAST16_TYPE__ uint_least16_t
+#endif
+#ifdef INT_LEAST32_MAX
+#define __INT_LEAST32_TYPE__ int_least32_t
+#endif
+#ifdef UINT_LEAST32_MAX
+#define __UINT_LEAST32_TYPE__ uint_least32_t
+#endif
+#ifdef INT64_MAX
+#define __INT64_TYPE__ int64_t
+#define __UINT64_TYPE__ uint64_t
+#endif
+
+#endif /* defined __INT8_TYPE__ */
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-typedef int8_t __int8_t ;
-typedef uint8_t __uint8_t ;
+typedef __INT8_TYPE__ __int8_t;
+typedef __UINT8_TYPE__ __uint8_t;
 #define ___int8_t_defined 1
 
-typedef int_least8_t __int_least8_t;
-typedef uint_least8_t __uint_least8_t;
+#ifdef __INT_LEAST8_TYPE__
+typedef __INT_LEAST8_TYPE__ __int_least8_t;
+typedef __UINT_LEAST8_TYPE__ __uint_least8_t;
 #define ___int_least8_t_defined 1
+#endif
 
-typedef int16_t __int16_t;
-typedef uint16_t __uint16_t;
+typedef __INT16_TYPE__ __int16_t;
+typedef __UINT16_TYPE__ __uint16_t;
 #define ___int16_t_defined 1
 
-typedef int_least16_t __int_least16_t;
-typedef uint_least16_t __uint_least16_t;
+#ifdef __INT_LEAST16_TYPE__
+typedef __INT_LEAST16_TYPE__ __int_least16_t;
+typedef __UINT_LEAST16_TYPE__ __uint_least16_t;
 #define ___int_least16_t_defined 1
+#endif
 
-typedef int32_t __int32_t;
-typedef uint32_t __uint32_t;
+typedef __INT32_TYPE__ __int32_t;
+typedef __UINT32_TYPE__ __uint32_t;
 #define ___int32_t_defined 1
 
-typedef int_least32_t __int_least32_t;
-typedef uint_least32_t __uint_least32_t;
+#ifdef __INT_LEAST32_TYPE__
+typedef __INT_LEAST32_TYPE__ __int_least32_t;
+typedef __UINT_LEAST32_TYPE__ __uint_least32_t;
 #define ___int_least32_t_defined 1
+#endif
 
-typedef int64_t __int64_t;
-typedef uint64_t __uint64_t;
+#ifdef __INT64_TYPE__
+typedef __INT64_TYPE__ __int64_t;
+typedef __UINT64_TYPE__ __uint64_t;
 #define ___int64_t_defined 1
+#endif
 
 #ifdef __cplusplus
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]