Skip to content
Permalink
Browse files

general: Changed macros and definitions for the engine to compile wit…

…h MinGW (#793)
  • Loading branch information
Cerberus1746 authored and CFSworks committed Dec 2, 2019
1 parent 77eeed6 commit 71dfc51f8a7d9adf65347f092baf6bf13eb2debe
@@ -25,7 +25,7 @@ using std::string;
#include <sys/param.h> // for realpath
#endif // __APPLE__

#ifdef WIN32_VC
#ifdef _WIN32
// Windows requires this for getcwd().
#include <direct.h>
#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;
@@ -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
}

/**
@@ -38,7 +38,7 @@
#include <algorithm>
#include <ctype.h>

#ifndef _MSC_VER
#ifndef _WIN32
#include <dlfcn.h>
#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
@@ -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 {
@@ -31,6 +31,18 @@
#include <fcntl.h>
#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;
@@ -17,7 +17,7 @@
#include <errno.h>
#include <stdio.h>

#if defined(WIN32_VC) || defined(WIN64_VC)
#ifdef _WIN32
#include <winsock2.h>
#endif

@@ -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
@@ -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 @@ class EXPCL_PANDA_EXPRESS WindowsRegistry
static std::string format_message(int error_code);
};

#endif // WIN32_VC
#endif // _WIN32

#endif
@@ -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;

@@ -23,7 +23,7 @@
#include "trueClock.h"

#if defined(CPPPARSER)
#elif defined(WIN32_VC) || defined(WIN64_VC)
#elif defined(_WIN32)
#include <winsock2.h> // For gethostname()
#include <Iphlpapi.h> // For GetAdaptersAddresses()
#elif defined(__ANDROID__)

0 comments on commit 71dfc51

Please sign in to comment.
You can’t perform that action at this time.