From 1acb81e11cdf8b8ff33418b15a961f79ac845828 Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Wed, 16 Aug 2023 14:09:34 +0200 Subject: [PATCH] Build fixes: - Fixed build error, which was previously introduced by commit c8ca89112e93957bf405a297b5ed6beda84acb69 - Treat warnings as errors --- CMakeLists.txt | 9 +++++++-- external/zlib/CMakeLists.txt | 3 +++ include/ma_global.h | 1 + libmariadb/ma_default.c | 2 ++ libmariadb/mariadb_rpl.c | 5 +++-- unittest/libmariadb/ma_getopt.h | 6 +----- unittest/libmariadb/my_test.h | 1 + unittest/libmariadb/rpl_api.c | 6 +++--- 8 files changed, 21 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index eb034add1..1fc58eb8f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,8 +99,6 @@ IF(MSVC) INCLUDE(${CC_SOURCE_DIR}/cmake/WindowsCache.cmake) ADD_DEFINITIONS(-DWIN32_LEAN_AND_MEAN -DNOGDI) IF (MSVC) - # Treat warnings as errors - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -WX") SET(CONFIG_TYPES "DEBUG" "RELEASE" "RELWITHDEBINFO") FOREACH(BUILD_TYPE ${CONFIG_TYPES}) FOREACH(COMPILER CXX C) @@ -144,6 +142,13 @@ IF(CMAKE_COMPILER_IS_GNUCC) ENDFOREACH() ENDIF() +IF (CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID MATCHES "GNU") + SET(WARNING_AS_ERROR "-Werror" CACHE INTERNAL "WARNING_AS_ERROR") +ELSEIF(CMAKE_C_COMPILER_ID MATCHES "MSVC") + SET(WARNING_AS_ERROR "/WX" CACHE INTERNAL "WARNING_AS_ERROR") +ENDIF() +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_AS_ERROR}") + # If the build type isn't specified, set to Relwithdebinfo as default. IF(NOT CMAKE_BUILD_TYPE) SET(CMAKE_BUILD_TYPE "RelWithDebInfo") diff --git a/external/zlib/CMakeLists.txt b/external/zlib/CMakeLists.txt index e92ad4e00..c6dbc97c4 100644 --- a/external/zlib/CMakeLists.txt +++ b/external/zlib/CMakeLists.txt @@ -5,6 +5,9 @@ project(zlib C) set(VERSION "1.2.13") +# Don't treat warnings as error for zlib +STRING(REPLACE ${WARNING_AS_ERROR} "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS}) + set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables") set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries") set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers") diff --git a/include/ma_global.h b/include/ma_global.h index 05e2918f7..6d1c6f65a 100644 --- a/include/ma_global.h +++ b/include/ma_global.h @@ -27,6 +27,7 @@ #include #define strcasecmp _stricmp #define strtok_r strtok_s +#define strdup _strdup #define sleep(x) Sleep(1000*(x)) #ifdef _MSC_VER #define inline __inline diff --git a/libmariadb/ma_default.c b/libmariadb/ma_default.c index a3eb2119e..0f6921c19 100644 --- a/libmariadb/ma_default.c +++ b/libmariadb/ma_default.c @@ -29,6 +29,8 @@ #include #include "shlwapi.h" +#define access _access + static const char *ini_exts[]= {"ini", "cnf", 0}; #define R_OK 4 #else diff --git a/libmariadb/mariadb_rpl.c b/libmariadb/mariadb_rpl.c index 4ebd3b2a6..d6fe8db57 100644 --- a/libmariadb/mariadb_rpl.c +++ b/libmariadb/mariadb_rpl.c @@ -962,7 +962,7 @@ static uint8_t mariadb_rpl_send_semisync_ack(MARIADB_RPL* rpl, MARIADB_RPL_EVENT rpl_set_error(rpl, CR_BINLOG_SEMI_SYNC_ERROR, 0, "semi synchronous replication is not enabled"); return 1; } - if (!event->is_semi_sync || !event->semi_sync_flags != SEMI_SYNC_ACK_REQ) + if (!event->is_semi_sync || (event->semi_sync_flags != SEMI_SYNC_ACK_REQ)) { rpl_set_error(rpl, CR_BINLOG_SEMI_SYNC_ERROR, 0, "This event doesn't require to send semi synchronous acknoledgement"); return 1; @@ -972,7 +972,7 @@ static uint8_t mariadb_rpl_send_semisync_ack(MARIADB_RPL* rpl, MARIADB_RPL_EVENT buf = alloca(buf_size); buf[0] = SEMI_SYNC_INDICATOR; - int8store(buf + 1, event->next_event_pos); + int8store(buf + 1, (uint64_t)event->next_event_pos); memcpy(buf + 9, rpl->filename, rpl->filename_length); ma_net_clear(&rpl->mysql->net); @@ -2084,6 +2084,7 @@ int STDCALL mariadb_rpl_get_optionsv(MARIADB_RPL *rpl, { unsigned int* semi_sync = va_arg(ap, unsigned int*); *semi_sync = rpl->is_semi_sync; + break; } default: diff --git a/unittest/libmariadb/ma_getopt.h b/unittest/libmariadb/ma_getopt.h index 790915b97..e169e8299 100644 --- a/unittest/libmariadb/ma_getopt.h +++ b/unittest/libmariadb/ma_getopt.h @@ -121,11 +121,7 @@ extern int _getopt_internal (int argc, char *const *argv, const struct option *longopts, int *longind, int long_only); #else /* not __STDC__ */ -extern int getopt (); -extern int getopt_long (); -extern int getopt_long_only (); - -extern int _getopt_internal (); +extern int getopt (int argc, char *const *argv, const char *optstring); #endif /* __STDC__ */ #ifdef __cplusplus diff --git a/unittest/libmariadb/my_test.h b/unittest/libmariadb/my_test.h index b4102f92e..a33847471 100644 --- a/unittest/libmariadb/my_test.h +++ b/unittest/libmariadb/my_test.h @@ -38,6 +38,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #else #include +#define unlink _unlink #endif #ifndef OK diff --git a/unittest/libmariadb/rpl_api.c b/unittest/libmariadb/rpl_api.c index dcf6f7a7b..f65a2915b 100644 --- a/unittest/libmariadb/rpl_api.c +++ b/unittest/libmariadb/rpl_api.c @@ -342,9 +342,9 @@ static int test_conc592(MYSQL *my __attribute__((unused))) } struct my_tests_st my_tests[] = { - // {"test_conc592", test_conc592, TEST_CONNECTION_NEW, 0, NULL, NULL}, - //{"test_rpl_async", test_rpl_async, TEST_CONNECTION_NEW, 0, NULL, NULL}, - //{"test_rpl_semisync", test_rpl_semisync, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_conc592", test_conc592, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_rpl_async", test_rpl_async, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"test_rpl_semisync", test_rpl_semisync, TEST_CONNECTION_NEW, 0, NULL, NULL}, {"test_conc467", test_conc467, TEST_CONNECTION_NEW, 0, NULL, NULL}, {NULL, NULL, 0, 0, NULL, NULL} };