Skip to content

Commit

Permalink
Enforce NOMINMAX macro everywhere in Mozc.
Browse files Browse the repository at this point in the history
With recent toolchains such as Visual C++ 2013 and Windows 8.1 SDK, we
are finally able to define NOMINMAX globally and unexceptionally without
breaking dependent libraries.  Now that including Windows.h no longer
defines min/max as a macro, we can remove per-file "#undef min" and
"#undef max" safely.

BUG=
TEST=unittest
REF_BUG=19010851
REF_CL=86940185
  • Loading branch information
yukawa committed Nov 9, 2015
1 parent 4474b76 commit 2cc1a05
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 32 deletions.
1 change: 1 addition & 0 deletions src/gyp/common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,7 @@
'COMPILER_MSVC',
'BUILD_MOZC', # for ime_shared library
'ID_TRACE_LEVEL=1',
'NOMINMAX',
'OS_WIN',
'UNICODE',
'WIN32',
Expand Down
4 changes: 3 additions & 1 deletion src/ipc/win32_ipc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
// skip all unless OS_WIN
#ifdef OS_WIN

#include <algorithm>

#include "ipc/ipc.h"

#include <Windows.h>
Expand Down Expand Up @@ -61,7 +63,7 @@ const int kMaxSuccessiveConnectionFailureCount = 5;
size_t GetNumberOfProcessors() {
// thread-safety is not required.
static size_t num = CPUStats().GetNumberOfProcessors();
return max(num, 1);
return max(num, static_cast<size_t>(1));
}

// Least significant bit of OVERLAPPED::hEvent can be used for special
Expand Down
2 changes: 1 addition & 1 deletion src/mozc_version_template.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MAJOR=2
MINOR=17
BUILD=2221
BUILD=2222
REVISION=102
# NACL_DICTIONARY_VERSION is the target version of the system dictionary to be
# downloaded by NaCl Mozc.
Expand Down
8 changes: 0 additions & 8 deletions src/renderer/win32/win32_image_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,6 @@
#include "base/stl_util.h"
#include "base/util.h"

// remove annoying macros
#ifdef min
#undef min
#endif // min
#ifdef max
#undef max
#endif // max

namespace mozc {
namespace renderer {
namespace win32 {
Expand Down
18 changes: 13 additions & 5 deletions src/renderer/win32/win32_image_util_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
#include <atlapp.h>
#include <atlgdi.h>
#include <atlmisc.h>
#include <gdiplus.h>

#include <algorithm>
#include <fstream>
#include <list>
#include <memory>
Expand All @@ -52,10 +52,13 @@

DECLARE_string(test_srcdir);

namespace mozc {
namespace renderer {
namespace win32 {
namespace {
using ::std::min;
using ::std::max;

// gdiplus.h must be placed here because it internally depends on
// global min/max functions.
// TODO(yukawa): Use WIC (Windows Imaging Component) instead of GDI+.
#include <gdiplus.h> // NOLINT

using ::mozc::renderer::win32::internal::GaussianBlur;
using ::mozc::renderer::win32::internal::SafeFrameBuffer;
Expand All @@ -69,6 +72,11 @@ using ::WTL::CLogFont;
using ::WTL::CPoint;
using ::WTL::CSize;

namespace mozc {
namespace renderer {
namespace win32 {
namespace {

typedef SubdivisionalPixel::SubdivisionalPixelIterator
SubdivisionalPixelIterator;

Expand Down
10 changes: 0 additions & 10 deletions src/renderer/win32/win32_renderer_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,6 @@
#include <atlgdi.h>
#include <atlmisc.h>

// undef min macro, which conflicts with std::numeric_limits<int>::min().
#if defined(min)
#undef min
#endif // min

// undef max macro, which conflicts with std::numeric_limits<int>::max().
#if defined(max)
#undef max
#endif // max

#include <algorithm>
#include <limits>
#include <memory>
Expand Down
2 changes: 0 additions & 2 deletions src/renderer/win32/window_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@

#include "renderer/win32/window_manager.h"

#undef min
#undef max
#include <algorithm>
#include <limits>

Expand Down
3 changes: 3 additions & 0 deletions src/server/mozc_cache_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
#include <atlstr.h> // for CString
#endif // !NO_LOGGING
#include <psapi.h>

#include <algorithm>

#include "base/file_util.h"
#include "base/scoped_handle.h"
#include "base/system_util.h"
Expand Down
3 changes: 2 additions & 1 deletion src/win32/ime/ime_ui_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <atlmisc.h>
#include <strsafe.h>

#include <algorithm>
#include <memory>

#include "base/const.h"
Expand Down Expand Up @@ -349,7 +350,7 @@ class LangBarCallbackImpl : public LangBarCallback {

virtual ULONG AddRef() {
const LONG count = ::InterlockedIncrement(&reference_count_);
return max(count, 0);
return static_cast<ULONG>(max(count, static_cast<LONG>(0)));
}

virtual ULONG Release() {
Expand Down
4 changes: 0 additions & 4 deletions src/win32/tip/tip_range_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ using ATL::CComQIPtr;
using ATL::CComVariant;
using std::unique_ptr;

#ifdef min
#undef min
#endif // min

// GUID_PROP_INPUTSCOPE
GUID kGuidPropInputscope = {
0x1713dd5a, 0x68e7, 0x4a5b, {0x9a, 0xf6, 0x59, 0x2a, 0x59, 0x5c, 0x77, 0x8d}
Expand Down

0 comments on commit 2cc1a05

Please sign in to comment.