MdePkg: Add a new macro VA_COPY for variable argument support. Fix a bug in the UefiLib instance that there is a non portable assumption that Marker is copied when passed to a function.

Signed-off-by: rsun3
Reviewed-by: mdkinney


git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13025 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
rsun3 2012-02-22 02:39:57 +00:00
parent 53c31c5164
commit 265fa9fa39
2 changed files with 23 additions and 2 deletions

View File

@ -6,7 +6,7 @@
environment. There are a set of base libraries in the Mde Package that can environment. There are a set of base libraries in the Mde Package that can
be used to implement base modules. be used to implement base modules.
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR> Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR> Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
@ -393,6 +393,7 @@ struct _LIST_ENTRY {
// VA_END (VA_LIST Marker) - Clear Marker // VA_END (VA_LIST Marker) - Clear Marker
// VA_ARG (VA_LIST Marker, var arg size) - Use Marker to get an argument from // VA_ARG (VA_LIST Marker, var arg size) - Use Marker to get an argument from
// the ... list. You must know the size and pass it in this macro. // the ... list. You must know the size and pass it in this macro.
// VA_COPY (VA_LIST Dest, VA_LIST Start) - Initialize Dest as a copy of Start.
// //
// example: // example:
// //
@ -454,6 +455,8 @@ struct _LIST_ENTRY {
#define VA_END(Marker) ((void)0) #define VA_END(Marker) ((void)0)
#define VA_COPY(Dest, Start) __va_copy (Dest, Start)
#elif defined(__GNUC__) && !defined(NO_BUILTIN_VA_FUNCS) #elif defined(__GNUC__) && !defined(NO_BUILTIN_VA_FUNCS)
// //
// Use GCC built-in macros for variable argument lists. // Use GCC built-in macros for variable argument lists.
@ -471,6 +474,8 @@ typedef __builtin_va_list VA_LIST;
#define VA_END(Marker) __builtin_va_end (Marker) #define VA_END(Marker) __builtin_va_end (Marker)
#define VA_COPY(Dest, Start) __builtin_va_copy (Dest, Start)
#else #else
/// ///
/// Variable used to traverse the list of arguments. This type can vary by /// Variable used to traverse the list of arguments. This type can vary by
@ -526,6 +531,19 @@ typedef CHAR8 *VA_LIST;
**/ **/
#define VA_END(Marker) (Marker = (VA_LIST) 0) #define VA_END(Marker) (Marker = (VA_LIST) 0)
/**
Initializes a VA_LIST as a copy of an existing VA_LIST.
This macro initializes Dest as a copy of Start, as if the VA_START macro had been applied to Dest
followed by the same sequence of uses of the VA_ARG macro as had previously been used to reach
the present state of Start.
@param Dest VA_LIST used to traverse the list of arguments.
@param Start VA_LIST used to traverse the list of arguments.
**/
#define VA_COPY(Dest, Start) ((void)((Dest) = (Start)))
#endif #endif
/// ///

View File

@ -742,8 +742,11 @@ CatVSPrint (
UINTN CharactersRequired; UINTN CharactersRequired;
UINTN SizeRequired; UINTN SizeRequired;
CHAR16 *BufferToReturn; CHAR16 *BufferToReturn;
VA_LIST ExtraMarker;
CharactersRequired = SPrintLength(FormatString, Marker); VA_COPY (ExtraMarker, Marker);
CharactersRequired = SPrintLength(FormatString, ExtraMarker);
VA_END (ExtraMarker);
if (String != NULL) { if (String != NULL) {
SizeRequired = StrSize(String) + (CharactersRequired * sizeof(CHAR16)); SizeRequired = StrSize(String) + (CharactersRequired * sizeof(CHAR16));