[PATCH v3 4/4] include: Fix conflicting definitions of NULL, wchar_t, wint_t, wctype_t.

Kevin Puetz PuetzKevinA at JohnDeere.com
Thu Sep 24 10:12:12 CDT 2020


When <basetyps.h> defines wchar_t, it must obey -f(no-)short-wchar
by referring to __WCHAR_TYPE__ which may not be `unsigned short`.

Similarly, windef.h defining NULL may need to use GCC's __null.
Otherwise one-definition-rule problems arise depending on whether
wine or libc headers are included first.

tchar.h wint_t and wctype_t are defined by <wchar.h>,
which was already being included.

Implementing these by deferring to the C89-specified libc headers,
(or msvcrt's versions with -mno-cygwin) ensures matching definitions.

Signed-off-by: Kevin Puetz <PuetzKevinA at JohnDeere.com>
---

<basetyps.h> uses gcc's __need_* macros to document/filter that it only
intends to define wchar_t (and not the rest, e.g. size_t/ptrdiff_t)
to match the names defined by the MSVC version as closely as possible.
That's not portable, but if not supported it'll just get the rest too,
which is unlikely to really hurt anything in practice.

<windef.h> always ended up with all of <stddef.h> later (via <winnt.h>),
and the real SDK header does to, so there's no reason to be subtle
there.
---
 include/basetyps.h | 8 +++++---
 include/tchar.h    | 9 ---------
 include/windef.h   | 9 +++++----
 3 files changed, 10 insertions(+), 16 deletions(-)

diff --git a/include/basetyps.h b/include/basetyps.h
index b0dd5d77f4..a2c5ed49f2 100644
--- a/include/basetyps.h
+++ b/include/basetyps.h
@@ -91,9 +91,11 @@ typedef unsigned long error_status_t;
 #endif
 
 #ifndef _WCHAR_T_DEFINED
-#ifndef __cplusplus
-typedef unsigned short wchar_t;
-#endif
+# ifndef __cplusplus
+#  define __need_wchar_t /* tells GCC's stddef.h we only need wchar_t */
+#  include <stddef.h>
+#  undef __need_wchar_t
+# endif
 #define _WCHAR_T_DEFINED
 #endif
 
diff --git a/include/tchar.h b/include/tchar.h
index b933b9dd15..6d785c0f51 100644
--- a/include/tchar.h
+++ b/include/tchar.h
@@ -232,15 +232,6 @@ extern "C" {
 #endif /* tchar mappings */
 
 #ifdef _UNICODE
-#if !defined(_WINT_T_DEFINED) && !defined(__WINT_TYPE__)
-typedef unsigned short wint_t;
-#endif
-
-#ifndef _WCTYPE_T_DEFINED
-typedef unsigned short wctype_t;
-#define _WCTYPE_T_DEFINED
-#endif
-
 #ifndef __TCHAR_DEFINED
 #if defined(WINE_UNICODE_NATIVE)
 #define __T(x) L##x
diff --git a/include/windef.h b/include/windef.h
index 521c3ab451..c0323d4275 100644
--- a/include/windef.h
+++ b/include/windef.h
@@ -206,11 +206,12 @@ extern "C" {
 
 /* Misc. constants. */
 
-#undef NULL
-#ifdef __cplusplus
-#define NULL  0
-#else
+#ifndef NULL
+#ifdef RC_INVOKED
 #define NULL  ((void*)0)
+#else
+#include <stddef.h>
+#endif
 #endif
 
 #ifdef FALSE



More information about the wine-devel mailing list