Skip to content

Commit

Permalink
Fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
szmyd committed Oct 4, 2023
1 parent ad3a16f commit 7ba33ac
Show file tree
Hide file tree
Showing 12 changed files with 156 additions and 21 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.10)
project(nuraft_mesg)
enable_testing()

include (cmake/Flags.cmake)

set(CMAKE_CXX_STANDARD 20)

if(EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
Expand Down
130 changes: 130 additions & 0 deletions cmake/Flags.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
####################################################################################################################################
# add_flags(Flags <Languages> <Configurations>)
#
# The Flags argument contains the flag(s) to add
#
# The <Languages> argument contains the languages the flag(s) apply to; the default is "C CXX".
#
# The <Configurations> argument contains the configurations to add the flag(s) to; the default is just the global flags. If
# specific configuration(s) are given then it is written to those only and not the global default
function(add_flags Flags)
set(options)
set(oneValueArgs Languages Configurations)
set(multiValueArgs)
cmake_parse_arguments(add_flags "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

if(NOT Flags)
message(ERROR "Add Flags: Flags cannot be empty.")
endif()

#set default languages and convert to list
if(NOT add_flags_Languages)
set(add_flags_Languages "C CXX")
endif()
separate_arguments(languages UNIX_COMMAND "${add_flags_Languages}")

#set default configurations and convert to list
if(NOT add_flags_Configurations)
else()
separate_arguments(configurations UNIX_COMMAND "${add_flags_Configurations}")
endif()

if(DEBUG_CMAKE)
message(STATUS "Add Flags:")
message(STATUS "Flags - ${Flags}")
message(STATUS "Languages - ${add_flags_Languages}")
if(DEFINED configurations)
message(STATUS "Configurations - ${add_flags_Configurations}")
else()
message(STATUS "Configurations - Global")
endif()
endif()

foreach(language ${languages})
string(TOUPPER "${language}" upper_language)
if(DEFINED configurations)
foreach(configuration ${configurations})
string(TOUPPER "${configuration}" upper_configuration)
if(NOT CMAKE_${upper_language}_FLAGS_${upper_configuration})
string(STRIP "${Flags}" CMAKE_MODIFIED_FLAGS)
else()
set(CMAKE_MODIFIED_FLAGS "${CMAKE_${upper_language}_FLAGS_${upper_configuration}} ${Flags}")
endif()
string(STRIP "${CMAKE_MODIFIED_FLAGS}" CMAKE_MODIFIED_FLAGS)
string(REGEX REPLACE "[ ]+" " " CMAKE_MODIFIED_FLAGS "${CMAKE_MODIFIED_FLAGS}")
set(CMAKE_${upper_language}_FLAGS_${upper_configuration} "${CMAKE_MODIFIED_FLAGS}" PARENT_SCOPE)
endforeach()
else()
if(NOT CMAKE_${upper_language}_FLAGS)
string(STRIP "${Flags}" CMAKE_MODIFIED_FLAGS)
else()
set(CMAKE_MODIFIED_FLAGS "${CMAKE_${upper_language}_FLAGS} ${Flags}")
endif()
string(STRIP "${CMAKE_MODIFIED_FLAGS}" CMAKE_MODIFIED_FLAGS)
string(REGEX REPLACE "[ ]+" " " CMAKE_MODIFIED_FLAGS "${CMAKE_MODIFIED_FLAGS}")
set(CMAKE_${upper_language}_FLAGS "${CMAKE_MODIFIED_FLAGS}" PARENT_SCOPE)
endif()
endforeach()
endfunction(add_flags)

####################################################################################################################################
# remove_flag(Flag <Languages> <Configurations>)
#
# The Flag argument contains the regex of the flag to remove
#
# The <Languages> argument contains the languages the flag(s) apply to; the default is "C CXX".
#
# The <Configurations> argument contains the configurations to remove the flag(s) from; the default is the global flags and the
# individual build configuration flags of "Debug, Release, ReleaseWithDebInfo, MinSizedRelease". If specific configuration(s) are
# given then it is removed from the those only and the global.
function(remove_flag Flag)
set(options)
set(oneValueArgs Languages Configurations)
set(multiValueArgs)
cmake_parse_arguments(remove_flag "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

if(NOT Flag)
message(ERROR "Remove Flag: Flag cannot be empty.")
endif()

#set default languages and convert to list
if(NOT remove_flag_Languages)
set(remove_flag_Languages "C CXX")
endif()
separate_arguments(languages UNIX_COMMAND "${remove_flag_Languages}")

#set default configurations and convert to list
if(NOT remove_flag_Configurations)
set(remove_flag_Configurations "Debug Release RelWithDebInfo MinSizedRelease")
endif()
separate_arguments(configurations UNIX_COMMAND "${remove_flag_Configurations}")

if(DEBUG_CMAKE)
message(STATUS "Remove Flag:")
message(STATUS "Flag - ${Flag}")
message(STATUS "Languages - ${remove_flag_Languages}")
message(STATUS "Configurations - ${remove_flag_Configurations}")
endif()

foreach(language ${languages})
string(TOUPPER "${language}" upper_language)
# remove from configurations
foreach(configuration ${configurations})
string(TOUPPER "${configuration}" upper_configuration)
if(CMAKE_${upper_language}_FLAGS_${upper_configuration})
string(REGEX REPLACE "${Flag}" "" CMAKE_MODIFIED_FLAGS "${CMAKE_${upper_language}_FLAGS_${upper_configuration}}")
string(STRIP "${CMAKE_MODIFIED_FLAGS}" CMAKE_MODIFIED_FLAGS)
string(REGEX REPLACE "[ ]+" " " CMAKE_MODIFIED_FLAGS "${CMAKE_MODIFIED_FLAGS}")
set(CMAKE_${upper_language}_FLAGS_${upper_configuration} "${CMAKE_MODIFIED_FLAGS}" PARENT_SCOPE)
endif()
endforeach()

#remove from global
if(CMAKE_${upper_language}_FLAGS)
string(REGEX REPLACE "${Flag}" "" CMAKE_MODIFIED_GLOBAL_FLAGS "${CMAKE_${upper_language}_FLAGS}")
string(STRIP "${CMAKE_MODIFIED_GLOBAL_FLAGS}" CMAKE_MODIFIED_GLOBAL_FLAGS)
string(REGEX REPLACE "[ ]+" " " CMAKE_MODIFIED_FLAGS "${CMAKE_MODIFIED_FLAGS}")
set(CMAKE_${upper_language}_FLAGS "${CMAKE_MODIFIED_GLOBAL_FLAGS}" PARENT_SCOPE)
endif()
endforeach()
endfunction(remove_flag)
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ include(${sisl_INCLUDE_DIRS}/../cmake/settings_gen.cmake)

add_subdirectory (proto)

add_flags("-Wall -Wextra -Werror -Wpedantic")

add_library(${PROJECT_NAME})
target_sources(${PROJECT_NAME} PRIVATE
lib/grpc_client.cpp
Expand Down
2 changes: 1 addition & 1 deletion src/lib/grpc_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ inline std::shared_ptr< nuraft::resp_msg > toResponse(RaftMessage const& raft_ms
std::atomic_uint64_t grpc_base_client::_client_counter = 0ul;

void grpc_base_client::send(std::shared_ptr< nuraft::req_msg >& req, nuraft::rpc_handler& complete,
uint64_t timeout_ms) {
uint64_t) {
assert(req && complete);
RaftMessage grpc_request;
grpc_request.set_allocated_base(fromBaseRequest(*req));
Expand Down
2 changes: 1 addition & 1 deletion src/lib/grpc_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ grpc_factory::grpc_factory(int const cli_thread_count, std::string const& name)
}

class grpc_error_client : public grpc_base_client {
void send(RaftMessage const& message, handle_resp complete) override {
void send(RaftMessage const&, handle_resp complete) override {
auto null_msg = RaftMessage();
auto status = ::grpc::Status(::grpc::ABORTED, "Bad connection");
complete(null_msg, status);
Expand Down
13 changes: 5 additions & 8 deletions src/lib/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,21 @@ class nuraft_mesg_logger : public ::nuraft::logger {
[[fallthrough]];
case 2: {
LOGERRORMOD(nuraft, "{}", mesg);
LOGERRORMOD_USING_LOGGER(nuraft, _custom_logger, "{}", mesg);
} break;
;
case 3: {
LOGWARNMOD(nuraft, "{}", mesg);
LOGWARNMOD_USING_LOGGER(nuraft, _custom_logger, "{}", mesg);
} break;
;
case 4: {
LOGINFOMOD_USING_LOGGER(nuraft, _custom_logger, "INFO {}", mesg);
LOGINFOMOD_USING_LOGGER(nuraft, _custom_logger, "{}", mesg);
} break;
;
case 5: {
LOGDEBUGMOD_USING_LOGGER(nuraft, _custom_logger, "DEBUG {}", mesg);
LOGDEBUGMOD_USING_LOGGER(nuraft, _custom_logger, "{}", mesg);
} break;
;
default: {
LOGTRACEMOD_USING_LOGGER(nuraft, _custom_logger, "TRACE {}", mesg);
LOGTRACEMOD_USING_LOGGER(nuraft, _custom_logger, "{}", mesg);
} break;
;
}
}
};
2 changes: 1 addition & 1 deletion src/lib/mesg_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ nuraft::cmd_result_code group_factory::create_client(peer_id_t const& client,
nuraft::ptr< nuraft::rpc_client >& raft_client) {
LOGDEBUGMOD(nuraft_mesg, "Creating client to {}", client);
auto endpoint = lookupEndpoint(client);
if (endpoint.empty()) nuraft::BAD_REQUEST;
if (endpoint.empty()) return nuraft::BAD_REQUEST;

LOGDEBUGMOD(nuraft_mesg, "Creating client for [{}] @ [{}]", client, endpoint);
raft_client =
Expand Down
4 changes: 2 additions & 2 deletions src/lib/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ SISL_OPTION_GROUP(nuraft_mesg,
(resp)->when_ready( \
[p = std::make_shared< decltype(p) >(std::move(p))]( \
nuraft::cmd_result< nuraft::ptr< nuraft::buffer >, nuraft::ptr< std::exception > >& result, \
auto& e) mutable { \
auto&) mutable { \
if (nuraft::cmd_result_code::OK != result.get_result_code()) \
p->setValue(folly::makeUnexpected(result.get_result_code())); \
else \
Expand Down Expand Up @@ -252,7 +252,7 @@ class msg_group_listner : public nuraft::rpc_listener {
msg_group_listner(std::shared_ptr< msg_service > svc, group_id_t const& group) : _svc(svc), _group(group) {}
~msg_group_listner() { _svc->shutdown_for(_group); }

void listen(nuraft::ptr< nuraft::msg_handler >& handler) override {
void listen(nuraft::ptr< nuraft::msg_handler >&) override {
LOGINFOMOD(nuraft_mesg, "Begin listening on {}", _group);
}
void stop() override { LOGINFOMOD(nuraft_mesg, "Stop {}", _group); }
Expand Down
8 changes: 5 additions & 3 deletions src/lib/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ inline RCMsgBase* fromBaseRequest(nuraft::msg_base const& rcbase) {
return base;
}

static void serialize_to_byte_buffer(grpc::ByteBuffer& cli_byte_buf, io_blob_list_t const& cli_buf) {
[[maybe_unused]] static void serialize_to_byte_buffer(grpc::ByteBuffer& cli_byte_buf, io_blob_list_t const& cli_buf) {
folly::small_vector< grpc::Slice, 4 > slices;
for (auto const& blob : cli_buf) {
slices.emplace_back(blob.bytes, blob.size, grpc::Slice::STATIC_SLICE);
Expand All @@ -42,7 +42,8 @@ static void serialize_to_byte_buffer(grpc::ByteBuffer& cli_byte_buf, io_blob_lis
cli_byte_buf.Swap(&tmp);
}

static grpc::Status deserialize_from_byte_buffer(grpc::ByteBuffer const& cli_byte_buf, sisl::io_blob& cli_buf) {
[[maybe_unused]] static grpc::Status deserialize_from_byte_buffer(grpc::ByteBuffer const& cli_byte_buf,
sisl::io_blob& cli_buf) {
grpc::Slice slice;
auto status = cli_byte_buf.TrySingleSlice(&slice);
if (!status.ok()) { return status; }
Expand All @@ -53,7 +54,8 @@ static grpc::Status deserialize_from_byte_buffer(grpc::ByteBuffer const& cli_byt

// generic rpc server looks up rpc name in a map and calls the corresponding callback. To avoid another lookup in this
// layer, we registed one callback for each (group_id, request_name) pair. The rpc_name is their concatenation.
static std::string get_generic_method_name(std::string const& request_name, group_id_t const& group_id) {
[[maybe_unused]] static std::string get_generic_method_name(std::string const& request_name,
group_id_t const& group_id) {
return fmt::format("{}|{}", request_name, group_id);
}

Expand Down
2 changes: 2 additions & 0 deletions src/tests/jungle_logstore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ cmake_minimum_required (VERSION 3.11)

file (GLOB LIBRARY_SOURCES *.cc)

add_flags("-w")

if (APPLE)
set(OPEN_MEMSTREAM open_memstream.c)
message(STATUS "APPLE: Use custom ${OPEN_MEMSTREAM}")
Expand Down
2 changes: 1 addition & 1 deletion src/tests/jungle_logstore/jungle_log_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class jungle_log_store : public log_store {
const Options& opt = jungle_log_store::Options());
~jungle_log_store();

__nocopy__(jungle_log_store);
__nocopy__(jungle_log_store)

public:
/**
Expand Down
8 changes: 4 additions & 4 deletions src/tests/test_state_machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ class test_state_machine : public state_machine {
LOGINFO("Rollback message [{}] op: {}", log_idx, j_obj.at("op_type").get< int >());
}

virtual void save_snapshot_data(snapshot& s, const ulong offset, buffer& data) {}
virtual bool apply_snapshot(snapshot& s) { return true; }
virtual void save_snapshot_data(snapshot&, const ulong, buffer&) {}
virtual bool apply_snapshot(snapshot&) { return true; }

virtual int read_snapshot_data(snapshot& s, const ulong offset, buffer& data) { return 0; }
virtual int read_snapshot_data(snapshot&, const ulong, buffer&) { return 0; }

virtual ptr< snapshot > last_snapshot() { return ptr< snapshot >(); }

virtual void create_snapshot(snapshot& s, async_result< bool >::handler_type& when_done) {}
virtual void create_snapshot(snapshot&, async_result< bool >::handler_type&) {}

virtual ulong last_commit_index() {
auto_lock(lock_);
Expand Down

0 comments on commit 7ba33ac

Please sign in to comment.