mirror of
https://github.com/tianocore/edk2
synced 2026-08-27 00:23:19 -04:00
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.
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>
123 lines
7.6 KiB
C
123 lines
7.6 KiB
C
/** @file
|
|
|
|
Copyright (c) 2017 - 2019, ARM Limited. All rights reserved.
|
|
|
|
SPDX-License-Identifier: BSD-2-Clause-Patent
|
|
|
|
@par Glossary:
|
|
- Cm or CM - Configuration Manager
|
|
- Obj or OBJ - Object
|
|
**/
|
|
|
|
#pragma once
|
|
|
|
/** The GET_OBJECT_LIST macro expands to a function that is used to retrieve
|
|
an object or an object list from the Configuration Manager using the
|
|
Configuration Manager Protocol interface.
|
|
|
|
The macro expands to a function which has the following prototype:
|
|
|
|
STATIC
|
|
EFI_STATUS
|
|
EFIAPI
|
|
Get<CmObjectId> (
|
|
IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol,
|
|
IN CONST CM_OBJECT_TOKEN Token OPTIONAL,
|
|
OUT Type ** List,
|
|
OUT UINT32 * Count OPTIONAL
|
|
);
|
|
|
|
Generated function parameters:
|
|
@param [in] CfgMgrProtocol Pointer to the Configuration Manager protocol
|
|
interface.
|
|
@param [in] Token Reference token for the Object.
|
|
@param [out] List Pointer to the Object list.
|
|
@param [out] Count Count of the objects returned in the list.
|
|
|
|
Macro Parameters:
|
|
@param [in] CmObjectNameSpace The Object Namespace
|
|
@param [in] CmObjectId Object Id.
|
|
@param [in] Type Structure used to describe the Object.
|
|
|
|
@retval EFI_SUCCESS Success.
|
|
@retval EFI_INVALID_PARAMETER A parameter is invalid.
|
|
@retval EFI_NOT_FOUND The required object information is not found.
|
|
@retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration
|
|
Manager is less than the Object size for the
|
|
requested object.
|
|
**/
|
|
#define GET_OBJECT_LIST(CmObjectNameSpace, CmObjectId, Type) \
|
|
STATIC \
|
|
EFI_STATUS \
|
|
EFIAPI \
|
|
Get##CmObjectId ( \
|
|
IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol, \
|
|
IN CONST CM_OBJECT_TOKEN Token OPTIONAL, \
|
|
OUT Type ** List, \
|
|
OUT UINT32 * CONST Count OPTIONAL \
|
|
) \
|
|
{ \
|
|
EFI_STATUS Status; \
|
|
CM_OBJ_DESCRIPTOR CmObjectDesc; \
|
|
UINT32 ObjCount = 0; \
|
|
if (List == NULL) { \
|
|
Status = EFI_INVALID_PARAMETER; \
|
|
DEBUG (( \
|
|
DEBUG_ERROR, \
|
|
"ERROR: Get" #CmObjectId ": Invalid out parameter for" \
|
|
" object list. Status = %r\n", \
|
|
Status \
|
|
)); \
|
|
goto error_handler; \
|
|
} \
|
|
Status = CfgMgrProtocol->GetObject ( \
|
|
CfgMgrProtocol, \
|
|
CREATE_CM_OBJECT_ID ( \
|
|
CmObjectNameSpace, \
|
|
CmObjectId \
|
|
), \
|
|
Token, \
|
|
&CmObjectDesc \
|
|
); \
|
|
if (EFI_ERROR (Status)) { \
|
|
DEBUG (( \
|
|
DEBUG_INFO, \
|
|
"INFO: Get" #CmObjectId ": Platform does not implement " \
|
|
#CmObjectId ". Status = %r\n", \
|
|
Status \
|
|
)); \
|
|
*List = NULL; \
|
|
goto error_handler; \
|
|
} \
|
|
if (CmObjectDesc.ObjectId != \
|
|
CREATE_CM_OBJECT_ID (CmObjectNameSpace, CmObjectId)) { \
|
|
DEBUG (( \
|
|
DEBUG_ERROR, \
|
|
"ERROR: Get" #CmObjectId ": " #CmObjectId \
|
|
": Invalid ObjectId = 0x%x\n, expected Id = 0x%x\n", \
|
|
CmObjectDesc.ObjectId, \
|
|
CREATE_CM_OBJECT_ID (CmObjectNameSpace, CmObjectId) \
|
|
)); \
|
|
ASSERT (FALSE); \
|
|
Status = EFI_INVALID_PARAMETER; \
|
|
goto error_handler; \
|
|
} \
|
|
if (CmObjectDesc.Size < (sizeof (Type) * CmObjectDesc.Count)) { \
|
|
DEBUG (( \
|
|
DEBUG_ERROR, \
|
|
"ERROR: Get" #CmObjectId ": " #CmObjectId \
|
|
": Buffer too small, size = 0x%x\n", \
|
|
CmObjectDesc.Size \
|
|
)); \
|
|
ASSERT (FALSE); \
|
|
Status = EFI_BAD_BUFFER_SIZE; \
|
|
goto error_handler; \
|
|
} \
|
|
ObjCount = CmObjectDesc.Count; \
|
|
*List = (Type*)CmObjectDesc.Data; \
|
|
error_handler: \
|
|
if (Count != NULL) { \
|
|
*Count = ObjCount; \
|
|
} \
|
|
return Status; \
|
|
}
|