annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/include/kj/windows-sanity.h @ 69:33d812a61356

planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author jpayne
date Tue, 18 Mar 2025 17:55:14 -0400
parents
children
rev   line source
jpayne@69 1 // Copyright (c) 2013-2018 Sandstorm Development Group, Inc. and contributors
jpayne@69 2 // Licensed under the MIT License:
jpayne@69 3 //
jpayne@69 4 // Permission is hereby granted, free of charge, to any person obtaining a copy
jpayne@69 5 // of this software and associated documentation files (the "Software"), to deal
jpayne@69 6 // in the Software without restriction, including without limitation the rights
jpayne@69 7 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
jpayne@69 8 // copies of the Software, and to permit persons to whom the Software is
jpayne@69 9 // furnished to do so, subject to the following conditions:
jpayne@69 10 //
jpayne@69 11 // The above copyright notice and this permission notice shall be included in
jpayne@69 12 // all copies or substantial portions of the Software.
jpayne@69 13 //
jpayne@69 14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
jpayne@69 15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
jpayne@69 16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
jpayne@69 17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
jpayne@69 18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
jpayne@69 19 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
jpayne@69 20 // THE SOFTWARE.
jpayne@69 21
jpayne@69 22 // This file replaces poorly-named #defines from windows.h with properly-namespaced versions, so
jpayne@69 23 // that they no longer conflict with similarly-named identifiers in other namespaces.
jpayne@69 24 //
jpayne@69 25 // This file must be #included some time after windows.h has been #included but before any attempt
jpayne@69 26 // to use the names for other purposes. However, this can be difficult to determine in header
jpayne@69 27 // files. Typically KJ / Cap'n Proto headers avoid including windows.h at all, but may use
jpayne@69 28 // conflicting identifiers. In order to relieve application developers from the need to include
jpayne@69 29 // windows-sanity.h themselves, we would like these headers to conditionally apply the fixes if
jpayne@69 30 // and only if windows.h was already included. Therefore, this header checks if windows.h has been
jpayne@69 31 // included and only applies fixups if this is the case. Furthermore, this header is designed such
jpayne@69 32 // that it can be included multiple times, and the fixups will be applied the first time it is
jpayne@69 33 // included *after* windows.h.
jpayne@69 34 //
jpayne@69 35 // Now, as long as any headers which need to use conflicting identifier names be sure to #include
jpayne@69 36 // windows-sanity.h, we can be sure that no conflicts will occur regardless of in what order the
jpayne@69 37 // application chooses to include these headers vs. windows.h.
jpayne@69 38
jpayne@69 39 #if !_WIN32 && !__CYGWIN__
jpayne@69 40
jpayne@69 41 // Not on Windows. Tell the compiler never to try to include this again.
jpayne@69 42 #pragma once
jpayne@69 43
jpayne@69 44 #elif defined(_INC_WINDOWS)
jpayne@69 45
jpayne@69 46 // We're on Windows and windows.h has been included. We need to fixup the namespace. We only need
jpayne@69 47 // to do this once, but we can't do it until windows.h has been included. Since that has happened
jpayne@69 48 // now, we use `#pragma once` to tell the compiler never to include this file again.
jpayne@69 49 #pragma once
jpayne@69 50
jpayne@69 51 namespace kj_win32_workarounds {
jpayne@69 52 // Namespace containing constant definitions intended to replace constants that are defined as
jpayne@69 53 // macros in the Windows headers. Do not refer to this namespace directly, we'll import it into
jpayne@69 54 // the global scope below.
jpayne@69 55
jpayne@69 56 #ifdef ERROR // This could be absent if e.g. NOGDI was used.
jpayne@69 57 const auto ERROR_ = ERROR;
jpayne@69 58 #undef ERROR
jpayne@69 59 const auto ERROR = ERROR_;
jpayne@69 60 #endif
jpayne@69 61
jpayne@69 62 typedef VOID VOID_;
jpayne@69 63 #undef VOID
jpayne@69 64 typedef VOID_ VOID;
jpayne@69 65 }
jpayne@69 66
jpayne@69 67 // Pull our constant definitions into the global namespace -- but only if they don't already exist
jpayne@69 68 // in the global namespace.
jpayne@69 69 using namespace kj_win32_workarounds;
jpayne@69 70
jpayne@69 71 #endif