Commit 86c8498c authored by Kenton Varda's avatar Kenton Varda

Transparently work around VOID and ERROR being #defined on Windows. Fixes #284.

parent 3aa2b2aa
......@@ -29,6 +29,7 @@
#include "pointer-helpers.h"
#include "orphan.h"
#include "list.h"
#include <kj/windows-sanity.h> // work-around macro conflict with `VOID`
namespace capnp {
......
......@@ -4,6 +4,7 @@
#pragma once
#include <capnp/generated-header-support.h>
#include <kj/windows-sanity.h>
#if CAPNP_VERSION != 7000
#error "Version mismatch between generated code and library headers. You must use the same version of the Cap'n Proto compiler and library."
......
......@@ -32,6 +32,7 @@
#include <inttypes.h>
#include <kj/string.h>
#include <kj/memory.h>
#include <kj/windows-sanity.h> // work-around macro conflict with `VOID`
#if CAPNP_DEBUG_TYPES
#include <kj/units.h>
......
......@@ -4,6 +4,7 @@
#pragma once
#include <capnp/generated-header-support.h>
#include <kj/windows-sanity.h>
#if !CAPNP_LITE
#include <capnp/capability.h>
#endif // !CAPNP_LITE
......
......@@ -2980,7 +2980,8 @@ private:
"\n"
"#pragma once\n"
"\n"
"#include <capnp/generated-header-support.h>\n",
"#include <capnp/generated-header-support.h>\n"
"#include <kj/windows-sanity.h>\n", // work-around macro conflict with VOID
hasInterfaces ? kj::strTree(
"#if !CAPNP_LITE\n"
"#include <capnp/capability.h>\n"
......
......@@ -4,6 +4,7 @@
#pragma once
#include <capnp/generated-header-support.h>
#include <kj/windows-sanity.h>
#if CAPNP_VERSION != 7000
#error "Version mismatch between generated code and library headers. You must use the same version of the Cap'n Proto compiler and library."
......
......@@ -4,6 +4,7 @@
#pragma once
#include <capnp/generated-header-support.h>
#include <kj/windows-sanity.h>
#if CAPNP_VERSION != 7000
#error "Version mismatch between generated code and library headers. You must use the same version of the Cap'n Proto compiler and library."
......
......@@ -41,6 +41,7 @@
#include "message.h"
#include "any.h"
#include "capability.h"
#include <kj/windows-sanity.h> // work-around macro conflict with `VOID`
namespace capnp {
......
......@@ -37,6 +37,7 @@
#include "common.h"
#include "blob.h"
#include "endian.h"
#include <kj/windows-sanity.h> // work-around macro conflict with `VOID`
#if (defined(__mips__) || defined(__hppa__)) && !defined(CAPNP_CANONICALIZE_NAN)
#define CAPNP_CANONICALIZE_NAN 1
......
......@@ -4,6 +4,7 @@
#pragma once
#include <capnp/generated-header-support.h>
#include <kj/windows-sanity.h>
#if !CAPNP_LITE
#include <capnp/capability.h>
#endif // !CAPNP_LITE
......
......@@ -4,6 +4,7 @@
#pragma once
#include <capnp/generated-header-support.h>
#include <kj/windows-sanity.h>
#if CAPNP_VERSION != 7000
#error "Version mismatch between generated code and library headers. You must use the same version of the Cap'n Proto compiler and library."
......
......@@ -4,6 +4,7 @@
#pragma once
#include <capnp/generated-header-support.h>
#include <kj/windows-sanity.h>
#if CAPNP_VERSION != 7000
#error "Version mismatch between generated code and library headers. You must use the same version of the Cap'n Proto compiler and library."
......
......@@ -4,6 +4,7 @@
#pragma once
#include <capnp/generated-header-support.h>
#include <kj/windows-sanity.h>
#if CAPNP_VERSION != 7000
#error "Version mismatch between generated code and library headers. You must use the same version of the Cap'n Proto compiler and library."
......
......@@ -30,6 +30,7 @@
#endif
#include <capnp/schema.capnp.h>
#include <kj/windows-sanity.h> // work-around macro conflict with `VOID`
namespace capnp {
......
......@@ -30,6 +30,7 @@
// in the constructor, teardown in the destructor.
#include "../test.h"
#include <kj/windows-sanity.h> // work-around macro conflict with `ERROR`
namespace kj {
......
......@@ -112,11 +112,7 @@
#include "string.h"
#include "exception.h"
#ifdef ERROR
// This is problematic because windows.h #defines ERROR, which we use in an enum here.
#error "Make sure to to undefine ERROR (or just #include <kj/windows-sanity.h>) before this file"
#endif
#include "windows-sanity.h" // work-around macro conflict with `ERROR`
namespace kj {
......
......@@ -28,6 +28,7 @@
#include "memory.h"
#include "array.h"
#include "string.h"
#include "windows-sanity.h" // work-around macro conflict with `ERROR`
namespace kj {
......
......@@ -28,6 +28,7 @@
#include "debug.h"
#include "vector.h"
#include "function.h"
#include "windows-sanity.h" // work-around macro conflict with `ERROR`
namespace kj {
......
// Copyright (c) 2013-2014 Sandstorm Development Group, Inc. and contributors
// Copyright (c) 2013-2018 Sandstorm Development Group, Inc. and contributors
// Licensed under the MIT License:
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
......@@ -19,20 +19,46 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// This file replaces poorly-named #defines from windows.h with properly-namespaced versions, so
// that they no longer conflict with similarly-named identifiers in other namespaces.
//
// This file must be #included some time after windows.h has been #included but before any attempt
// to use the names for other purposes. However, this can be difficult to determine in header
// files. Typically KJ / Cap'n Proto headers avoid including windows.h at all, but may use
// conflicting identifiers. In order to relieve application developers from the need to include
// windows-sanity.h themselves, we would like these headers to conditionally apply the fixes if
// and only if windows.h was already included. Therefore, this header checks if windows.h has been
// included and only applies fixups if this is the case. Furthermore, this header is designed such
// that it can be included multiple times, and the fixups will be applied the first time it is
// included *after* windows.h.
//
// Now, as long as any headers which need to use conflicting identifier names be sure to #include
// windows-sanity.h, we can be sure that no conflicts will occur regardless of in what order the
// application chooses to include these headers vs. windows.h.
#if !_WIN32
// Not on Windows. Tell the compiler never to try to include this again.
#pragma once
#if defined(__GNUC__) && !KJ_HEADER_WARNINGS
#pragma GCC system_header
#endif
#elif defined(_INC_WINDOWS)
#ifndef _INC_WINDOWS
#error "windows.h needs to be included before kj/windows-sanity.h (or perhaps you don't need either?)"
#endif
// We're on Windows and windows.h has been included. We need to fixup the namespace. We only need
// to do this once, but we can't do it until windows.h has been included. Since that has happened
// now, we use `#pragma once` to tell the compiler never to include this file again.
#pragma once
namespace win32 {
const auto ERROR_ = ERROR;
#undef ERROR
const auto ERROR = ERROR_;
typedef VOID VOID_;
#undef VOID
typedef VOID_ VOID;
}
using win32::ERROR;
using win32::VOID;
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment