From: "Pedro Falcato" <pedro.falcato@gmail.com>
To: devel@edk2.groups.io
Cc: Michael D Kinney <michael.d.kinney@intel.com>,
Liming Gao <gaoliming@byosoft.com.cn>,
Zhiguang Liu <zhiguang.liu@intel.com>
Subject: [PATCH v2] MdePkg/BasePrintLib: Add %z specifier
Date: Tue, 5 Jul 2022 02:16:22 +0100 [thread overview]
Message-ID: <20220705011622.351454-1-pedro.falcato@gmail.com> (raw)
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3977
%z is used in standard C99 as the printf specifier for size_t types.
Add support for it so we can portably print UINTN.
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Signed-off-by: Pedro Falcato <pedro.falcato@gmail.com>
---
MdePkg/Include/Library/PrintLib.h | 13 ++++++++-----
MdePkg/Library/BasePrintLib/PrintLibInternal.c | 9 +++++++++
MdePkg/Library/BasePrintLib/PrintLibInternal.h | 1 +
3 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/MdePkg/Include/Library/PrintLib.h b/MdePkg/Include/Library/PrintLib.h
index 8d523cac52..0d67f62d3f 100644
--- a/MdePkg/Include/Library/PrintLib.h
+++ b/MdePkg/Include/Library/PrintLib.h
@@ -42,6 +42,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
- L, l
- The number being printed is size UINT64. Only valid for types X, x, and d.
If this flag is not specified, then the number being printed is size int.
+ - z
+ - The number being printed is of size UINTN. Only valid for types X, x and d.
+ If this flag is not specified, then the number being printed is size int.
- NOTE: All invalid flags are ignored.
[width]:
@@ -73,18 +76,18 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
using this type too by making sure bits 8..15 of the argument are set to 0.
- x
- The argument is an unsigned hexadecimal number. The characters used are 0..9 and
- A..F. If the flag 'L' is not specified, then the argument is assumed
+ A..F. If the flags 'L', 'z' are not specified, then the argument is assumed
to be size int. This does not follow ANSI C.
- X
- The argument is an unsigned hexadecimal number and the number is padded with
- zeros. This is equivalent to a format string of "0x". If the flag
- 'L' is not specified, then the argument is assumed to be size int.
+ zeros. This is equivalent to a format string of "0x". If the flags
+ 'L', 'z' are not specified, then the argument is assumed to be size int.
This does not follow ANSI C.
- d
- - The argument is a signed decimal number. If the flag 'L' is not specified,
+ - The argument is a signed decimal number. If the flags 'L', 'z' are not specified,
then the argument is assumed to be size int.
- u
- - The argument is a unsigned decimal number. If the flag 'L' is not specified,
+ - The argument is a unsigned decimal number. If the flags 'L'. 'z' are not specified,
then the argument is assumed to be size int.
- p
- The argument is a pointer that is a (VOID *), and it is printed as an
diff --git a/MdePkg/Library/BasePrintLib/PrintLibInternal.c b/MdePkg/Library/BasePrintLib/PrintLibInternal.c
index 42b598a432..1cd99b2213 100644
--- a/MdePkg/Library/BasePrintLib/PrintLibInternal.c
+++ b/MdePkg/Library/BasePrintLib/PrintLibInternal.c
@@ -720,6 +720,9 @@ BasePrintLibSPrintMarker (
case 'l':
Flags |= LONG_TYPE;
break;
+ case 'z':
+ Flags |= SIZET_TYPE;
+ break;
case '*':
if ((Flags & PRECISION) == 0) {
Flags |= PAD_TO_WIDTH;
@@ -833,6 +836,12 @@ BasePrintLibSPrintMarker (
} else {
Value = BASE_ARG (BaseListMarker, int);
}
+ } else if ((Flags & SIZET_TYPE) != 0) {
+ if (BaseListMarker == NULL) {
+ Value = VA_ARG (VaListMarker, UINTN);
+ } else {
+ Value = BASE_ARG (BaseListMarker, UINTN);
+ }
} else {
if (BaseListMarker == NULL) {
Value = VA_ARG (VaListMarker, INT64);
diff --git a/MdePkg/Library/BasePrintLib/PrintLibInternal.h b/MdePkg/Library/BasePrintLib/PrintLibInternal.h
index 34d591c6fc..9193e6192b 100644
--- a/MdePkg/Library/BasePrintLib/PrintLibInternal.h
+++ b/MdePkg/Library/BasePrintLib/PrintLibInternal.h
@@ -29,6 +29,7 @@
#define ARGUMENT_REVERSED BIT12
#define COUNT_ONLY_NO_PRINT BIT13
#define UNSIGNED_TYPE BIT14
+#define SIZET_TYPE BIT15
//
// Record date and time information
--
2.37.0
next reply other threads:[~2022-07-05 1:16 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-05 1:16 Pedro Falcato [this message]
2022-07-06 18:22 ` [edk2-devel] [PATCH v2] MdePkg/BasePrintLib: Add %z specifier Michael D Kinney
2022-07-06 22:27 ` Pedro Falcato
2022-07-12 20:46 ` Michael D Kinney
2022-07-12 21:33 ` Pedro Falcato
2022-07-12 22:02 ` Michael D Kinney
2022-07-12 22:30 ` Pedro Falcato
2022-07-15 16:30 ` Michael D Kinney
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220705011622.351454-1-pedro.falcato@gmail.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox