Skip to contentSkip to conversation

vl: Abort if multiple machines are registered as default

PATCH Superseded Philippe Mathieu-Daudé 3 participants 6 messages Feb 7, 2020

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vl: Abort if multiple machines are registered as default

It would be confusing to have multiple default machines. Abort if this ever occurs.

---
 vl.c | 7 +++++++
 1 file changed, 7 insertions(+)
vl.c +7 -0
index 7dcb0879c4..da828188eb 100644
@@ -2354,6 +2354,8 @@ static MachineClass *machine_parse(const char *name, GSList *machines)
     GSList *el;
 
     if (is_help_option(name)) {
+        int default_count = 0;
+
         printf("Supported machines are:\n");
         machines = g_slist_sort(machines, machine_class_cmp);
         for (el = machines; el; el = el->next) {
@@ -2364,6 +2366,11 @@ static MachineClass *machine_parse(const char *name, GSList *machines)
             printf("%-20s %s%s%s\n", mc->name, mc->desc,
                    mc->is_default ? " (default)" : "",
                    mc->deprecation_reason ? " (deprecated)" : "");
+            default_count += !!mc->is_default;
+        }
+        if (default_count > 1) {
+            error_printf("Multiple default machines available\n");
+            abort();
         }
         exit(0);
     }
Signature · 1 line
2.21.1
#1 lore raw

Le 07/02/2020 à 12:02, Philippe Mathieu-Daudé a écrit :

Quoted 24 lines

It would be confusing to have multiple default machines. Abort if this ever occurs.

---
 vl.c | 7 +++++++
 1 file changed, 7 insertions(+)
vl.c +2 -0
index 7dcb0879c4..da828188eb 100644
@@ -2354,6 +2354,8 @@ static MachineClass *machine_parse(const char *name, GSList *machines)
     GSList *el;
 
     if (is_help_option(name)) {
+        int default_count = 0;
+
         printf("Supported machines are:\n");
         machines = g_slist_sort(machines, machine_class_cmp);
         for (el = machines; el; el = el->next) {
@@ -2364,6 +2366,11 @@ static MachineClass *machine_parse(const char *name, GSList *machines)
             printf("%-20s %s%s%s\n", mc->name, mc->desc,

vl.c static MachineClass *machine_parse(const char *name, GSList *machines) · line 2376

Quoted 10 lines
vl.c +5 -0
                    mc->is_default ? " (default)" : "",
                    mc->deprecation_reason ? " (deprecated)" : "");
+            default_count += !!mc->is_default;
+        }
+        if (default_count > 1) {
+            error_printf("Multiple default machines available\n");
+            abort();
         }
         exit(0);
     }

Does it really deserve an abort?
Ideal solution would be to be able to check this at build or in the unit tests.

Thanks,
Laurent

#5 lore raw
In reply to Philippe Mathieu-Daudé

Hi

Quoted 23 lines · Philippe Mathieu-Daudé

It would be confusing to have multiple default machines. Abort if this ever occurs.

---
 vl.c | 7 +++++++
 1 file changed, 7 insertions(+)
vl.c +2 -0
index 7dcb0879c4..da828188eb 100644
@@ -2354,6 +2354,8 @@ static MachineClass *machine_parse(const char *name, GSList *machines)
     GSList *el;
 
     if (is_help_option(name)) {
+        int default_count = 0;
+
         printf("Supported machines are:\n");
         machines = g_slist_sort(machines, machine_class_cmp);
         for (el = machines; el; el = el->next) {

vl.c static MachineClass *machine_parse(const char *name, GSList *machines) · line 2373

Quoted 8 lines
vl.c +5 -0
@@ -2364,6 +2366,11 @@ static MachineClass *machine_parse(const char *name, GSList *machines)
             printf("%-20s %s%s%s\n", mc->name, mc->desc,
                    mc->is_default ? " (default)" : "",
                    mc->deprecation_reason ? " (deprecated)" : "");
+            default_count += !!mc->is_default;
+        }
+        if (default_count > 1) {
+            error_printf("Multiple default machines available\n");
+            abort();

looks ok

It's a build-time issue? If the user can't do anything about it, you may simply have an assert(default_count <= 1) rather than a human-friendly string, I think.

Signature · 1 line
Marc-André Lureau
#2 lore raw
In reply to Laurent Vivier
Quoted 31 lines · Laurent Vivier

Le 07/02/2020 à 12:02, Philippe Mathieu-Daudé a écrit :

Quoted 30 lines

It would be confusing to have multiple default machines. Abort if this ever occurs.

---
  vl.c | 7 +++++++
  1 file changed, 7 insertions(+)
vl.c +7 -0
index 7dcb0879c4..da828188eb 100644
@@ -2354,6 +2354,8 @@ static MachineClass *machine_parse(const char *name, GSList *machines)
      GSList *el;
 
      if (is_help_option(name)) {
+        int default_count = 0;
+
          printf("Supported machines are:\n");
          machines = g_slist_sort(machines, machine_class_cmp);
          for (el = machines; el; el = el->next) {
@@ -2364,6 +2366,11 @@ static MachineClass *machine_parse(const char *name, GSList *machines)
              printf("%-20s %s%s%s\n", mc->name, mc->desc,
                     mc->is_default ? " (default)" : "",
                     mc->deprecation_reason ? " (deprecated)" : "");
+            default_count += !!mc->is_default;
+        }
+        if (default_count > 1) {
+            error_printf("Multiple default machines available\n");
+            abort();
Quoted 8 lines

vl.c static MachineClass *machine_parse(const char *name, GSList *machines) · line 2376

Quoted 4 lines
vl.c +0 -0
          }
          exit(0);
      }

Does it really deserve an abort?
Ideal solution would be to be able to check this at build or in the unit tests.

This is for developers, not for users. I'll use Marc-André suggestion and use an assertion.

#3 lore raw

Le 07/02/2020 à 12:25, Philippe Mathieu-Daudé a écrit :

Quoted 42 lines · Laurent Vivier
Quoted 32 lines

Le 07/02/2020 à 12:02, Philippe Mathieu-Daudé a écrit :

Quoted 31 lines

It would be confusing to have multiple default machines. Abort if this ever occurs.

---
  vl.c | 7 +++++++

  1 file changed, 7 insertions(+)
vl.c +7 -0
index 7dcb0879c4..da828188eb 100644
@@ -2354,6 +2354,8 @@ static MachineClass *machine_parse(const char
 *name, GSList *machines)
       GSList *el;
         if (is_help_option(name)) {
+        int default_count = 0;
+
           printf("Supported machines are:\n");
           machines = g_slist_sort(machines, machine_class_cmp);
           for (el = machines; el; el = el->next) {
@@ -2364,6 +2366,11 @@ static MachineClass *machine_parse(const char
 *name, GSList *machines)
               printf("%-20s %s%s%s\n", mc->name, mc->desc,
                      mc->is_default ? " (default)" : "",
                      mc->deprecation_reason ? " (deprecated)" : "");
+            default_count += !!mc->is_default;
+        }
+        if (default_count > 1) {
+            error_printf("Multiple default machines available\n");
+            abort();
Quoted 8 lines
Quoted 4 lines
vl.c +0 -0
           }
           exit(0);

      }

Does it really deserve an abort?
Ideal solution would be to be able to check this at build or in the unit tests.

Quoted 2 lines

This is for developers, not for users. I'll use Marc-André suggestion and use an assertion.

I agree, but it's why it would be better if it is detected before it comes to the user.

Perhaps you can add a test to run "qemu -h" to trigger the abort() early in the develompment process (if it doesn't already exist).

Thanks,
Laurent
Thanks,
LAurent

#4 lore raw

Le 07/02/2020 à 12:28, Laurent Vivier a écrit :

Quoted 43 lines

Le 07/02/2020 à 12:25, Philippe Mathieu-Daudé a écrit :

Quoted 42 lines · Laurent Vivier
Quoted 40 lines

Le 07/02/2020 à 12:02, Philippe Mathieu-Daudé a écrit :

Quoted 33 lines

It would be confusing to have multiple default machines. Abort if this ever occurs.

---
  vl.c | 7 +++++++

  1 file changed, 7 insertions(+)
vl.c +7 -0
index 7dcb0879c4..da828188eb 100644
@@ -2354,6 +2354,8 @@ static MachineClass *machine_parse(const char
 *name, GSList *machines)
       GSList *el;
         if (is_help_option(name)) {
+        int default_count = 0;
+
           printf("Supported machines are:\n");
           machines = g_slist_sort(machines, machine_class_cmp);
           for (el = machines; el; el = el->next) {
@@ -2364,6 +2366,11 @@ static MachineClass *machine_parse(const char
 *name, GSList *machines)
               printf("%-20s %s%s%s\n", mc->name, mc->desc,
                      mc->is_default ? " (default)" : "",
                      mc->deprecation_reason ? " (deprecated)" : "");
+            default_count += !!mc->is_default;
+        }
+        if (default_count > 1) {
+            error_printf("Multiple default machines available\n");
+            abort();
           }
           exit(0);
Quoted 2 lines

      }

Does it really deserve an abort?
Ideal solution would be to be able to check this at build or in the unit tests.

Quoted 8 lines
Quoted 2 lines

This is for developers, not for users. I'll use Marc-André suggestion and use an assertion.

I agree, but it's why it would be better if it is detected before it comes to the user.

Perhaps you can add a test to run "qemu -h" to trigger the abort() early in the develompment process (if it doesn't already exist).

I mean "-M help".

Thanks,
Laurent