diff dyncall/dyncall_macros.h @ 616:5d999f5c13d1

- fixed mingw and cygwin env detection (was always shadowed by _WIN32 macro detection, and __MINGW__ macro check was wrong to begin with) - cosmetic cleanups for consistency - added runtime detection to dyncall_macros.h to handle some edge cases - fixed detection of native thiscall callconv for builds not using MSVC but using (or adhering to) the MSVC runtime (e.g. ReactOS' MinGW based RosBE)
author Tassilo Philipp
date Sun, 02 Oct 2022 13:58:33 +0200
parents dfc2e6ee8782
children 6a8aac9b2bcf
line wrap: on
line diff
--- a/dyncall/dyncall_macros.h	Sat Oct 01 16:14:00 2022 +0200
+++ b/dyncall/dyncall_macros.h	Sun Oct 02 13:58:33 2022 +0200
@@ -50,83 +50,89 @@
 
 /* MS Windows XP x64/Vista64 or later. */
 #if defined(WIN64) || defined(_WIN64) || defined(__WIN64__)
-#define DC__OS_Win64
+# define DC__OS_Win64
 
 /* MS Windows NT/95/98/ME/2000/XP/Vista32. */
 #elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || defined(__WINDOWS__) || defined(_WINDOWS)
-#define DC__OS_Win32
+# define DC__OS_Win32
 
 /* All the OS' based on Darwin OS (MacOS X, OpenDarwin). Note that '__APPLE__' may be defined for classic MacOS, too. */
 /* __MACOSX__ is not defined in gcc assembler mode (switch: -S) */
-/* @@@ TODO: Check for Classic OS */
-
 #elif defined(__APPLE__) || defined(__Darwin__)
-#  define DC__OS_Darwin
-#  if defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__)
-#    define DC__OS_IPhone
-#  else /* defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) */
-#    define DC__OS_MacOSX
-#  endif
+# define DC__OS_Darwin
+# if defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__)
+#  define DC__OS_IPhone
+# else /* defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) */
+#  define DC__OS_MacOSX
+# endif
 
 /* The most popular open source Unix-like OS - Linux. */
 #elif defined(__linux__) || defined(__linux) || defined(__gnu_linux__)
-#define DC__OS_Linux
+# define DC__OS_Linux
 
 /* The most powerful open source Unix-like OS - FreeBSD. */
 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) /* latter is (also) used by systems using FreeBSD kernel, e.g. Debian/kFreeBSD, which could be detected specifically by also checking for __GLIBC__ */
-#define DC__OS_FreeBSD
+# define DC__OS_FreeBSD
 
 /* The most secure open source Unix-like OS - OpenBSD. */
 #elif defined(__OpenBSD__)
-#define DC__OS_OpenBSD
+# define DC__OS_OpenBSD
 
 /* The most portable open source Unix-like OS - NetBSD. */
 #elif defined(__NetBSD__)
-#define DC__OS_NetBSD
+# define DC__OS_NetBSD
 
 /* The FreeBSD fork having heavy clusterization in mind - DragonFlyBSD. */
 #elif defined(__DragonFly__)
-#define DC__OS_DragonFlyBSD
+# define DC__OS_DragonFlyBSD
 
 /* Sun's Unix-like OS - SunOS / Solaris. */
 #elif defined(__sun__) || defined(__sun) || defined(sun)
-#define DC__OS_SunOS
-
-/* The "Linux-like environment for Windows" - Cygwin. */
-#elif defined(__CYGWIN__)
-#define DC__OS_Cygwin
-
-/* The "Minimalist GNU for Windows" - MinGW. */
-#elif defined(__MINGW__)/*@@@*/
-#define DC__OS_MinGW
+# define DC__OS_SunOS
 
 /* The Nintendo DS (homebrew) using devkitpro. */
 #elif defined(__nds__)
-#define DC__OS_NDS
+# define DC__OS_NDS
 
 /* The PlayStation Portable (homebrew) SDK. */
 #elif defined(__psp__) || defined(PSP)
-#define DC__OS_PSP
+# define DC__OS_PSP
 
 /* Haiku (BeOS alike). */
 #elif defined(__HAIKU__)
-#define DC__OS_BeOS
+# define DC__OS_BeOS
 
 /* The Unix successor - Plan9 from Bell Labs */
 #elif defined(Plan9) || defined(__Plan9__)
-#define DC__OS_Plan9
+# define DC__OS_Plan9
 
 /* Digital's Unix-like OS - VMS */
 #elif defined(__vms)
-#define DC__OS_VMS
+# define DC__OS_VMS
 
+/* Tanenbaum's Microkernel OS - Minix */
 #elif defined(__minix)
-#define DC__OS_Minix
-
-#else
+# define DC__OS_Minix
 
 /* Unable to determine OS, which is probably ok (e.g. baremetal stuff, etc.). */
-#define DC__OS_UNKNOWN
+#else
+# define DC__OS_UNKNOWN
+
+#endif
+
+
+/* windows sub envs */
+#if defined(DC__OS_Win32) || defined(DC__OS_Win64)
+
+/* The "Linux-like environment for Windows" - Cygwin. */
+# if defined(__CYGWIN__)
+#  define DC__OS_Cygwin
+
+/* The "Minimalist GNU for Windows" - MinGW. */
+# elif defined(__MINGW32__) || defined(__MINGW64__)
+#  define DC__OS_MinGW
+# endif
+
 #endif
 
 
@@ -137,35 +143,35 @@
 
 /* Intel's C/C++ compiler. */
 #if defined(__INTEL_COMPILER)
-#define DC__C_Intel
+# define DC__C_Intel
 
 /* MS C/C++ compiler. */
 #elif defined(_MSC_VER)
-#define DC__C_MSVC
+# define DC__C_MSVC
 
 /* LLVM clang. */
 #elif defined(__clang__) || defined(__llvm__)
-#define DC__C_CLANG
+# define DC__C_CLANG
 
 /* The GNU Compiler Collection - GCC. */
 #elif defined(__GNUC__)
-#define DC__C_GNU
+# define DC__C_GNU
 
 /* Watcom compiler. */
 #elif defined(__WATCOMC__)
-#define DC__C_WATCOM
+# define DC__C_WATCOM
 
 /* Portable C Compiler. */
 #elif defined(__PCC__)
-#define DC__C_PCC
+# define DC__C_PCC
 
 /* Sun Pro C. */
 #elif defined(__SUNPRO_C)
-#define DC__C_SUNPRO
+# define DC__C_SUNPRO
 
 /* Undetected C Compiler. */
 #else
-#define DC__C_UNKNOWN
+# define DC__C_UNKNOWN
 #endif
 
 
@@ -181,9 +187,9 @@
 # define DC__Arch_Itanium
 #elif defined(_M_PPC) || defined(__powerpc__) || defined(__powerpc) || defined(__POWERPC__) || defined(__ppc__) || defined(__power__)
 # if defined(__ppc64__) || defined(_ARCH_PPC64) || defined(__power64__) || defined(__powerpc64__)
-#   define DC__Arch_PPC64
+#  define DC__Arch_PPC64
 # else
-#   define DC__Arch_PPC32
+#  define DC__Arch_PPC32
 # endif
 #elif defined(__mips64__) || defined(__mips64)
 # define DC__Arch_MIPS64
@@ -205,6 +211,13 @@
 
 
 
+/* -- Runtime ------------------------------------------------------- */
+
+#if defined(__MSVCRT__)
+# define DC__RT_MSVCRT
+#endif
+
+
 /* -- Rough OS classification --------------------------------------- */
 
 #if defined(DC__OS_Win32) || defined(DC__OS_Win64)
@@ -230,9 +243,9 @@
 #if defined(DC__Arch_ARM_ARM) || defined(DC__Arch_ARM_THUMB)
 # if defined(__ARM_EABI__) || defined(DC__OS_NDS)
 #  if defined (__ARM_PCS_VFP) && (__ARM_PCS_VFP == 1)
-#    define DC__ABI_ARM_HF
+#   define DC__ABI_ARM_HF
 #  else
-#    define DC__ABI_ARM_EABI
+#   define DC__ABI_ARM_EABI
 #  endif
 # elif defined(__APCS_32__)
 #  define DC__ABI_ARM_OABI
@@ -285,12 +298,12 @@
 # elif (defined(DC__Arch_PPC64) && (DC__ABI_PPC64_ELF_V == 2)) || defined(MIPSEL) || defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__) || defined(__ARMEL__) || defined(__AARCH64EL__)
 #  define DC__Endian_LITTLE
 # elif defined(DC__Arch_Sparc64) && !defined(__BYTE_ORDER__) /* Sparc64 default is big-endian, except if explicitly defined */
-#    define DC__Endian_BIG
+#   define DC__Endian_BIG
 # elif defined(BYTE_ORDER) || defined(_BYTE_ORDER) || defined(__BYTE_ORDER__) /* explicitly set byte order, either through compiler or platform specific endian.h */
 #  if (defined(BIG_ENDIAN) && (BYTE_ORDER == BIG_ENDIAN)) ||  (defined(_BIG_ENDIAN) && (_BYTE_ORDER == _BIG_ENDIAN)) || (defined(__ORDER_BIG_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))
-#    define DC__Endian_BIG
+#   define DC__Endian_BIG
 #  elif (defined(LITTLE_ENDIAN) && (BYTE_ORDER == LITTLE_ENDIAN)) ||  (defined(_LITTLE_ENDIAN) && (_BYTE_ORDER == _LITTLE_ENDIAN)) || (defined(__ORDER_LITTLE_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
-#    define DC__Endian_LITTLE
+#   define DC__Endian_LITTLE
 #  endif
 # elif (defined(_BIG_ENDIAN) && (_BIG_ENDIAN == 1)) || (defined(__BIG_ENDIAN__) && (__BIG_ENDIAN__ == 1)) /* explicitly set as on/off */
 #  define DC__Endian_BIG
@@ -317,12 +330,12 @@
 /* syscalls */
 #if (defined(DC__Arch_Intel_x86) || (defined(DC__Arch_AMD64) && defined(DC_UNIX)) || defined(DC__Arch_PPC32) || defined(DC__Arch_PPC64)) && \
     !defined(DC__OS_MacOSX) && !defined(DC__OS_Plan9) && !defined(DC__OS_NDS) && !defined(DC__OS_PSP) && !defined(DC__OS_Minix) && !defined(DC__OS_SunOS) && !defined(DC__OS_BeOS)
-#  define DC__Feature_Syscall
+# define DC__Feature_Syscall
 #endif
 
 /* aggregate (struct, union) by value */
 #if defined(DC__Arch_AMD64)
-#  define DC__Feature_AggrByVal
+# define DC__Feature_AggrByVal
 #endif