qemu-riscv
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH for-8.2 v2 5/7] target/riscv/cpu.c: add a ADD_CPU_PROPERTIES_


From: Daniel Henrique Barboza
Subject: Re: [PATCH for-8.2 v2 5/7] target/riscv/cpu.c: add a ADD_CPU_PROPERTIES_ARRAY() macro
Date: Thu, 13 Jul 2023 18:27:05 -0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0



On 7/13/23 17:40, Richard Henderson wrote:
On 7/12/23 21:57, Daniel Henrique Barboza wrote:
+#define ADD_CPU_PROPERTIES_ARRAY(_dev, _array) \
+    for (prop = _array; prop && prop->name; prop++) { \
+        qdev_property_add_static(_dev, prop); \
+    } \

do { } while(0)

Watch the \ on the last line of the macro.
Declare the iterator within the macro, rather than use one defined in the outer 
scope.

Like this?

#define ADD_CPU_PROPERTIES_ARRAY(_dev, _array) \
    do { \
        Property *prop; \
        for (prop = _array; prop && prop->name; prop++) { \
            qdev_property_add_static(_dev, prop); \
        } \
    } while(0)

Why not use ARRAY_SIZE?

Hm, the arrays are finishing with DEFINE_PROP_END_OF_LIST() (I copied the 
existing
array structure), which adds an empty element, so ARRAY_SIZE will get empty 
stuff
in the end.

Since these are new arrays I can get rid of the end_of_list blank element and 
use
ARRAY_SIZE().


Daniel


r~



reply via email to

[Prev in Thread] Current Thread [Next in Thread]