Skip to content
This repository has been archived by the owner on Apr 6, 2019. It is now read-only.

Commit

Permalink
Resolve Compiler Warnings for Windows Build (#129)
Browse files Browse the repository at this point in the history
* MSVC: Use same 'PlatformToolset' for all build configurations.

* MSVC warnings
- Enable `TreatWarningsAsErrors` for compiler and linker.
- Resolve compiler warnings (possible loss of data).
  • Loading branch information
zodiac403 authored and Cylix committed Nov 3, 2017
1 parent f494ab3 commit b35e369
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 6 deletions.
29 changes: 29 additions & 0 deletions includes/cpp_redis/misc/macro.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// The MIT License (MIT)
//
// Copyright (c) 2015-2017 Simon Ninon <[email protected]>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#pragma once

#if _WIN32
#define __CPP_REDIS_LENGTH(size) static_cast<unsigned int>(size) // for Windows, convert size to `unsigned int`
#else /* _WIN32 */
#define __CPP_REDIS_LENGTH(size) size // for Unix, keep size as `size_t`
#endif /* _WIN32 */
25 changes: 21 additions & 4 deletions msvc15/cpp_redis.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ SOFTWARE.
<ClInclude Include="..\includes\cpp_redis\helpers\variadic_template.hpp" />
<ClInclude Include="..\includes\cpp_redis\misc\error.hpp" />
<ClInclude Include="..\includes\cpp_redis\misc\logger.hpp" />
<ClInclude Include="..\includes\cpp_redis\misc\macro.hpp" />
<ClInclude Include="..\includes\cpp_redis\network\redis_connection.hpp" />
<ClInclude Include="..\includes\cpp_redis\network\tcp_client.hpp" />
<ClInclude Include="..\includes\cpp_redis\network\tcp_client_iface.hpp" />
Expand All @@ -91,13 +92,13 @@ SOFTWARE.
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
Expand All @@ -110,7 +111,7 @@ SOFTWARE.
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
Expand Down Expand Up @@ -148,10 +149,14 @@ SOFTWARE.
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;_WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\includes;..\tacopie\includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
</Link>
<Lib>
<TreatLibWarningAsErrors>true</TreatLibWarningAsErrors>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
Expand All @@ -162,10 +167,14 @@ SOFTWARE.
<PreprocessorDefinitions>_DEBUG;_LIB;_WIN32;_WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\includes;..\tacopie\includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
</Link>
<Lib>
<TreatLibWarningAsErrors>true</TreatLibWarningAsErrors>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
Expand All @@ -177,12 +186,16 @@ SOFTWARE.
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;_WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\includes;..\tacopie\includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
<Lib>
<TreatLibWarningAsErrors>true</TreatLibWarningAsErrors>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
Expand All @@ -194,14 +207,18 @@ SOFTWARE.
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>NDEBUG;_LIB;_WIN32;_WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\includes;..\tacopie\includes;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
<Lib>
<TreatLibWarningAsErrors>true</TreatLibWarningAsErrors>
</Lib>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
3 changes: 3 additions & 0 deletions msvc15/cpp_redis.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,8 @@ SOFTWARE.
<ClInclude Include="..\includes\cpp_redis\network\tcp_client_iface.hpp">
<Filter>Header Files\cpp_redis\network</Filter>
</ClInclude>
<ClInclude Include="..\includes\cpp_redis\misc\macro.hpp">
<Filter>Header Files\cpp_redis\misc</Filter>
</ClInclude>
</ItemGroup>
</Project>
3 changes: 2 additions & 1 deletion sources/core/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <cpp_redis/core/client.hpp>
#include <cpp_redis/misc/error.hpp>
#include <cpp_redis/misc/macro.hpp>

namespace cpp_redis {

Expand Down Expand Up @@ -257,7 +258,7 @@ client::clear_callbacks(void) {
//! dequeue commands and move them to a local variable
std::queue<command_request> commands = std::move(m_commands);

m_callbacks_running += commands.size();
m_callbacks_running += __CPP_REDIS_LENGTH(commands.size());

std::thread t([=]() mutable {
while (!commands.empty()) {
Expand Down
3 changes: 2 additions & 1 deletion sources/network/tcp_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#include <cpp_redis/misc/macro.hpp>
#include <cpp_redis/network/tcp_client.hpp>

namespace cpp_redis {
Expand Down Expand Up @@ -82,7 +83,7 @@ tcp_client::set_on_disconnection_handler(const disconnection_handler_t& disconne

void
set_default_nb_workers(std::size_t nb_threads) {
tacopie::get_default_io_service(nb_threads);
tacopie::get_default_io_service(__CPP_REDIS_LENGTH(nb_threads));
}

} // namespace network
Expand Down

0 comments on commit b35e369

Please sign in to comment.