public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] BaseTools/DevicePath: fix GCC build error in print_mem(), and clean it up
@ 2018-01-02 17:16 Laszlo Ersek
  2018-01-03  1:26 ` Zhu, Yonghong
  0 siblings, 1 reply; 4+ messages in thread
From: Laszlo Ersek @ 2018-01-02 17:16 UTC (permalink / raw)
  To: edk2-devel-01; +Cc: Liming Gao, Yonghong Zhu

Currently "BaseTools/Source/C/DevicePath/DevicePath.c" fails to build with
GCC48:

> DevicePath.c: In function 'print_mem':
> DevicePath.c:109:5: error: 'for' loop initial declarations are only
> allowed in C99 mode
>      for (size_t i=0; i<n; i++) {
>      ^
> DevicePath.c:109:5: note: use option -std=c99 or -std=gnu99 to compile
> your code

In addition, the print_mem() function does not conform to the edk2 coding
style:

- we use CamelCase and no underscores in identifiers,
- the types and type qualifiers should follow the edk2 style,
- initialization as part of definition is forbidden for local variables.

Clean these up.

While updating the print_mem()/PrintMem() call sites, also remove the
superfluous parentheses around the second argument.

Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Fixes: 7dbc50bd244d95fdc1741b9cfc561f0bfd724de1
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---

Notes:
    Build-tested only (I don't have a DSC file with a device path PCD).

 BaseTools/Source/C/DevicePath/DevicePath.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/BaseTools/Source/C/DevicePath/DevicePath.c b/BaseTools/Source/C/DevicePath/DevicePath.c
index 4c87163209ab..76b8553b7145 100644
--- a/BaseTools/Source/C/DevicePath/DevicePath.c
+++ b/BaseTools/Source/C/DevicePath/DevicePath.c
@@ -103,11 +103,19 @@ Returns:
 }
 
 
-void print_mem(void const *vp, size_t n)
+STATIC
+VOID
+PrintMem (
+  CONST VOID *Buffer,
+  UINTN      Count
+  )
 {
-    unsigned char const *p = vp;
-    for (size_t i=0; i<n; i++) {
-        printf("0x%02x ", p[i]);
+  CONST UINT8 *Bytes;
+  UINTN       Idx;
+
+  Bytes = Buffer;
+  for (Idx = 0; Idx < Count; Idx++) {
+    printf("0x%02x ", Bytes[Idx]);
   }
 }
 
@@ -177,10 +185,10 @@ int main(int argc, CHAR8 *argv[])
   DevicePath = UefiDevicePathLibConvertTextToDevicePath(Str16);
   while (!((DevicePath->Type == END_DEVICE_PATH_TYPE) && (DevicePath->SubType == END_ENTIRE_DEVICE_PATH_SUBTYPE)) )
   {
-    print_mem(DevicePath, (DevicePath->Length[0] | DevicePath->Length[1] << 8));
+    PrintMem (DevicePath, DevicePath->Length[0] | DevicePath->Length[1] << 8);
     DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)((UINT8 *)DevicePath + (DevicePath->Length[0] | DevicePath->Length[1] << 8));
   }
-  print_mem(DevicePath, (DevicePath->Length[0] | DevicePath->Length[1] << 8));
+  PrintMem (DevicePath, DevicePath->Length[0] | DevicePath->Length[1] << 8);
   putchar('\n');
   return STATUS_SUCCESS;
 }
-- 
2.14.1.3.gb7cf6e02401b



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] BaseTools/DevicePath: fix GCC build error in print_mem(), and clean it up
  2018-01-02 17:16 [PATCH] BaseTools/DevicePath: fix GCC build error in print_mem(), and clean it up Laszlo Ersek
@ 2018-01-03  1:26 ` Zhu, Yonghong
  2018-01-03  8:37   ` Zhu, Yonghong
  0 siblings, 1 reply; 4+ messages in thread
From: Zhu, Yonghong @ 2018-01-03  1:26 UTC (permalink / raw)
  To: Laszlo Ersek, edk2-devel-01; +Cc: Gao, Liming, Zhu, Yonghong

Thanks.

Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com> 

Best Regards,
Zhu Yonghong


-----Original Message-----
From: Laszlo Ersek [mailto:lersek@redhat.com] 
Sent: Wednesday, January 03, 2018 1:17 AM
To: edk2-devel-01 <edk2-devel@lists.01.org>
Cc: Gao, Liming <liming.gao@intel.com>; Zhu, Yonghong <yonghong.zhu@intel.com>
Subject: [PATCH] BaseTools/DevicePath: fix GCC build error in print_mem(), and clean it up

Currently "BaseTools/Source/C/DevicePath/DevicePath.c" fails to build with
GCC48:

> DevicePath.c: In function 'print_mem':
> DevicePath.c:109:5: error: 'for' loop initial declarations are only 
> allowed in C99 mode
>      for (size_t i=0; i<n; i++) {
>      ^
> DevicePath.c:109:5: note: use option -std=c99 or -std=gnu99 to compile 
> your code

In addition, the print_mem() function does not conform to the edk2 coding
style:

- we use CamelCase and no underscores in identifiers,
- the types and type qualifiers should follow the edk2 style,
- initialization as part of definition is forbidden for local variables.

Clean these up.

While updating the print_mem()/PrintMem() call sites, also remove the superfluous parentheses around the second argument.

Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Fixes: 7dbc50bd244d95fdc1741b9cfc561f0bfd724de1
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---

Notes:
    Build-tested only (I don't have a DSC file with a device path PCD).

 BaseTools/Source/C/DevicePath/DevicePath.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/BaseTools/Source/C/DevicePath/DevicePath.c b/BaseTools/Source/C/DevicePath/DevicePath.c
index 4c87163209ab..76b8553b7145 100644
--- a/BaseTools/Source/C/DevicePath/DevicePath.c
+++ b/BaseTools/Source/C/DevicePath/DevicePath.c
@@ -103,11 +103,19 @@ Returns:
 }
 
 
-void print_mem(void const *vp, size_t n)
+STATIC
+VOID
+PrintMem (
+  CONST VOID *Buffer,
+  UINTN      Count
+  )
 {
-    unsigned char const *p = vp;
-    for (size_t i=0; i<n; i++) {
-        printf("0x%02x ", p[i]);
+  CONST UINT8 *Bytes;
+  UINTN       Idx;
+
+  Bytes = Buffer;
+  for (Idx = 0; Idx < Count; Idx++) {
+    printf("0x%02x ", Bytes[Idx]);
   }
 }
 
@@ -177,10 +185,10 @@ int main(int argc, CHAR8 *argv[])
   DevicePath = UefiDevicePathLibConvertTextToDevicePath(Str16);
   while (!((DevicePath->Type == END_DEVICE_PATH_TYPE) && (DevicePath->SubType == END_ENTIRE_DEVICE_PATH_SUBTYPE)) )
   {
-    print_mem(DevicePath, (DevicePath->Length[0] | DevicePath->Length[1] << 8));
+    PrintMem (DevicePath, DevicePath->Length[0] | DevicePath->Length[1] 
+ << 8);
     DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)((UINT8 *)DevicePath + (DevicePath->Length[0] | DevicePath->Length[1] << 8));
   }
-  print_mem(DevicePath, (DevicePath->Length[0] | DevicePath->Length[1] << 8));
+  PrintMem (DevicePath, DevicePath->Length[0] | DevicePath->Length[1] 
+ << 8);
   putchar('\n');
   return STATUS_SUCCESS;
 }
--
2.14.1.3.gb7cf6e02401b



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] BaseTools/DevicePath: fix GCC build error in print_mem(), and clean it up
  2018-01-03  1:26 ` Zhu, Yonghong
@ 2018-01-03  8:37   ` Zhu, Yonghong
  2018-01-03 14:56     ` Laszlo Ersek
  0 siblings, 1 reply; 4+ messages in thread
From: Zhu, Yonghong @ 2018-01-03  8:37 UTC (permalink / raw)
  To: 'Laszlo Ersek', 'edk2-devel-01'
  Cc: Gao, Liming, Zhu, Yonghong

I pushed this fix first since it blocked some GCC tool chain.

SHA-1: 9a6b445bc2e6e2db6f67ab3cc425d5831aa1b7c8 

Best Regards,
Zhu Yonghong


-----Original Message-----
From: Zhu, Yonghong 
Sent: Wednesday, January 3, 2018 9:27 AM
To: Laszlo Ersek <lersek@redhat.com>; edk2-devel-01 <edk2-devel@lists.01.org>
Cc: Gao, Liming <liming.gao@intel.com>; Zhu, Yonghong <yonghong.zhu@intel.com>
Subject: RE: [PATCH] BaseTools/DevicePath: fix GCC build error in print_mem(), and clean it up

Thanks.

Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com> 

Best Regards,
Zhu Yonghong


-----Original Message-----
From: Laszlo Ersek [mailto:lersek@redhat.com]
Sent: Wednesday, January 03, 2018 1:17 AM
To: edk2-devel-01 <edk2-devel@lists.01.org>
Cc: Gao, Liming <liming.gao@intel.com>; Zhu, Yonghong <yonghong.zhu@intel.com>
Subject: [PATCH] BaseTools/DevicePath: fix GCC build error in print_mem(), and clean it up

Currently "BaseTools/Source/C/DevicePath/DevicePath.c" fails to build with
GCC48:

> DevicePath.c: In function 'print_mem':
> DevicePath.c:109:5: error: 'for' loop initial declarations are only 
> allowed in C99 mode
>      for (size_t i=0; i<n; i++) {
>      ^
> DevicePath.c:109:5: note: use option -std=c99 or -std=gnu99 to compile 
> your code

In addition, the print_mem() function does not conform to the edk2 coding
style:

- we use CamelCase and no underscores in identifiers,
- the types and type qualifiers should follow the edk2 style,
- initialization as part of definition is forbidden for local variables.

Clean these up.

While updating the print_mem()/PrintMem() call sites, also remove the superfluous parentheses around the second argument.

Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Fixes: 7dbc50bd244d95fdc1741b9cfc561f0bfd724de1
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---

Notes:
    Build-tested only (I don't have a DSC file with a device path PCD).

 BaseTools/Source/C/DevicePath/DevicePath.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/BaseTools/Source/C/DevicePath/DevicePath.c b/BaseTools/Source/C/DevicePath/DevicePath.c
index 4c87163209ab..76b8553b7145 100644
--- a/BaseTools/Source/C/DevicePath/DevicePath.c
+++ b/BaseTools/Source/C/DevicePath/DevicePath.c
@@ -103,11 +103,19 @@ Returns:
 }
 
 
-void print_mem(void const *vp, size_t n)
+STATIC
+VOID
+PrintMem (
+  CONST VOID *Buffer,
+  UINTN      Count
+  )
 {
-    unsigned char const *p = vp;
-    for (size_t i=0; i<n; i++) {
-        printf("0x%02x ", p[i]);
+  CONST UINT8 *Bytes;
+  UINTN       Idx;
+
+  Bytes = Buffer;
+  for (Idx = 0; Idx < Count; Idx++) {
+    printf("0x%02x ", Bytes[Idx]);
   }
 }
 
@@ -177,10 +185,10 @@ int main(int argc, CHAR8 *argv[])
   DevicePath = UefiDevicePathLibConvertTextToDevicePath(Str16);
   while (!((DevicePath->Type == END_DEVICE_PATH_TYPE) && (DevicePath->SubType == END_ENTIRE_DEVICE_PATH_SUBTYPE)) )
   {
-    print_mem(DevicePath, (DevicePath->Length[0] | DevicePath->Length[1] << 8));
+    PrintMem (DevicePath, DevicePath->Length[0] | DevicePath->Length[1] 
+ << 8);
     DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)((UINT8 *)DevicePath + (DevicePath->Length[0] | DevicePath->Length[1] << 8));
   }
-  print_mem(DevicePath, (DevicePath->Length[0] | DevicePath->Length[1] << 8));
+  PrintMem (DevicePath, DevicePath->Length[0] | DevicePath->Length[1] 
+ << 8);
   putchar('\n');
   return STATUS_SUCCESS;
 }
--
2.14.1.3.gb7cf6e02401b



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] BaseTools/DevicePath: fix GCC build error in print_mem(), and clean it up
  2018-01-03  8:37   ` Zhu, Yonghong
@ 2018-01-03 14:56     ` Laszlo Ersek
  0 siblings, 0 replies; 4+ messages in thread
From: Laszlo Ersek @ 2018-01-03 14:56 UTC (permalink / raw)
  To: Zhu, Yonghong, 'edk2-devel-01'; +Cc: Gao, Liming

On 01/03/18 09:37, Zhu, Yonghong wrote:
> I pushed this fix first since it blocked some GCC tool chain.
> 
> SHA-1: 9a6b445bc2e6e2db6f67ab3cc425d5831aa1b7c8 
> 
> Best Regards,
> Zhu Yonghong

Thank you!
Laszlo

> 
> 
> -----Original Message-----
> From: Zhu, Yonghong 
> Sent: Wednesday, January 3, 2018 9:27 AM
> To: Laszlo Ersek <lersek@redhat.com>; edk2-devel-01 <edk2-devel@lists.01.org>
> Cc: Gao, Liming <liming.gao@intel.com>; Zhu, Yonghong <yonghong.zhu@intel.com>
> Subject: RE: [PATCH] BaseTools/DevicePath: fix GCC build error in print_mem(), and clean it up
> 
> Thanks.
> 
> Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com> 
> 
> Best Regards,
> Zhu Yonghong
> 
> 
> -----Original Message-----
> From: Laszlo Ersek [mailto:lersek@redhat.com]
> Sent: Wednesday, January 03, 2018 1:17 AM
> To: edk2-devel-01 <edk2-devel@lists.01.org>
> Cc: Gao, Liming <liming.gao@intel.com>; Zhu, Yonghong <yonghong.zhu@intel.com>
> Subject: [PATCH] BaseTools/DevicePath: fix GCC build error in print_mem(), and clean it up
> 
> Currently "BaseTools/Source/C/DevicePath/DevicePath.c" fails to build with
> GCC48:
> 
>> DevicePath.c: In function 'print_mem':
>> DevicePath.c:109:5: error: 'for' loop initial declarations are only 
>> allowed in C99 mode
>>      for (size_t i=0; i<n; i++) {
>>      ^
>> DevicePath.c:109:5: note: use option -std=c99 or -std=gnu99 to compile 
>> your code
> 
> In addition, the print_mem() function does not conform to the edk2 coding
> style:
> 
> - we use CamelCase and no underscores in identifiers,
> - the types and type qualifiers should follow the edk2 style,
> - initialization as part of definition is forbidden for local variables.
> 
> Clean these up.
> 
> While updating the print_mem()/PrintMem() call sites, also remove the superfluous parentheses around the second argument.
> 
> Cc: Liming Gao <liming.gao@intel.com>
> Cc: Yonghong Zhu <yonghong.zhu@intel.com>
> Fixes: 7dbc50bd244d95fdc1741b9cfc561f0bfd724de1
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Laszlo Ersek <lersek@redhat.com>
> ---
> 
> Notes:
>     Build-tested only (I don't have a DSC file with a device path PCD).
> 
>  BaseTools/Source/C/DevicePath/DevicePath.c | 20 ++++++++++++++------
>  1 file changed, 14 insertions(+), 6 deletions(-)
> 
> diff --git a/BaseTools/Source/C/DevicePath/DevicePath.c b/BaseTools/Source/C/DevicePath/DevicePath.c
> index 4c87163209ab..76b8553b7145 100644
> --- a/BaseTools/Source/C/DevicePath/DevicePath.c
> +++ b/BaseTools/Source/C/DevicePath/DevicePath.c
> @@ -103,11 +103,19 @@ Returns:
>  }
>  
>  
> -void print_mem(void const *vp, size_t n)
> +STATIC
> +VOID
> +PrintMem (
> +  CONST VOID *Buffer,
> +  UINTN      Count
> +  )
>  {
> -    unsigned char const *p = vp;
> -    for (size_t i=0; i<n; i++) {
> -        printf("0x%02x ", p[i]);
> +  CONST UINT8 *Bytes;
> +  UINTN       Idx;
> +
> +  Bytes = Buffer;
> +  for (Idx = 0; Idx < Count; Idx++) {
> +    printf("0x%02x ", Bytes[Idx]);
>    }
>  }
>  
> @@ -177,10 +185,10 @@ int main(int argc, CHAR8 *argv[])
>    DevicePath = UefiDevicePathLibConvertTextToDevicePath(Str16);
>    while (!((DevicePath->Type == END_DEVICE_PATH_TYPE) && (DevicePath->SubType == END_ENTIRE_DEVICE_PATH_SUBTYPE)) )
>    {
> -    print_mem(DevicePath, (DevicePath->Length[0] | DevicePath->Length[1] << 8));
> +    PrintMem (DevicePath, DevicePath->Length[0] | DevicePath->Length[1] 
> + << 8);
>      DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)((UINT8 *)DevicePath + (DevicePath->Length[0] | DevicePath->Length[1] << 8));
>    }
> -  print_mem(DevicePath, (DevicePath->Length[0] | DevicePath->Length[1] << 8));
> +  PrintMem (DevicePath, DevicePath->Length[0] | DevicePath->Length[1] 
> + << 8);
>    putchar('\n');
>    return STATUS_SUCCESS;
>  }
> --
> 2.14.1.3.gb7cf6e02401b
> 



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-01-03 14:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-02 17:16 [PATCH] BaseTools/DevicePath: fix GCC build error in print_mem(), and clean it up Laszlo Ersek
2018-01-03  1:26 ` Zhu, Yonghong
2018-01-03  8:37   ` Zhu, Yonghong
2018-01-03 14:56     ` Laszlo Ersek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox