Guess who joined the fuccboi club with g++ and VC++? THAT'S RIGHT, IT'S MINGW AND IT'S HANDY DANDY FRIEND, LIBSTDC++! WOOOOOO!

This commit is contained in:
ThePhD 2016-08-12 15:57:53 -04:00
parent 0d1d5ebd09
commit f608c4f0f8
4 changed files with 24 additions and 16 deletions

View File

@ -24,10 +24,10 @@
#include <lua.hpp> #include <lua.hpp>
#if defined(_WIN32) || defined(_MSC_VER) #if defined(_WIN32) || defined(_MSC_VER) || defined(__MINGW32__)
#ifndef SOL_CODECVT_SUPPORT #ifndef SOL_CODECVT_SUPPORT
#define SOL_CODECVT_SUPPORT 1 #define SOL_CODECVT_SUPPORT 1
#endif // codecvt support #endif // sol codecvt support
#elif defined(__GNUC__) #elif defined(__GNUC__)
#if __GNUC__ >= 5 #if __GNUC__ >= 5
#ifndef SOL_CODECVT_SUPPORT #ifndef SOL_CODECVT_SUPPORT

View File

@ -191,14 +191,17 @@ namespace sol {
if (sizeof(wchar_t) == 2) { if (sizeof(wchar_t) == 2) {
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> convert; std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> convert;
std::wstring r = convert.from_bytes(str, str + len); std::wstring r = convert.from_bytes(str, str + len);
#ifdef __MINGW32__
// Fuck you, MinGW, and fuck you libstdc++ for introducing this absolutely asinine bug
// https://sourceforge.net/p/mingw-w64/bugs/538/
// http://chat.stackoverflow.com/transcript/message/32271369#32271369
for (auto& c : r) {
uint8_t* b = reinterpret_cast<uint8_t*>(&c);
std::swap(b[0], b[1]);
}
#endif
return r; return r;
} }
else if (sizeof(wchar_t) == 4) {
std::wstring_convert<std::codecvt_utf8<wchar_t>> convert;
std::wstring r = convert.from_bytes(str, str + len);
return r;
}
// ... Uh, what the fuck do I even do here?
std::wstring_convert<std::codecvt_utf8<wchar_t>> convert; std::wstring_convert<std::codecvt_utf8<wchar_t>> convert;
std::wstring r = convert.from_bytes(str, str + len); std::wstring r = convert.from_bytes(str, str + len);
return r; return r;
@ -270,7 +273,7 @@ namespace sol {
return str.size() > 0 ? str[0] : '\0'; return str.size() > 0 ? str[0] : '\0';
} }
}; };
#endif // codecvt Header Support #endif // codecvt header support
template<> template<>
struct getter<meta_function> { struct getter<meta_function> {

View File

@ -420,11 +420,6 @@ namespace sol {
std::string u8str = convert.to_bytes(strb, stre); std::string u8str = convert.to_bytes(strb, stre);
return stack::push(L, u8str); return stack::push(L, u8str);
} }
else if (sizeof(wchar_t) == 4) {
std::wstring_convert<std::codecvt_utf8<wchar_t>> convert;
std::string u8str = convert.to_bytes(strb, stre);
return stack::push(L, u8str);
}
std::wstring_convert<std::codecvt_utf8<wchar_t>> convert; std::wstring_convert<std::codecvt_utf8<wchar_t>> convert;
std::string u8str = convert.to_bytes(strb, stre); std::string u8str = convert.to_bytes(strb, stre);
return stack::push(L, u8str); return stack::push(L, u8str);
@ -564,7 +559,7 @@ namespace sol {
return stack::push(L, u32str.data(), u32str.data() + sz); return stack::push(L, u32str.data(), u32str.data() + sz);
} }
}; };
#endif // Codecvt Header Support #endif // codecvt Header Support
template<typename... Args> template<typename... Args>
struct pusher<std::tuple<Args...>> { struct pusher<std::tuple<Args...>> {

View File

@ -3,6 +3,8 @@
#include <catch.hpp> #include <catch.hpp>
#include <sol.hpp> #include <sol.hpp>
#include <iostream>
struct test {}; struct test {};
template <typename T> template <typename T>
struct test_t {}; struct test_t {};
@ -23,8 +25,10 @@ TEST_CASE("stack/strings", "test that strings can be roundtripped") {
static const char16_t utf16str[] = { 0xD83C, 0xDF4C, 0x20, 0x6665, 0x20, 0x46, 0x6F, 0x6F, 0x20, 0xA9, 0x20, 0x62, 0x61, 0x72, 0x20, 0xD834, 0xDF06, 0x20, 0x62, 0x61, 0x7A, 0x20, 0x2603, 0x20, 0x71, 0x75, 0x78, 0x00 }; static const char16_t utf16str[] = { 0xD83C, 0xDF4C, 0x20, 0x6665, 0x20, 0x46, 0x6F, 0x6F, 0x20, 0xA9, 0x20, 0x62, 0x61, 0x72, 0x20, 0xD834, 0xDF06, 0x20, 0x62, 0x61, 0x7A, 0x20, 0x2603, 0x20, 0x71, 0x75, 0x78, 0x00 };
static const char32_t utf32str[] = { 0x1F34C, 0x0020, 0x6665, 0x0020, 0x0046, 0x006F, 0x006F, 0x0020, 0x00A9, 0x0020, 0x0062, 0x0061, 0x0072, 0x0020, 0x1D306, 0x0020, 0x0062, 0x0061, 0x007A, 0x0020, 0x2603, 0x0020, 0x0071, 0x0075, 0x0078, 0x00 }; static const char32_t utf32str[] = { 0x1F34C, 0x0020, 0x6665, 0x0020, 0x0046, 0x006F, 0x006F, 0x0020, 0x00A9, 0x0020, 0x0062, 0x0061, 0x0072, 0x0020, 0x1D306, 0x0020, 0x0062, 0x0061, 0x007A, 0x0020, 0x2603, 0x0020, 0x0071, 0x0075, 0x0078, 0x00 };
#ifdef _WIN32 #ifdef _WIN32
std::cout << "win32 widestr" << std::endl;
static const wchar_t widestr[] = { 0xD83C, 0xDF4C, 0x20, 0x6665, 0x20, 0x46, 0x6F, 0x6F, 0x20, 0xA9, 0x20, 0x62, 0x61, 0x72, 0x20, 0xD834, 0xDF06, 0x20, 0x62, 0x61, 0x7A, 0x20, 0x2603, 0x20, 0x71, 0x75, 0x78, 0x00 }; static const wchar_t widestr[] = { 0xD83C, 0xDF4C, 0x20, 0x6665, 0x20, 0x46, 0x6F, 0x6F, 0x20, 0xA9, 0x20, 0x62, 0x61, 0x72, 0x20, 0xD834, 0xDF06, 0x20, 0x62, 0x61, 0x7A, 0x20, 0x2603, 0x20, 0x71, 0x75, 0x78, 0x00 };
#else #else
std::cout << "non-windows widestr" << std::endl;
static const wchar_t widestr[] = { 0x1F34C, 0x0020, 0x6665, 0x0020, 0x0046, 0x006F, 0x006F, 0x0020, 0x00A9, 0x0020, 0x0062, 0x0061, 0x0072, 0x0020, 0x1D306, 0x0020, 0x0062, 0x0061, 0x007A, 0x0020, 0x2603, 0x0020, 0x0071, 0x0075, 0x0078, 0x00 }; static const wchar_t widestr[] = { 0x1F34C, 0x0020, 0x6665, 0x0020, 0x0046, 0x006F, 0x006F, 0x0020, 0x00A9, 0x0020, 0x0062, 0x0061, 0x0072, 0x0020, 0x1D306, 0x0020, 0x0062, 0x0061, 0x007A, 0x0020, 0x2603, 0x0020, 0x0071, 0x0075, 0x0078, 0x00 };
#endif #endif
static const std::string utf8str_s = utf8str; static const std::string utf8str_s = utf8str;
@ -33,6 +37,12 @@ TEST_CASE("stack/strings", "test that strings can be roundtripped") {
static const std::wstring widestr_s = widestr; static const std::wstring widestr_s = widestr;
#ifdef SOL_CODECVT_SUPPORT #ifdef SOL_CODECVT_SUPPORT
std::cout << "sizeof(wchar_t): " << sizeof(wchar_t) << std::endl;
std::cout << "sizeof(char16_t): " << sizeof(char16_t) << std::endl;
std::cout << "sizeof(char32_t): " << sizeof(char32_t) << std::endl;
std::cout << "utf8str: " << utf8str << std::endl;
std::cout << "utf8str_s: " << utf8str_s << std::endl;
lua["utf8"] = utf8str; lua["utf8"] = utf8str;
lua["utf16"] = utf16str; lua["utf16"] = utf16str;
lua["utf32"] = utf32str; lua["utf32"] = utf32str;
@ -47,7 +57,7 @@ TEST_CASE("stack/strings", "test that strings can be roundtripped") {
REQUIRE(utf16_to_utf8 == utf8str_s); REQUIRE(utf16_to_utf8 == utf8str_s);
REQUIRE(utf32_to_utf8 == utf8str_s); REQUIRE(utf32_to_utf8 == utf8str_s);
REQUIRE(wide_to_utf8 == utf8str_s); REQUIRE(wide_to_utf8 == utf8str_s);
std::wstring utf8_to_wide = lua["utf8"]; std::wstring utf8_to_wide = lua["utf8"];
std::wstring utf16_to_wide = lua["utf16"]; std::wstring utf16_to_wide = lua["utf16"];
std::wstring utf32_to_wide = lua["utf32"]; std::wstring utf32_to_wide = lua["utf32"];