From 484a4b518f6025f2cdec9eb89fdf3883eb57fc28 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 30 Jan 2022 22:44:29 +0100 Subject: Add another very awful workaround to prevent a crash on Mingw32 This appears to be the same issue as 70df3d54f37c280f7afe60f6e964b8406577f39f. Hopefully the next MinGW update will remove the need for this. --- src/serialization.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/serialization.cpp') diff --git a/src/serialization.cpp b/src/serialization.cpp index b6ce3b37f..d4d7b5f6e 100644 --- a/src/serialization.cpp +++ b/src/serialization.cpp @@ -208,11 +208,31 @@ struct ZSTD_Deleter { } }; +#if defined(__MINGW32__) && !defined(__MINGW64__) +/* + * This is exactly as dumb as it looks. + * Yes, this is a memory leak. No, we don't have better solution right now. + */ +template class leaky_ptr +{ + T *value; +public: + leaky_ptr(T *value) : value(value) {}; + T *get() { return value; } +}; +#endif + void compressZstd(const u8 *data, size_t data_size, std::ostream &os, int level) { +#if defined(__MINGW32__) && !defined(__MINGW64__) + // leaks one context per thread but doesn't crash :shrug: + thread_local leaky_ptr stream(ZSTD_createCStream()); +#else // reusing the context is recommended for performance // it will destroyed when the thread ends thread_local std::unique_ptr stream(ZSTD_createCStream()); +#endif + ZSTD_initCStream(stream.get(), level); @@ -256,9 +276,14 @@ void compressZstd(const std::string &data, std::ostream &os, int level) void decompressZstd(std::istream &is, std::ostream &os) { +#if defined(__MINGW32__) && !defined(__MINGW64__) + // leaks one context per thread but doesn't crash :shrug: + thread_local leaky_ptr stream(ZSTD_createDStream()); +#else // reusing the context is recommended for performance // it will destroyed when the thread ends thread_local std::unique_ptr stream(ZSTD_createDStream()); +#endif ZSTD_initDStream(stream.get()); -- cgit v1.2.3 From ba6fbc417ecb812345c1747f42b6606dfc8e1d5b Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 3 Feb 2022 21:35:08 +0100 Subject: Remove awful Mingw32 workarounds Instead a warning is triggered if an affected compiler is detected. closes #12022 --- src/main.cpp | 8 ++++++++ src/script/common/c_converter.cpp | 8 -------- src/serialization.cpp | 28 ++-------------------------- 3 files changed, 10 insertions(+), 34 deletions(-) (limited to 'src/serialization.cpp') diff --git a/src/main.cpp b/src/main.cpp index ca95ef874..5ea212d8a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -65,6 +65,14 @@ extern "C" { #error Minetest cannot be built without exceptions or RTTI #endif +#if defined(__MINGW32__) && !defined(__MINGW64__) && !defined(__clang__) && \ + (__GNUC__ < 11 || (__GNUC__ == 11 && __GNUC_MINOR__ < 1)) +// see e.g. https://github.com/minetest/minetest/issues/10137 +#warning ================================== +#warning 32-bit MinGW gcc before 11.1 has known issues with crashes on thread exit, you should upgrade. +#warning ================================== +#endif + #define DEBUGFILE "debug.txt" #define DEFAULT_SERVER_PORT 30000 diff --git a/src/script/common/c_converter.cpp b/src/script/common/c_converter.cpp index 716405593..08fb9ad30 100644 --- a/src/script/common/c_converter.cpp +++ b/src/script/common/c_converter.cpp @@ -452,17 +452,9 @@ size_t read_stringlist(lua_State *L, int index, std::vector *result Table field getters */ -#if defined(__MINGW32__) && !defined(__MINGW64__) -/* MinGW 32-bit somehow crashes in the std::set destructor when this - * variable is thread-local, so just don't do that. */ -static std::set warned_msgs; -#endif - bool check_field_or_nil(lua_State *L, int index, int type, const char *fieldname) { -#if !defined(__MINGW32__) || defined(__MINGW64__) thread_local std::set warned_msgs; -#endif int t = lua_type(L, index); if (t == LUA_TNIL) diff --git a/src/serialization.cpp b/src/serialization.cpp index d4d7b5f6e..d3009bc83 100644 --- a/src/serialization.cpp +++ b/src/serialization.cpp @@ -208,30 +208,11 @@ struct ZSTD_Deleter { } }; -#if defined(__MINGW32__) && !defined(__MINGW64__) -/* - * This is exactly as dumb as it looks. - * Yes, this is a memory leak. No, we don't have better solution right now. - */ -template class leaky_ptr -{ - T *value; -public: - leaky_ptr(T *value) : value(value) {}; - T *get() { return value; } -}; -#endif - void compressZstd(const u8 *data, size_t data_size, std::ostream &os, int level) { -#if defined(__MINGW32__) && !defined(__MINGW64__) - // leaks one context per thread but doesn't crash :shrug: - thread_local leaky_ptr stream(ZSTD_createCStream()); -#else // reusing the context is recommended for performance - // it will destroyed when the thread ends + // it will be destroyed when the thread ends thread_local std::unique_ptr stream(ZSTD_createCStream()); -#endif ZSTD_initCStream(stream.get(), level); @@ -276,14 +257,9 @@ void compressZstd(const std::string &data, std::ostream &os, int level) void decompressZstd(std::istream &is, std::ostream &os) { -#if defined(__MINGW32__) && !defined(__MINGW64__) - // leaks one context per thread but doesn't crash :shrug: - thread_local leaky_ptr stream(ZSTD_createDStream()); -#else // reusing the context is recommended for performance - // it will destroyed when the thread ends + // it will be destroyed when the thread ends thread_local std::unique_ptr stream(ZSTD_createDStream()); -#endif ZSTD_initDStream(stream.get()); -- cgit v1.2.3 From 5683bb76cc3a60d952c9f58c41adaa5f195dd3f4 Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Wed, 1 Dec 2021 18:30:40 -0500 Subject: Fix compiler warnings --- src/CMakeLists.txt | 6 ++++-- src/client/clientlauncher.cpp | 2 ++ src/client/shader.cpp | 10 ++++----- src/serialization.cpp | 14 ------------ src/server/player_sao.h | 48 ++++++++++++++++++++--------------------- src/terminal_chat_console.cpp | 3 ++- src/unittest/test_irrptr.cpp | 4 +++- src/unittest/test_voxelarea.cpp | 4 ++-- src/util/srp.cpp | 4 ++-- 9 files changed, 44 insertions(+), 51 deletions(-) (limited to 'src/serialization.cpp') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ac4c1de73..2de68a8f0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -470,6 +470,9 @@ endif() include_directories( ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR} + ${PROJECT_SOURCE_DIR}/script +) +include_directories(SYSTEM ${ZLIB_INCLUDE_DIR} ${ZSTD_INCLUDE_DIR} ${SQLITE3_INCLUDE_DIR} @@ -477,7 +480,6 @@ include_directories( ${GMP_INCLUDE_DIR} ${JSON_INCLUDE_DIR} ${LUA_BIT_INCLUDE_DIR} - ${PROJECT_SOURCE_DIR}/script ) if(USE_GETTEXT) @@ -485,7 +487,7 @@ if(USE_GETTEXT) endif() if(BUILD_CLIENT) - include_directories( + include_directories(SYSTEM ${FREETYPE_INCLUDE_DIRS} ${SOUND_INCLUDE_DIRS} ${X11_INCLUDE_DIR} diff --git a/src/client/clientlauncher.cpp b/src/client/clientlauncher.cpp index 063154316..54c561d11 100644 --- a/src/client/clientlauncher.cpp +++ b/src/client/clientlauncher.cpp @@ -564,6 +564,8 @@ void ClientLauncher::speed_tests() // volatile to avoid some potential compiler optimisations volatile static s16 temp16; volatile static f32 tempf; + // Silence compiler warning + (void)temp16; static v3f tempv3f1; static v3f tempv3f2; static std::string tempstring; diff --git a/src/client/shader.cpp b/src/client/shader.cpp index 1be9ef128..bbb872761 100644 --- a/src/client/shader.cpp +++ b/src/client/shader.cpp @@ -242,11 +242,6 @@ public: MainShaderConstantSetter() : m_world_view_proj("mWorldViewProj") , m_world("mWorld") -#if ENABLE_GLES - , m_world_view("mWorldView") - , m_texture("mTexture") - , m_normal("mNormal") -#endif , m_shadow_view_proj("m_ShadowViewProj") , m_light_direction("v_LightDirection") , m_texture_res("f_textureresolution") @@ -261,6 +256,11 @@ public: , m_perspective_bias1_pixel("xyPerspectiveBias1") , m_perspective_zbias_vertex("zPerspectiveBias") , m_perspective_zbias_pixel("zPerspectiveBias") +#if ENABLE_GLES + , m_world_view("mWorldView") + , m_texture("mTexture") + , m_normal("mNormal") +#endif {} ~MainShaderConstantSetter() = default; diff --git a/src/serialization.cpp b/src/serialization.cpp index d3009bc83..11164a0ed 100644 --- a/src/serialization.cpp +++ b/src/serialization.cpp @@ -108,7 +108,6 @@ void decompressZlib(std::istream &is, std::ostream &os, size_t limit) char output_buffer[bufsize]; int status = 0; int ret; - int bytes_read = 0; int bytes_written = 0; int input_buffer_len = 0; @@ -122,8 +121,6 @@ void decompressZlib(std::istream &is, std::ostream &os, size_t limit) z.avail_in = 0; - //dstream<<"initial fail="< &privs); diff --git a/src/terminal_chat_console.cpp b/src/terminal_chat_console.cpp index 9e3d33736..b12261c3b 100644 --- a/src/terminal_chat_console.cpp +++ b/src/terminal_chat_console.cpp @@ -17,6 +17,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include #include "config.h" #if USE_CURSES #include "version.h" @@ -398,7 +399,7 @@ void TerminalChatConsole::step(int ch) minutes = (float)minutes / 1000 * 60; if (m_game_time) - printw(" | Game %d Time of day %02d:%02d ", + printw(" | Game %" PRIu64 " Time of day %02d:%02d ", m_game_time, hours, minutes); // draw text diff --git a/src/unittest/test_irrptr.cpp b/src/unittest/test_irrptr.cpp index 3484f1514..2fb7cfcd6 100644 --- a/src/unittest/test_irrptr.cpp +++ b/src/unittest/test_irrptr.cpp @@ -93,7 +93,9 @@ void TestIrrPtr::testRefCounting() #if defined(__clang__) #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wself-assign-overloaded" + #if __clang_major__ >= 7 + #pragma GCC diagnostic ignored "-Wself-assign-overloaded" + #endif #pragma GCC diagnostic ignored "-Wself-move" #endif diff --git a/src/unittest/test_voxelarea.cpp b/src/unittest/test_voxelarea.cpp index 9826d2ee7..1d72650d7 100644 --- a/src/unittest/test_voxelarea.cpp +++ b/src/unittest/test_voxelarea.cpp @@ -120,7 +120,7 @@ void TestVoxelArea::test_extent() VoxelArea v1(v3s16(-1337, -547, -789), v3s16(-147, 447, 669)); UASSERT(v1.getExtent() == v3s16(1191, 995, 1459)); - VoxelArea v2(v3s16(32493, -32507, 32753), v3s16(32508, -32492, 32768)); + VoxelArea v2(v3s16(32493, -32507, 32753), v3s16(32508, -32492, -32768)); UASSERT(v2.getExtent() == v3s16(16, 16, 16)); } @@ -129,7 +129,7 @@ void TestVoxelArea::test_volume() VoxelArea v1(v3s16(-1337, -547, -789), v3s16(-147, 447, 669)); UASSERTEQ(s32, v1.getVolume(), 1728980655); - VoxelArea v2(v3s16(32493, -32507, 32753), v3s16(32508, -32492, 32768)); + VoxelArea v2(v3s16(32493, -32507, 32753), v3s16(32508, -32492, -32768)); UASSERTEQ(s32, v2.getVolume(), 4096); } diff --git a/src/util/srp.cpp b/src/util/srp.cpp index ceb2fef9e..daa7f332b 100644 --- a/src/util/srp.cpp +++ b/src/util/srp.cpp @@ -354,7 +354,7 @@ static size_t hash_length(SRP_HashAlgorithm alg) case SRP_SHA384: return SHA384_DIGEST_LENGTH; case SRP_SHA512: return SHA512_DIGEST_LENGTH; */ - default: return -1; + default: return 0; }; } // clang-format on @@ -422,7 +422,7 @@ static SRP_Result H_nn( } static SRP_Result H_ns(mpz_t result, SRP_HashAlgorithm alg, const unsigned char *n, - size_t len_n, const unsigned char *bytes, uint32_t len_bytes) + size_t len_n, const unsigned char *bytes, size_t len_bytes) { unsigned char buff[SHA512_DIGEST_LENGTH]; size_t nbytes = len_n + len_bytes; -- cgit v1.2.3