From: Oliver Kurth Date: Fri, 5 Jan 2018 22:47:15 +0000 (-0800) Subject: vm_basic_types.h: use stdint.h a little more. X-Git-Tag: stable-10.3.0~184 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8a9c43698ebcc858314ec1c041d24b8e8d1372cf;p=thirdparty%2Fopen-vm-tools.git vm_basic_types.h: use stdint.h a little more. Now that enough of the builds are C++11, let's make the common case use the header to define the intNN types directly from language-standard intNN_t types, and treat pre-C99/C++98 code as the special case. This also provides some clarity about the last __STRICT_ANSI__ macros in this file. One was related to usage of 'long long' in strict c90 mode and has been replaced with a comment indicating that 64-bit-variable compiler extensions are mandatory (strict c90 mode is not allowed via the headers). The other related to X11 headers; those headers have been examined to understand the workarounds needed and the exact scenario(s) that are problematic have been commented (turns out FreeBSD had nothing to do with the problem). Finally, all the Bool-related definitions have been moved and merged to a single location NOT at the top of the file. Net effects of this change: - non-linux C++11 (so Windows+Mac) now uses stdint.h - exact set of macros involved in declaring Bool is reduced - compiling with c90 mode really will break now (use gnu90 instead). --- diff --git a/open-vm-tools/lib/include/vm_basic_types.h b/open-vm-tools/lib/include/vm_basic_types.h index 5794a9907..209673d73 100644 --- a/open-vm-tools/lib/include/vm_basic_types.h +++ b/open-vm-tools/lib/include/vm_basic_types.h @@ -77,24 +77,6 @@ #define INCLUDE_ALLOW_VMCORE #include "includeCheck.h" -/* STRICT ANSI means the Xserver build and X defines Bool differently. */ -#if !defined(_XTYPEDEF_BOOL) && \ - (!defined(__STRICT_ANSI__) || defined(__FreeBSD__) || \ - defined(__MINGW32__) || defined(__APPLE__)) -#define _XTYPEDEF_BOOL -typedef char Bool; -#endif - -#ifndef FALSE -#define FALSE 0 -#endif - -#ifndef TRUE -#define TRUE 1 -#endif - -#define IS_BOOL(x) (((x) & ~1) == 0) - /* * Macros __i386__ and __ia64 are intrinsically defined by GCC */ @@ -177,7 +159,14 @@ typedef char Bool; #endif -#if defined(__linux__) && defined(__cplusplus) && __cplusplus >= 201103L +#if defined(__cplusplus) && __cplusplus >= 201103L || \ + defined(__APPLE__) || defined(HAVE_STDINT_H) +/* + * TODO: C99 a.k.a. defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + * really should be in the above conditional. However, a non-trivial amount + * of code tries to compile in C99 mode with broken stdint.h headers, so + * C99 will need to use the fallback for now. + */ /* * We're using stdint.h instead of cstdint below because of libstdcpp.cpp. @@ -186,8 +175,6 @@ typedef char Bool; */ #include -typedef char Bool; - typedef uint64_t uint64; typedef int64_t int64; typedef uint32_t uint32; @@ -197,52 +184,25 @@ typedef int16_t int16; typedef uint8_t uint8; typedef int8_t int8; -#elif defined(__APPLE__) || defined(HAVE_STDINT_H) - -/* - * TODO: This is a C99 standard header. We should be able to test for - * #if __STDC_VERSION__ >= 199901L, but that breaks the Netware build - * (which doesn't have stdint.h). - */ - -#include - -typedef uint64_t uint64; -typedef int64_t int64; -typedef uint32_t uint32; -typedef int32_t int32; -typedef uint16_t uint16; -typedef int16_t int16; -typedef uint8_t uint8; -typedef int8_t int8; - -/* - * Note: C does not specify whether char is signed or unsigned, and - * both gcc and msvc implement processor-specific signedness. With - * three types: - * typeof(char) != typeof(signed char) != typeof(unsigned char) - * - * Be careful here, because gcc (4.0.1 and others) likes to warn about - * conversions between signed char * and char *. - */ - #else /* !HAVE_STDINT_H */ +/* Pre-c99 or pre-c++11; use compiler extension to get 64-bit types */ #ifdef _MSC_VER typedef unsigned __int64 uint64; typedef signed __int64 int64; #elif __GNUC__ -/* The Xserver source compiles with -ansi -pendantic */ -# if !defined(__STRICT_ANSI__) || defined(__FreeBSD__) -# if defined(VM_X86_64) || defined(VM_ARM_64) +# if defined(VM_X86_64) || defined(VM_ARM_64) typedef unsigned long uint64; typedef long int64; -# else +# else +/* + * Only strict c90 (without extensions) lacks a 'long long' type. + * If this declaration fails ... use -std=c99 or -std=gnu90. + */ typedef unsigned long long uint64; typedef long long int64; -# endif # endif #else # error - Need compiler define for int64/uint64 @@ -258,6 +218,36 @@ typedef signed char int8; #endif /* HAVE_STDINT_H */ + +/* + * The _XTYPEDEF_BOOL guard prevents colliding with: + * #define Bool int + * typedef int Bool; + * If using this header AND X11 headers, be sure to #undef Bool and + * be careful about the different size. + */ +#if !defined(_XTYPEDEF_BOOL) +#define _XTYPEDEF_BOOL +/* + * C does not specify whether char is signed or unsigned, and + * both gcc and msvc implement it as a non-signed, non-unsigned type. + * Thus, (uint8_t *)&Bool and (int8_t *)&Bool are possible compile errors. + * This is intentional. + */ +typedef char Bool; +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +#ifndef TRUE +#define TRUE 1 +#endif + +#define IS_BOOL(x) (((x) & ~1) == 0) + + /* * FreeBSD (for the tools build) unconditionally defines these in * sys/inttypes.h so don't redefine them if this file has already