Re: [PATCH v2 05/25] dtoc: Tidy up implementation of AddStringList()

2022-03-03 Thread Alper Nebi Yasak
On 24/02/2022 02:00, Simon Glass wrote:
> Refactor this to avoid a loop. Also add a test for an empty string.
> 
> Signed-off-by: Simon Glass 
> Suggested-by: Alper Nebi Yasak 
> ---
> 
> Changes in v2:
> - Add new patch to tidy up implementaiton of AddStringList()
> 
>  tools/dtoc/fdt.py  | 4 +---
>  tools/dtoc/test_fdt.py | 6 ++
>  2 files changed, 7 insertions(+), 3 deletions(-)

Reviewed-by: Alper Nebi Yasak 

> diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py
> index c16909a876..d933972918 100644
> --- a/tools/dtoc/fdt.py
> +++ b/tools/dtoc/fdt.py
> @@ -516,9 +516,7 @@ class Node:
>  Returns:
>  Prop added
>  """
> -out = b''
> -for string in val:
> -out += bytes(string, 'utf-8') + b'\0'
> +out = b'\0'.join(bytes(s, 'utf-8') for s in val) + b'\0' if val else 
> b''

Meh, it turned out uglier than I thought it would be. Either is fine
really, I didn't add "Reviewed-by"s for v1 only because I thought you'd
need to send a v2 for the later FIT stuff anyway.

>  return self.AddData(prop_name, out)
>  
>  def AddInt(self, prop_name, val):
>  
> [...]


[PATCH v2 05/25] dtoc: Tidy up implementation of AddStringList()

2022-02-23 Thread Simon Glass
Refactor this to avoid a loop. Also add a test for an empty string.

Signed-off-by: Simon Glass 
Suggested-by: Alper Nebi Yasak 
---

Changes in v2:
- Add new patch to tidy up implementaiton of AddStringList()

 tools/dtoc/fdt.py  | 4 +---
 tools/dtoc/test_fdt.py | 6 ++
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py
index c16909a876..d933972918 100644
--- a/tools/dtoc/fdt.py
+++ b/tools/dtoc/fdt.py
@@ -516,9 +516,7 @@ class Node:
 Returns:
 Prop added
 """
-out = b''
-for string in val:
-out += bytes(string, 'utf-8') + b'\0'
+out = b'\0'.join(bytes(s, 'utf-8') for s in val) + b'\0' if val else 
b''
 return self.AddData(prop_name, out)
 
 def AddInt(self, prop_name, val):
diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py
index c2013b9289..d33328c392 100755
--- a/tools/dtoc/test_fdt.py
+++ b/tools/dtoc/test_fdt.py
@@ -550,6 +550,12 @@ class TestProp(unittest.TestCase):
 data = self.fdt.getprop(self.node.Offset(), 'stringlist')
 self.assertEqual(b'123\x00456\0', data)
 
+val = []
+self.node.AddStringList('stringlist', val)
+self.dtb.Sync(auto_resize=True)
+data = self.fdt.getprop(self.node.Offset(), 'stringlist')
+self.assertEqual(b'', data)
+
 def test_delete_node(self):
 """Test deleting a node"""
 old_offset = self.fdt.path_offset('/spl-test')
-- 
2.35.1.574.g5d30c73bfb-goog