From 0728b91bfad008ec0aa2992087ce90652237a102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Sun, 8 Jun 2014 20:57:39 -0700 Subject: [PATCH] Workaround C4127 MSVC level 4 warning. --- examples/common/nanovg/nanovg.h | 2 +- src/bgfx.cpp | 4 ++-- src/bgfx_p.h | 22 +++++++++++----------- src/glcontext_wgl.cpp | 2 +- src/renderer_d3d.h | 12 ++++++------ src/renderer_d3d9.cpp | 4 ++-- src/renderer_d3d9.h | 6 +++--- src/renderer_gl.cpp | 6 +++--- src/renderer_gl.h | 6 +++--- 9 files changed, 32 insertions(+), 32 deletions(-) diff --git a/examples/common/nanovg/nanovg.h b/examples/common/nanovg/nanovg.h index e413a7324..f9b1df27e 100644 --- a/examples/common/nanovg/nanovg.h +++ b/examples/common/nanovg/nanovg.h @@ -534,7 +534,7 @@ struct NVGcontext* nvgCreate(int atlasw, int atlash, int edgeaa); // void nvgDelete(struct NVGcontext* ctx); -#define NVG_NOTUSED(v) do { (void)(true ? (void)0 : ( (void)(v) ) ); } while(0) +#define NVG_NOTUSED(v) for (;;) { (void)(true ? (void)0 : ( (void)(v) ) ); break; } #ifdef __cplusplus } diff --git a/src/bgfx.cpp b/src/bgfx.cpp index 16084f901..df90410b4 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -974,13 +974,13 @@ namespace bgfx if (BX_ENABLED(BGFX_CONFIG_DEBUG) ) { #define CHECK_HANDLE_LEAK(_handleAlloc) \ - do { \ + BX_MACRO_BLOCK_BEGIN \ BX_WARN(0 == _handleAlloc.getNumHandles() \ , "LEAK: " #_handleAlloc " %d (max: %d)" \ , _handleAlloc.getNumHandles() \ , _handleAlloc.getMaxHandles() \ ); \ - } while (0) + BX_MACRO_BLOCK_END CHECK_HANDLE_LEAK(m_dynamicIndexBufferHandle); CHECK_HANDLE_LEAK(m_dynamicVertexBufferHandle); diff --git a/src/bgfx_p.h b/src/bgfx_p.h index 575e0cb2e..184f8ff3d 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -23,26 +23,26 @@ namespace bgfx } #define _BX_TRACE(_format, ...) \ - do { \ + BX_MACRO_BLOCK_BEGIN \ bgfx::dbgPrintf(BX_FILE_LINE_LITERAL "BGFX " _format "\n", ##__VA_ARGS__); \ - } while(0) + BX_MACRO_BLOCK_END #define _BX_WARN(_condition, _format, ...) \ - do { \ - if (!(_condition) ) \ + BX_MACRO_BLOCK_BEGIN \ + if (!BX_IGNORE_C4127(_condition) ) \ { \ BX_TRACE("WARN " _format, ##__VA_ARGS__); \ } \ - } while(0) + BX_MACRO_BLOCK_END #define _BX_CHECK(_condition, _format, ...) \ - do { \ - if (!(_condition) ) \ + BX_MACRO_BLOCK_BEGIN \ + if (!BX_IGNORE_C4127(_condition) ) \ { \ BX_TRACE("CHECK " _format, ##__VA_ARGS__); \ bgfx::fatal(bgfx::Fatal::DebugCheck, _format, ##__VA_ARGS__); \ } \ - } while(0) + BX_MACRO_BLOCK_END #if BGFX_CONFIG_DEBUG # define BX_TRACE _BX_TRACE @@ -52,12 +52,12 @@ namespace bgfx #endif // BGFX_CONFIG_DEBUG #define BGFX_FATAL(_condition, _err, _format, ...) \ - do { \ - if (!(_condition) ) \ + BX_MACRO_BLOCK_BEGIN \ + if (!BX_IGNORE_C4127(_condition) ) \ { \ fatal(_err, _format, ##__VA_ARGS__); \ } \ - } while(0) + BX_MACRO_BLOCK_END #include #include diff --git a/src/glcontext_wgl.cpp b/src/glcontext_wgl.cpp index 1b64f187f..f8551d151 100644 --- a/src/glcontext_wgl.cpp +++ b/src/glcontext_wgl.cpp @@ -287,7 +287,7 @@ namespace bgfx { \ BX_TRACE("wgl %p " #_func " (" #_import ")", _func); \ } \ - BGFX_FATAL(_optional || NULL != _func, Fatal::UnableToInitialize, "Failed to create OpenGL context. wglGetProcAddress(\"%s\")", #_import); \ + BGFX_FATAL(BX_IGNORE_C4127(_optional) || NULL != _func, Fatal::UnableToInitialize, "Failed to create OpenGL context. wglGetProcAddress(\"%s\")", #_import); \ } \ } # include "glimports.h" diff --git a/src/renderer_d3d.h b/src/renderer_d3d.h index 49a762b69..8f2556bb3 100644 --- a/src/renderer_d3d.h +++ b/src/renderer_d3d.h @@ -22,29 +22,29 @@ namespace bgfx { #define _DX_CHECK(_call) \ - do { \ + BX_MACRO_BLOCK_BEGIN \ HRESULT __hr__ = _call; \ BX_CHECK(SUCCEEDED(__hr__), #_call " FAILED 0x%08x" DX_CHECK_EXTRA_F "\n" \ , (uint32_t)__hr__ \ DX_CHECK_EXTRA_ARGS \ ); \ - } while (0) + BX_MACRO_BLOCK_END #define _DX_RELEASE(_ptr, _expected, _check) \ - do { \ + BX_MACRO_BLOCK_BEGIN \ if (NULL != _ptr) \ { \ ULONG count = _ptr->Release(); \ _check(isGraphicsDebuggerPresent() || _expected == count, "%p RefCount is %d (expected %d).", _ptr, count, _expected); BX_UNUSED(count); \ _ptr = NULL; \ } \ - } while (0) + BX_MACRO_BLOCK_END # define _DX_CHECK_REFCOUNT(_ptr, _expected) \ - do { \ + BX_MACRO_BLOCK_BEGIN \ ULONG count = getRefCount(_ptr); \ BX_CHECK(isGraphicsDebuggerPresent() || _expected == count, "%p RefCount is %d (expected %d).", _ptr, count, _expected); \ - } while (0) + BX_MACRO_BLOCK_END #if BGFX_CONFIG_DEBUG # define DX_CHECK(_call) _DX_CHECK(_call) diff --git a/src/renderer_d3d9.cpp b/src/renderer_d3d9.cpp index f42a628db..3104b8515 100644 --- a/src/renderer_d3d9.cpp +++ b/src/renderer_d3d9.cpp @@ -1239,7 +1239,7 @@ namespace bgfx IDirect3DDevice9* device = m_device; - do + for (;;) { uint32_t opcode = _constantBuffer.read(); @@ -1348,7 +1348,7 @@ namespace bgfx #undef CASE_IMPLEMENT_UNIFORM - } while (true); + } } #if BX_PLATFORM_WINDOWS diff --git a/src/renderer_d3d9.h b/src/renderer_d3d9.h index 771b4324d..692d81b4b 100644 --- a/src/renderer_d3d9.h +++ b/src/renderer_d3d9.h @@ -30,9 +30,9 @@ typedef IDirect3D9* (WINAPI *Direct3DCreate9Fn)(UINT SDKVersion); # define D3DFMT_DF24 D3DFMT_D24FS8 -# define _PIX_SETMARKER(_col, _name) do {} while(0) -# define _PIX_BEGINEVENT(_col, _name) do {} while(0) -# define _PIX_ENDEVENT() do {} while(0) +# define _PIX_SETMARKER(_col, _name) BX_NOOP() +# define _PIX_BEGINEVENT(_col, _name) BX_NOOP() +# define _PIX_ENDEVENT() BX_NOOP #endif // BX_PLATFORM_ #ifndef D3DSTREAMSOURCE_INDEXEDDATA diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index b8b138f80..5b8d252ec 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -1852,7 +1852,7 @@ namespace bgfx { _constantBuffer.reset(); - do + for (;;) { uint32_t opcode = _constantBuffer.read(); @@ -1928,7 +1928,7 @@ namespace bgfx #undef CASE_IMPLEMENT_UNIFORM #undef CASE_IMPLEMENT_UNIFORM_T - } while (true); + } } void clearQuad(ClearQuad& _clearQuad, const Rect& _rect, const Clear& _clear, uint32_t _height) @@ -2859,7 +2859,7 @@ namespace bgfx && GL_RGBA == m_fmt && !s_renderGL->m_textureSwizzleSupport ; - const bool unpackRowLength = !!BGFX_CONFIG_RENDERER_OPENGL || s_extension[Extension::EXT_unpack_subimage].m_supported; + const bool unpackRowLength = BX_IGNORE_C4127(!!BGFX_CONFIG_RENDERER_OPENGL || s_extension[Extension::EXT_unpack_subimage].m_supported); const bool convert = m_textureFormat != m_requestedFormat; const bool compressed = isCompressed(TextureFormat::Enum(m_textureFormat) ); diff --git a/src/renderer_gl.h b/src/renderer_gl.h index 3ccd01330..40dab1ffc 100644 --- a/src/renderer_gl.h +++ b/src/renderer_gl.h @@ -376,15 +376,15 @@ namespace bgfx const char* glEnumName(GLenum _enum); #define _GL_CHECK(_check, _call) \ - do { \ + BX_MACRO_BLOCK_BEGIN \ /*BX_TRACE(#_call);*/ \ _call; \ GLenum err = glGetError(); \ _check(0 == err, #_call "; GL error 0x%x: %s", err, glEnumName(err) ); \ BX_UNUSED(err); \ - } while (0) + BX_MACRO_BLOCK_END -#define IGNORE_GL_ERROR_CHECK(...) do {} while(0) +#define IGNORE_GL_ERROR_CHECK(...) BX_NOOP() #if BGFX_CONFIG_DEBUG # define GL_CHECK(_call) _GL_CHECK(BX_CHECK, _call)