[PATCH 09/10] tests/aio-multithread: Clean up global variable shadowing

Philippe Mathieu-Daudé posted 10 patches 1 year, 1 month ago
Maintainers: John Snow <jsnow@redhat.com>, Thomas Huth <thuth@redhat.com>, Laurent Vivier <lvivier@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Tyrone Ting <kfting@nuvoton.com>, Hao Wu <wuhaotsh@google.com>, Fam Zheng <fam@euphon.net>, Stefan Hajnoczi <stefanha@redhat.com>, Kevin Wolf <kwolf@redhat.com>, Alberto Garcia <berto@igalia.com>
[PATCH 09/10] tests/aio-multithread: Clean up global variable shadowing
Posted by Philippe Mathieu-Daudé 1 year, 1 month ago
Rename the argument to avoid:

  tests/unit/test-aio-multithread.c:226:37: error: declaration shadows a variable in the global scope [-Werror,-Wshadow]
  static void test_multi_co_mutex(int threads, int seconds)
                                      ^
  tests/unit/test-aio-multithread.c:401:34: error: declaration shadows a variable in the global scope [-Werror,-Wshadow]
  static void test_multi_mutex(int threads, int seconds)
                                   ^
  tests/unit/test-aio-multithread.c:24:18: note: previous declaration is here
  static IOThread *threads[NUM_CONTEXTS];
                   ^

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 tests/unit/test-aio-multithread.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/tests/unit/test-aio-multithread.c b/tests/unit/test-aio-multithread.c
index 08d4570ccb..d587f20667 100644
--- a/tests/unit/test-aio-multithread.c
+++ b/tests/unit/test-aio-multithread.c
@@ -223,7 +223,7 @@ static void coroutine_fn test_multi_co_mutex_entry(void *opaque)
     qatomic_dec(&running);
 }
 
-static void test_multi_co_mutex(int threads, int seconds)
+static void test_multi_co_mutex(unsigned ctx_num, int seconds)
 {
     int i;
 
@@ -233,9 +233,9 @@ static void test_multi_co_mutex(int threads, int seconds)
     now_stopping = false;
 
     create_aio_contexts();
-    assert(threads <= NUM_CONTEXTS);
-    running = threads;
-    for (i = 0; i < threads; i++) {
+    assert(ctx_num <= NUM_CONTEXTS);
+    running = ctx_num;
+    for (i = 0; i < ctx_num; i++) {
         Coroutine *co1 = qemu_coroutine_create(test_multi_co_mutex_entry, NULL);
         aio_co_schedule(ctx[i], co1);
     }
@@ -398,7 +398,7 @@ static void test_multi_mutex_entry(void *opaque)
     qatomic_dec(&running);
 }
 
-static void test_multi_mutex(int threads, int seconds)
+static void test_multi_mutex(unsigned ctx_num, int seconds)
 {
     int i;
 
@@ -408,9 +408,9 @@ static void test_multi_mutex(int threads, int seconds)
     now_stopping = false;
 
     create_aio_contexts();
-    assert(threads <= NUM_CONTEXTS);
-    running = threads;
-    for (i = 0; i < threads; i++) {
+    assert(ctx_num <= NUM_CONTEXTS);
+    running = ctx_num;
+    for (i = 0; i < ctx_num; i++) {
         Coroutine *co1 = qemu_coroutine_create(test_multi_mutex_entry, NULL);
         aio_co_schedule(ctx[i], co1);
     }
-- 
2.41.0


Re: [PATCH 09/10] tests/aio-multithread: Clean up global variable shadowing
Posted by Thomas Huth 1 year, 1 month ago
On 09/10/2023 12.02, Philippe Mathieu-Daudé wrote:
> Rename the argument to avoid:
> 
>    tests/unit/test-aio-multithread.c:226:37: error: declaration shadows a variable in the global scope [-Werror,-Wshadow]
>    static void test_multi_co_mutex(int threads, int seconds)
>                                        ^
>    tests/unit/test-aio-multithread.c:401:34: error: declaration shadows a variable in the global scope [-Werror,-Wshadow]
>    static void test_multi_mutex(int threads, int seconds)
>                                     ^
>    tests/unit/test-aio-multithread.c:24:18: note: previous declaration is here
>    static IOThread *threads[NUM_CONTEXTS];
>                     ^
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   tests/unit/test-aio-multithread.c | 16 ++++++++--------
>   1 file changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/tests/unit/test-aio-multithread.c b/tests/unit/test-aio-multithread.c
> index 08d4570ccb..d587f20667 100644
> --- a/tests/unit/test-aio-multithread.c
> +++ b/tests/unit/test-aio-multithread.c
> @@ -223,7 +223,7 @@ static void coroutine_fn test_multi_co_mutex_entry(void *opaque)
>       qatomic_dec(&running);
>   }
>   
> -static void test_multi_co_mutex(int threads, int seconds)
> +static void test_multi_co_mutex(unsigned ctx_num, int seconds)

Why did you change the type of the variable? ... you should at least mention 
this in the commit description.

>   {
>       int i;
>   
> @@ -233,9 +233,9 @@ static void test_multi_co_mutex(int threads, int seconds)
>       now_stopping = false;
>   
>       create_aio_contexts();
> -    assert(threads <= NUM_CONTEXTS);
> -    running = threads;
> -    for (i = 0; i < threads; i++) {
> +    assert(ctx_num <= NUM_CONTEXTS);
> +    running = ctx_num;
> +    for (i = 0; i < ctx_num; i++) {
>           Coroutine *co1 = qemu_coroutine_create(test_multi_co_mutex_entry, NULL);
>           aio_co_schedule(ctx[i], co1);
>       }
> @@ -398,7 +398,7 @@ static void test_multi_mutex_entry(void *opaque)
>       qatomic_dec(&running);
>   }
>   
> -static void test_multi_mutex(int threads, int seconds)
> +static void test_multi_mutex(unsigned ctx_num, int seconds)

dito.

  Thomas

>   {
>       int i;
>   
> @@ -408,9 +408,9 @@ static void test_multi_mutex(int threads, int seconds)
>       now_stopping = false;
>   
>       create_aio_contexts();
> -    assert(threads <= NUM_CONTEXTS);
> -    running = threads;
> -    for (i = 0; i < threads; i++) {
> +    assert(ctx_num <= NUM_CONTEXTS);
> +    running = ctx_num;
> +    for (i = 0; i < ctx_num; i++) {
>           Coroutine *co1 = qemu_coroutine_create(test_multi_mutex_entry, NULL);
>           aio_co_schedule(ctx[i], co1);
>       }