mirror of
https://github.com/tianocore/edk2
synced 2026-08-27 00:23:19 -04:00
CryptoPkg: Replace include guards with #pragma once
Replace traditional `#ifndef`/`#define`/`#endif` include guards with
`#pragma` once.
`#pragma once` is a widely supported preprocessor directive that
prevents header files from being included multiple times. It is
supported by all toolchains used to build edk2: GCC, Clang/LLVM, and
MSVC.
Does not include updates to OpenSSL generated header files checked
into the repo. Those in `CryptoPkg\Library\OpensslLib\OpensslGen\`.
Compared to macro-based include guards, `#pragma once`:
- Eliminates the risk of macro name collisions or copy/paste errors
where two headers inadvertently use the same guard macro.
- Eliminate inconsistency in the way include guard macros are named
(e.g., some files use `__FILE_H__`, others use `FILE_H_`, etc.).
- Reduces boilerplate (three lines replaced by one).
- Avoids polluting the macro namespace with guard symbols.
- Can improve build times as the preprocessor can skip re-opening the
file entirely, rather than re-reading it to find the matching
`#endif` ("multiple-include optimization").
- Note that some compilers may already optimize traditional include
guards, by recognzining the idiomatic pattern.
This change is made acknowledging that overall portability of the
code will technically be reduced, as `#pragma once` is not part of the
C/C++ standards.
However, this is considered acceptable given:
1. edk2 already defines a subset of supported compilers in
BaseTools/Conf/tools_def.template, all of which have supported
`#pragma once` for over two decades.
2. There have been concerns raised to the project about inconsistent
include guard naming and potential macro collisions.
Approximate compiler support dates:
- MSVC: Supported since Visual C++ 4.2 (1996)
- GCC: Supported since 3.4 (2004)
(http://gnu.ist.utl.pt/software/gcc/gcc-3.4/changes.html)
- Clang (LLVM based): Since initial release in 2007
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
This commit is contained in:
parent
0e6d10de1c
commit
0f42cae11c
20 changed files with 21 additions and 79 deletions
|
|
@ -10,8 +10,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||
|
||||
**/
|
||||
|
||||
#ifndef __BASE_CRYPT_LIB_H__
|
||||
#define __BASE_CRYPT_LIB_H__
|
||||
#pragma once
|
||||
|
||||
#include <Uefi/UefiBaseType.h>
|
||||
|
||||
|
|
@ -4302,5 +4301,3 @@ EcDsaVerify (
|
|||
IN CONST UINT8 *Signature,
|
||||
IN UINTN SigSize
|
||||
);
|
||||
|
||||
#endif // __BASE_CRYPT_LIB_H__
|
||||
|
|
|
|||
|
|
@ -9,8 +9,7 @@
|
|||
|
||||
**/
|
||||
|
||||
#ifndef __HASH_API_LIB_H_
|
||||
#define __HASH_API_LIB_H_
|
||||
#pragma once
|
||||
|
||||
typedef VOID *HASH_API_CONTEXT;
|
||||
|
||||
|
|
@ -106,5 +105,3 @@ HashApiHashAll (
|
|||
IN UINTN DataToHashLen,
|
||||
OUT UINT8 *Digest
|
||||
);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,8 +6,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||
|
||||
**/
|
||||
|
||||
#ifndef __TLS_LIB_H__
|
||||
#define __TLS_LIB_H__
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
Initializes the OpenSSL library.
|
||||
|
|
@ -968,5 +967,3 @@ TlsGetExportKey (
|
|||
OUT VOID *KeyBuffer,
|
||||
IN UINTN KeyBufferLen
|
||||
);
|
||||
|
||||
#endif // __TLS_LIB_H__
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
|
||||
**/
|
||||
|
||||
#ifndef __PCD_CRYPTO_SERVICE_FAMILY_ENABLE_H__
|
||||
#define __PCD_CRYPTO_SERVICE_FAMILY_ENABLE_H__
|
||||
#pragma once
|
||||
|
||||
///
|
||||
/// Define used to enable all the crypto services in a family
|
||||
|
|
@ -431,5 +430,3 @@ typedef struct {
|
|||
UINT32 Family;
|
||||
} Ec;
|
||||
} PCD_CRYPTO_SERVICE_FAMILY_ENABLE;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -21,8 +21,7 @@ and related or neighboring rights to the source code in this file.
|
|||
http://creativecommons.org/publicdomain/zero/1.0/
|
||||
**/
|
||||
|
||||
#ifndef CRYPT_PARALLEL_HASH_H_
|
||||
#define CRYPT_PARALLEL_HASH_H_
|
||||
#pragma once
|
||||
|
||||
#include "InternalCryptLib.h"
|
||||
|
||||
|
|
@ -228,5 +227,3 @@ EFIAPI
|
|||
DispatchBlockToAp (
|
||||
VOID
|
||||
);
|
||||
|
||||
#endif // CRYPT_PARALLEL_HASH_H_
|
||||
|
|
|
|||
|
|
@ -6,8 +6,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||
|
||||
**/
|
||||
|
||||
#ifndef __INTERNAL_CRYPT_LIB_H__
|
||||
#define __INTERNAL_CRYPT_LIB_H__
|
||||
#pragma once
|
||||
|
||||
#undef _WIN32
|
||||
#undef _WIN64
|
||||
|
|
@ -60,5 +59,3 @@ WrapPkcs7Data (
|
|||
OUT UINT8 **WrapData,
|
||||
OUT UINTN *WrapDataSize
|
||||
);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,8 +6,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||
|
||||
**/
|
||||
|
||||
#ifndef INTERNAL_CRYPT_LIB_H_
|
||||
#define INTERNAL_CRYPT_LIB_H_
|
||||
#pragma once
|
||||
|
||||
#include <Library/BaseLib.h>
|
||||
#include <Library/BaseMemoryLib.h>
|
||||
|
|
@ -70,5 +69,3 @@ WrapPkcs7Data (
|
|||
OUT UINT8 **WrapData,
|
||||
OUT UINTN *WrapDataSize
|
||||
);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -9,8 +9,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||
|
||||
**/
|
||||
|
||||
#ifndef CRYPT_PKCS7_INTERNAL_H_
|
||||
#define CRYPT_PKCS7_INTERNAL_H_
|
||||
#pragma once
|
||||
|
||||
#include "InternalCryptLib.h"
|
||||
|
||||
|
|
@ -85,5 +84,3 @@ typedef struct MbedtlsPkcs7 {
|
|||
else \
|
||||
(g) += Ret; \
|
||||
} while( 0 )
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,11 +6,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||
|
||||
**/
|
||||
|
||||
#ifndef __INTERNAL_CRYPT_LIB_H__
|
||||
#define __INTERNAL_CRYPT_LIB_H__
|
||||
#pragma once
|
||||
|
||||
#include <Base.h>
|
||||
#include <Library/BaseCryptLib.h>
|
||||
#include <Library/DebugLib.h>
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -9,8 +9,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||
|
||||
**/
|
||||
|
||||
#ifndef __CRT_LIB_SUPPORT_H__
|
||||
#define __CRT_LIB_SUPPORT_H__
|
||||
#pragma once
|
||||
|
||||
#include <Library/BaseLib.h>
|
||||
#include <Library/BaseMemoryLib.h>
|
||||
|
|
@ -485,4 +484,3 @@ strpbrk (
|
|||
#else
|
||||
#define UINTPTR_MAX 0xFFFFFFFFUL
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||
|
||||
**/
|
||||
|
||||
#ifndef CRYPTO_CRT_STDIO_H_
|
||||
#define CRYPTO_CRT_STDIO_H_
|
||||
#pragma once
|
||||
|
||||
#include <CrtLibSupport.h>
|
||||
|
||||
//
|
||||
|
|
@ -24,5 +24,3 @@ typedef INT64 int64_t;
|
|||
typedef UINT64 uint64_t;
|
||||
typedef UINTN uintptr_t;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,8 +6,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||
|
||||
**/
|
||||
|
||||
#ifndef __INTERNAL_TLS_LIB_H__
|
||||
#define __INTERNAL_TLS_LIB_H__
|
||||
#pragma once
|
||||
|
||||
#undef _WIN32
|
||||
#undef _WIN64
|
||||
|
|
@ -56,5 +55,3 @@ typedef struct {
|
|||
BIO *BioDebug;
|
||||
INT32 Ack;
|
||||
} TLS_EXT_CTX;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,11 +6,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||
|
||||
**/
|
||||
|
||||
#ifndef __INTERNAL_TLS_LIB_NULL_H__
|
||||
#define __INTERNAL_TLS_LIB_NULL_H__
|
||||
#pragma once
|
||||
|
||||
#include <Library/BaseCryptLib.h>
|
||||
#include <Library/DebugLib.h>
|
||||
#include <Library/BaseLib.h>
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,11 +6,8 @@
|
|||
|
||||
**/
|
||||
|
||||
#ifndef INTRINSTIC_LIB_H_
|
||||
#define INTRINSTIC_LIB_H_
|
||||
#pragma once
|
||||
|
||||
//
|
||||
// Compiler dependent intrinsic APIs.
|
||||
//
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,7 +6,4 @@
|
|||
|
||||
**/
|
||||
|
||||
#ifndef MBEDTLS_LIB_H_
|
||||
#define MBEDTLS_LIB_H_
|
||||
|
||||
#endif
|
||||
#pragma once
|
||||
|
|
|
|||
|
|
@ -6,9 +6,6 @@
|
|||
|
||||
**/
|
||||
|
||||
#ifndef OPENSSL_LIB_H_
|
||||
#define OPENSSL_LIB_H_
|
||||
#pragma once
|
||||
|
||||
#include <openssl/opensslv.h>
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,8 +6,7 @@
|
|||
|
||||
**/
|
||||
|
||||
#ifndef __EDKII_CRYPTO_PPI_H__
|
||||
#define __EDKII_CRYPTO_PPI_H__
|
||||
#pragma once
|
||||
|
||||
#include <Protocol/Crypto.h>
|
||||
|
||||
|
|
@ -17,5 +16,3 @@
|
|||
typedef EDKII_CRYPTO_PROTOCOL EDKII_CRYPTO_PPI;
|
||||
|
||||
extern GUID gEdkiiCryptoPpiGuid;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -7,8 +7,7 @@
|
|||
|
||||
**/
|
||||
|
||||
#ifndef __EDKII_CRYPTO_PROTOCOL_H__
|
||||
#define __EDKII_CRYPTO_PROTOCOL_H__
|
||||
#pragma once
|
||||
|
||||
#include <Base.h>
|
||||
#include <Library/BaseCryptLib.h>
|
||||
|
|
@ -5754,5 +5753,3 @@ struct _EDKII_CRYPTO_PROTOCOL {
|
|||
};
|
||||
|
||||
extern GUID gEdkiiCryptoProtocolGuid;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,8 +6,7 @@
|
|||
|
||||
**/
|
||||
|
||||
#ifndef __EDKII_SMM_CRYPTO_PROTOCOL_H__
|
||||
#define __EDKII_SMM_CRYPTO_PROTOCOL_H__
|
||||
#pragma once
|
||||
|
||||
#include <Protocol/Crypto.h>
|
||||
|
||||
|
|
@ -17,5 +16,3 @@
|
|||
typedef EDKII_CRYPTO_PROTOCOL EDKII_SMM_CRYPTO_PROTOCOL;
|
||||
|
||||
extern GUID gEdkiiSmmCryptoProtocolGuid;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,8 +6,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||
|
||||
**/
|
||||
|
||||
#ifndef __CRYPTEST_H__
|
||||
#define __CRYPTEST_H__
|
||||
#pragma once
|
||||
|
||||
#include <PiPei.h>
|
||||
#include <Uefi.h>
|
||||
|
|
@ -168,5 +167,3 @@ EFIAPI
|
|||
UefiTestMain (
|
||||
VOID
|
||||
);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue