[PATCH v2 01/18] Use __machine_*_t_defined for internal types

Sebastian Huber sebastian.huber at embedded-brains.de
Fri Apr 15 11:44:12 UTC 2016


Newlib defines defaults for internal types via <sys/_types.h> and uses
<machine/_types.h> to let targets define their own type if necessary.

Previously for example

	#ifndef __dev_t_defined
	typedef short __dev_t;
	#endif

However, the __*_t_defined pattern conflicts with the glibc type guard
pattern for user types, e.g. dev_t in this example.  Introduce a
__machine_*_t_defined pattern for internal types (defined by
<machine/_types.h>, used by <sys/_types.h>).  For example

	#ifndef __machine_dev_t_defined
	typedef short __dev_t;
	#endif

Signed-off-by: Sebastian Huber <sebastian.huber at embedded-brains.de>
---
 newlib/libc/include/sys/_types.h               | 38 ++++++++++++++++----------
 newlib/libc/machine/aarch64/machine/_types.h   |  2 +-
 newlib/libc/machine/spu/machine/_types.h       | 10 +++----
 newlib/libc/stdlib/local.h                     |  2 +-
 newlib/libc/sys/rtems/include/machine/_types.h | 38 ++++++++++----------------
 winsup/cygwin/include/machine/_types.h         |  8 +++---
 6 files changed, 49 insertions(+), 49 deletions(-)

diff --git a/newlib/libc/include/sys/_types.h b/newlib/libc/include/sys/_types.h
index c12eca3..762dfed 100644
--- a/newlib/libc/include/sys/_types.h
+++ b/newlib/libc/include/sys/_types.h
@@ -2,8 +2,18 @@
 
 /* This file defines various typedefs needed by the system calls that support
    the C library.  Basically, they're just the POSIX versions with an '_'
-   prepended.  This file lives in the `sys' directory so targets can provide
-   their own if desired (or they can put target dependant conditionals here).
+   prepended.  Targets shall use <machine/_types.h> to define their own
+   internal types if desired.
+
+   There are three define patterns used for type definitions.  Lets assume
+   xyz_t is a user type.
+
+   The internal type definition uses __machine_xyz_t_defined.  It is defined by
+   <machine/_types.h> to disable a default definition in <sys/_types.h>. It
+   must not be used in other files.
+
+   User type definitions are guarded by __xyz_t_defined in glibc and
+   _XYZ_T_DECLARED in BSD compatible systems.
 */
 
 #ifndef	_SYS__TYPES_H
@@ -12,7 +22,7 @@
 #include <machine/_types.h>
 #include <sys/lock.h>
 
-#ifndef __off_t_defined
+#ifndef __machine_off_t_defined
 typedef long _off_t;
 #endif
 
@@ -22,18 +32,18 @@ typedef signed char __pid_t;
 typedef int __pid_t;
 #endif
 
-#ifndef __dev_t_defined
+#ifndef __machine_dev_t_defined
 typedef short __dev_t;
 #endif
 
-#ifndef __uid_t_defined
+#ifndef __machine_uid_t_defined
 typedef unsigned short __uid_t;
 #endif
-#ifndef __gid_t_defined
+#ifndef __machine_gid_t_defined
 typedef unsigned short __gid_t;
 #endif
 
-#ifndef __off64_t_defined
+#ifndef __machine_off64_t_defined
 __extension__ typedef long long _off64_t;
 #endif
 
@@ -45,7 +55,7 @@ typedef _off_t __off_t;
 
 typedef _off64_t __loff_t;
 
-#ifndef __key_t_defined
+#ifndef __machine_key_t_defined
 typedef long __key_t;
 #endif
 
@@ -53,18 +63,18 @@ typedef long __key_t;
  * We need fpos_t for the following, but it doesn't have a leading "_",
  * so we use _fpos_t instead.
  */
-#ifndef __fpos_t_defined
+#ifndef __machine_fpos_t_defined
 typedef long _fpos_t;		/* XXX must match off_t in <sys/types.h> */
 				/* (and must be `long' for now) */
 #endif
 
 #ifdef __LARGE64_FILES
-#ifndef __fpos64_t_defined
+#ifndef __machine_fpos64_t_defined
 typedef _off64_t _fpos64_t;
 #endif
 #endif
 
-#ifndef __ssize_t_defined
+#ifndef __machine_ssize_t_defined
 #ifdef __SIZE_TYPE__
 /* If __SIZE_TYPE__ is defined (gcc) we define ssize_t based on size_t.
    We simply change "unsigned" to "signed" for this single definition
@@ -84,7 +94,7 @@ typedef long _ssize_t;
 #define __need_wint_t
 #include <stddef.h>
 
-#ifndef __mbstate_t_defined
+#ifndef __machine_mbstate_t_defined
 /* Conversion state information.  */
 typedef struct
 {
@@ -97,11 +107,11 @@ typedef struct
 } _mbstate_t;
 #endif
 
-#ifndef __flock_t_defined
+#ifndef __machine_flock_t_defined
 typedef _LOCK_RECURSIVE_T _flock_t;
 #endif
 
-#ifndef __iconv_t_defined
+#ifndef __machine_iconv_t_defined
 /* Iconv descriptor type */
 typedef void *_iconv_t;
 #endif
diff --git a/newlib/libc/machine/aarch64/machine/_types.h b/newlib/libc/machine/aarch64/machine/_types.h
index 7df9f8d..c846741 100644
--- a/newlib/libc/machine/aarch64/machine/_types.h
+++ b/newlib/libc/machine/aarch64/machine/_types.h
@@ -31,7 +31,7 @@
 
 #include <machine/_default_types.h>
 
-#define __ssize_t_defined
+#define __machine_ssize_t_defined
 typedef long signed int _ssize_t;
 
 #endif /* _MACHINE__TYPES_H */
diff --git a/newlib/libc/machine/spu/machine/_types.h b/newlib/libc/machine/spu/machine/_types.h
index d58c617..edff175 100644
--- a/newlib/libc/machine/spu/machine/_types.h
+++ b/newlib/libc/machine/spu/machine/_types.h
@@ -39,22 +39,22 @@
 /*
  * fpos_t large enough for either 32 or 64 bit ppc glibc fpos_t.
  */
-#define __fpos_t_defined
+#define __machine_fpos_t_defined
 typedef struct {
   char __pos[16];
 } _fpos_t;
 
 #ifdef __LARGE64_FILES
-#define __fpos64_t_defined
+#define __machine_fpos64_t_defined
 typedef _fpos_t _fpos64_t;
 #endif
 
-#define __dev_t_defined
+#define __machine_dev_t_defined
 typedef int __dev_t;
 
-#define __uid_t_defined
+#define __machine_uid_t_defined
 typedef unsigned int __uid_t;
-#define __gid_t_defined
+#define __machine_gid_t_defined
 typedef unsigned int __gid_t;
 
 #endif /* _MACHINE__TYPES_H */
diff --git a/newlib/libc/stdlib/local.h b/newlib/libc/stdlib/local.h
index 12e6998..aaa32df 100644
--- a/newlib/libc/stdlib/local.h
+++ b/newlib/libc/stdlib/local.h
@@ -7,7 +7,7 @@ char *	_EXFUN(_gcvt,(struct _reent *, double , int , char *, char, int));
 
 char *__locale_charset(_NOARGS);
 
-#ifndef __mbstate_t_defined
+#ifndef __machine_mbstate_t_defined
 #include <wchar.h>
 #endif
 
diff --git a/newlib/libc/sys/rtems/include/machine/_types.h b/newlib/libc/sys/rtems/include/machine/_types.h
index e0d93f7..f17d281 100644
--- a/newlib/libc/sys/rtems/include/machine/_types.h
+++ b/newlib/libc/sys/rtems/include/machine/_types.h
@@ -1,35 +1,25 @@
-/*
- *  $Id$
- */
-
 #ifndef _MACHINE__TYPES_H
-#define _MACHINE__TYPES_H
+#define	_MACHINE__TYPES_H
 
 #include <machine/_default_types.h>
 
-typedef __int32_t blksize_t;
-typedef __int32_t blkcnt_t;
+typedef	__int32_t	blksize_t;
+typedef	__int32_t	blkcnt_t;
 
-typedef __uint64_t __dev_t;
-#define __dev_t_defined 1
+typedef	__uint64_t	__dev_t;
+#define	__machine_dev_t_defined
 
 #if defined(__arm__) || defined(__i386__) || defined(__m68k__) || defined(__mips__) || defined(__PPC__) || defined(__sparc__)
-/* Use 64bit types */
-typedef __int64_t _off_t;
-#define __off_t_defined 1
-
-typedef __int64_t _fpos_t;
-#define __fpos_t_defined 1
+typedef	__int64_t	_off_t;
 #else
-/* Use 32bit types */
-typedef __int32_t _off_t;
-#define __off_t_defined 1
-
-typedef __int32_t _fpos_t;
-#define __fpos_t_defined 1
+typedef	__int32_t	_off_t;
 #endif
+#define	__machine_off_t_defined
 
-typedef __uint32_t _mode_t;
-#define __mode_t_defined 1
+typedef	_off_t		_fpos_t;
+#define	__machine_fpos_t_defined
 
-#endif
+typedef	__uint32_t	_mode_t;
+#define	__machine_mode_t_defined
+
+#endif /* _MACHINE__TYPES_H */
diff --git a/winsup/cygwin/include/machine/_types.h b/winsup/cygwin/include/machine/_types.h
index aafa998..50e704b 100644
--- a/winsup/cygwin/include/machine/_types.h
+++ b/winsup/cygwin/include/machine/_types.h
@@ -11,16 +11,16 @@ typedef __uint16_t __uid16_t;
 typedef __uint16_t __gid16_t;
 #endif
 
-#define __dev_t_defined
+#define __machine_dev_t_defined
 typedef __uint32_t __dev_t;
 
-#define __uid_t_defined
+#define __machine_uid_t_defined
 typedef __uint32_t __uid_t;
 
-#define __gid_t_defined
+#define __machine_gid_t_defined
 typedef __uint32_t __gid_t;
 
-#define __key_t_defined
+#define __machine_key_t_defined
 typedef long long __key_t;
 
 #endif /* _MACHINE__TYPES_H */
-- 
1.8.4.5



More information about the devel mailing list