From 71dfc51f8a7d9adf65347f092baf6bf13eb2debe Mon Sep 17 00:00:00 2001 From: Leandro Benedet Garcia Date: Mon, 2 Dec 2019 13:21:01 -0300 Subject: [PATCH] general: Changed macros and definitions for the engine to compile with MinGW (#793) --- dtool/src/dtoolutil/executionEnvironment.cxx | 6 ++--- dtool/src/dtoolutil/filename.cxx | 24 ++++++++++---------- dtool/src/prc/configPageManager.cxx | 6 ++--- panda/src/device/xInputDevice.cxx | 4 ++++ panda/src/downloader/bioPtr.cxx | 13 +++++++++++ panda/src/express/error_utils.cxx | 2 +- panda/src/express/windowsRegistry.cxx | 2 +- panda/src/express/windowsRegistry.h | 4 ++-- panda/src/nativenet/socket_address.cxx | 10 ++++++++ panda/src/net/connectionManager.cxx | 2 +- 10 files changed, 50 insertions(+), 23 deletions(-) diff --git a/dtool/src/dtoolutil/executionEnvironment.cxx b/dtool/src/dtoolutil/executionEnvironment.cxx index 79d4a07e04..4a10c9d168 100644 --- a/dtool/src/dtoolutil/executionEnvironment.cxx +++ b/dtool/src/dtoolutil/executionEnvironment.cxx @@ -25,7 +25,7 @@ using std::string; #include // for realpath #endif // __APPLE__ -#ifdef WIN32_VC +#ifdef _WIN32 // Windows requires this for getcwd(). #include #define getcwd _getcwd @@ -80,7 +80,7 @@ extern char **environ; // GLOBAL_ARGCGLOBAL_ARGV that we can read at static init time to determine // our command-line arguments. -#if !defined(WIN32_VC) && defined(HAVE_GLOBAL_ARGV) && defined(PROTOTYPE_GLOBAL_ARGV) +#if !defined(_WIN32) && defined(HAVE_GLOBAL_ARGV) && defined(PROTOTYPE_GLOBAL_ARGV) extern char **GLOBAL_ARGV; extern int GLOBAL_ARGC; #endif @@ -200,7 +200,7 @@ expand_string(const string &str) { */ Filename ExecutionEnvironment:: get_cwd() { -#ifdef WIN32_VC +#ifdef _WIN32 // getcwd() requires us to allocate a dynamic buffer and grow it on demand. static size_t bufsize = 1024; static wchar_t *buffer = nullptr; diff --git a/dtool/src/dtoolutil/filename.cxx b/dtool/src/dtoolutil/filename.cxx index da5657dd9d..ba1db02198 100644 --- a/dtool/src/dtoolutil/filename.cxx +++ b/dtool/src/dtoolutil/filename.cxx @@ -2507,25 +2507,25 @@ make_dir() const { size_t slash = dirname.find('/'); while (slash != string::npos) { Filename component(dirname.substr(0, slash)); -#ifdef WIN32_VC +#ifdef _WIN32 wstring os_specific = component.to_os_specific_w(); _wmkdir(os_specific.c_str()); #else string os_specific = component.to_os_specific(); ::mkdir(os_specific.c_str(), 0777); -#endif // WIN32_VC +#endif // _WIN32 slash = dirname.find('/', slash + 1); } // Now make the last one, and check the return value. Filename component(dirname); -#ifdef WIN32_VC +#ifdef _WIN32 wstring os_specific = component.to_os_specific_w(); int result = _wmkdir(os_specific.c_str()); #else string os_specific = component.to_os_specific(); int result = ::mkdir(os_specific.c_str(), 0777); -#endif // WIN32_VC +#endif // _WIN32 return (result == 0); } @@ -2538,13 +2538,13 @@ make_dir() const { */ bool Filename:: mkdir() const { -#ifdef WIN32_VC +#ifdef _WIN32 wstring os_specific = to_os_specific_w(); int result = _wmkdir(os_specific.c_str()); #else string os_specific = to_os_specific(); int result = ::mkdir(os_specific.c_str(), 0777); -#endif // WIN32_VC +#endif // _WIN32 return (result == 0); } @@ -2642,7 +2642,7 @@ bool Filename:: atomic_compare_and_exchange_contents(string &orig_contents, const string &old_contents, const string &new_contents) const { -#ifdef WIN32_VC +#ifdef _WIN32 wstring os_specific = to_os_specific_w(); HANDLE hfile = CreateFileW(os_specific.c_str(), GENERIC_READ | GENERIC_WRITE, 0, nullptr, OPEN_ALWAYS, @@ -2708,7 +2708,7 @@ atomic_compare_and_exchange_contents(string &orig_contents, CloseHandle(hfile); return match; -#else // WIN32_VC +#else // _WIN32 string os_specific = to_os_specific(); int fd = open(os_specific.c_str(), O_RDWR | O_CREAT, 0666); if (fd < 0) { @@ -2761,7 +2761,7 @@ atomic_compare_and_exchange_contents(string &orig_contents, } return match; -#endif // WIN32_VC +#endif // _WIN32 } /** @@ -2778,7 +2778,7 @@ atomic_compare_and_exchange_contents(string &orig_contents, */ bool Filename:: atomic_read_contents(string &contents) const { -#ifdef WIN32_VC +#ifdef _WIN32 wstring os_specific = to_os_specific_w(); HANDLE hfile = CreateFileW(os_specific.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_ALWAYS, @@ -2824,7 +2824,7 @@ atomic_read_contents(string &contents) const { CloseHandle(hfile); return true; -#else // WIN32_VC +#else // _WIN32 string os_specific = to_os_specific(); int fd = open(os_specific.c_str(), O_RDWR | O_CREAT, 0666); if (fd < 0) { @@ -2861,7 +2861,7 @@ atomic_read_contents(string &contents) const { close(fd); return true; -#endif // WIN32_VC +#endif // _WIN32 } /** diff --git a/dtool/src/prc/configPageManager.cxx b/dtool/src/prc/configPageManager.cxx index b26eb17c69..737d25026b 100644 --- a/dtool/src/prc/configPageManager.cxx +++ b/dtool/src/prc/configPageManager.cxx @@ -38,7 +38,7 @@ #include #include -#ifndef _MSC_VER +#ifndef _WIN32 #include #endif @@ -120,7 +120,7 @@ reload_implicit_pages() { const char *main_dir; const char *log_filename; }; -#ifdef _MSC_VER +#ifdef _WIN32 const BlobInfo *blobinfo = (const BlobInfo *)GetProcAddress(GetModuleHandle(NULL), "blobinfo"); #elif defined(RTLD_MAIN_ONLY) const BlobInfo *blobinfo = (const BlobInfo *)dlsym(RTLD_MAIN_ONLY, "blobinfo"); @@ -130,7 +130,7 @@ reload_implicit_pages() { const BlobInfo *blobinfo = (const BlobInfo *)dlsym(dlopen(NULL, RTLD_NOW), "blobinfo"); #endif if (blobinfo == nullptr) { -#ifndef _MSC_VER +#ifndef _WIN32 // Clear the error flag. dlerror(); #endif diff --git a/panda/src/device/xInputDevice.cxx b/panda/src/device/xInputDevice.cxx index b86a5cd90b..74783f8751 100644 --- a/panda/src/device/xInputDevice.cxx +++ b/panda/src/device/xInputDevice.cxx @@ -68,10 +68,14 @@ #define BATTERY_LEVEL_FULL 0x03 #endif +// With MingW32 this raises the error: +// Redefinition of '_XINPUT_BATTERY_INFORMATION' +#ifdef _MSC_VER typedef struct _XINPUT_BATTERY_INFORMATION { BYTE BatteryType; BYTE BatteryLevel; } XINPUT_BATTERY_INFORMATION; +#endif // Undocumented, I figured out how this looks by trial and error. typedef struct _XINPUT_BUSINFO { diff --git a/panda/src/downloader/bioPtr.cxx b/panda/src/downloader/bioPtr.cxx index 56a288987b..2b9adf4366 100644 --- a/panda/src/downloader/bioPtr.cxx +++ b/panda/src/downloader/bioPtr.cxx @@ -31,6 +31,18 @@ #include #endif +// For some reason in msys those two macros are not defined correctly in the +// header file ws2tcpip.h +// Also, those lines will be removed when the engine change +// _WIN32_WINNT to 0x0600 +#ifndef AI_ADDRCONFIG +#define AI_ADDRCONFIG 0x00000400 +#endif + +#ifndef AI_V4MAPPED +#define AI_V4MAPPED 0x00000800 +#endif + using std::string; #ifdef _WIN32 @@ -95,6 +107,7 @@ BioPtr(const URLSpec &url) : _connecting(false) { // These hints tell getaddrinfo what kind of address to return. struct addrinfo hints, *res = nullptr; memset(&hints, 0, sizeof(hints)); + hints.ai_flags = AI_V4MAPPED | AI_ADDRCONFIG; hints.ai_family = support_ipv6 ? AF_UNSPEC : AF_INET; hints.ai_socktype = SOCK_STREAM; diff --git a/panda/src/express/error_utils.cxx b/panda/src/express/error_utils.cxx index 8509856f18..0ede902fbf 100644 --- a/panda/src/express/error_utils.cxx +++ b/panda/src/express/error_utils.cxx @@ -17,7 +17,7 @@ #include #include -#if defined(WIN32_VC) || defined(WIN64_VC) +#ifdef _WIN32 #include #endif diff --git a/panda/src/express/windowsRegistry.cxx b/panda/src/express/windowsRegistry.cxx index b96091c299..4461f1694a 100644 --- a/panda/src/express/windowsRegistry.cxx +++ b/panda/src/express/windowsRegistry.cxx @@ -15,7 +15,7 @@ #include "config_express.h" #include "textEncoder.h" -#if defined(WIN32_VC) +#if defined(_WIN32) #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN 1 #endif diff --git a/panda/src/express/windowsRegistry.h b/panda/src/express/windowsRegistry.h index c402eed2ab..9176f940a4 100644 --- a/panda/src/express/windowsRegistry.h +++ b/panda/src/express/windowsRegistry.h @@ -17,7 +17,7 @@ #include "pandabase.h" // This class is only defined on Windows builds. -#ifdef WIN32_VC +#ifdef _WIN32 /** * This class provides a hook to Python to read and write strings and integers @@ -56,6 +56,6 @@ private: static std::string format_message(int error_code); }; -#endif // WIN32_VC +#endif // _WIN32 #endif diff --git a/panda/src/nativenet/socket_address.cxx b/panda/src/nativenet/socket_address.cxx index 3b8c19d3dd..e92310ce7f 100644 --- a/panda/src/nativenet/socket_address.cxx +++ b/panda/src/nativenet/socket_address.cxx @@ -14,6 +14,14 @@ #include "socket_address.h" #include "config_downloader.h" +// For some reason in msys those two macros are not defined correctly in the +// header file ws2tcpip.h +// Also, those lines will be removed when the engine change +// _WIN32_WINNT to 0x0600 +#ifndef AI_ADDRCONFIG +#define AI_ADDRCONFIG 0x00000400 +#endif + /** * This function will take a port and string-based TCP address and initialize * the address with this information. Returns true on success; on failure, it @@ -28,6 +36,8 @@ set_host(const std::string &hostname, unsigned short port) { struct addrinfo hints, *res = nullptr; memset(&hints, 0, sizeof(hints)); + + hints.ai_flags = AI_ADDRCONFIG; hints.ai_family = support_ipv6 ? AF_UNSPEC : AF_INET; diff --git a/panda/src/net/connectionManager.cxx b/panda/src/net/connectionManager.cxx index f125356f50..6ad6063a8b 100644 --- a/panda/src/net/connectionManager.cxx +++ b/panda/src/net/connectionManager.cxx @@ -23,7 +23,7 @@ #include "trueClock.h" #if defined(CPPPARSER) -#elif defined(WIN32_VC) || defined(WIN64_VC) +#elif defined(_WIN32) #include // For gethostname() #include // For GetAdaptersAddresses() #elif defined(__ANDROID__)