[05/16] vl: introduce object_parse_property_opt
diff mbox series

Message ID 1573655945-14912-6-git-send-email-pbonzini@redhat.com
State New
Headers show
Series
  • Complete the implementation of -accel
Related show

Commit Message

Paolo Bonzini Nov. 13, 2019, 2:38 p.m. UTC
We will reuse the parsing loop of machine_set_property soon for "-accel",
but we do not want the "_" -> "-" conversion since "-accel" can just
standardize on dashes.  We will also add a bunch of legacy option handling
to keep the QOM machine object clean.  Extract the loop into a separate
function, and keep the legacy handling in machine_set_property.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 vl.c | 38 +++++++++++++++++++++++---------------
 1 file changed, 23 insertions(+), 15 deletions(-)

Comments

Marc-André Lureau Nov. 14, 2019, 8:23 a.m. UTC | #1
On Wed, Nov 13, 2019 at 6:42 PM Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> We will reuse the parsing loop of machine_set_property soon for "-accel",
> but we do not want the "_" -> "-" conversion since "-accel" can just
> standardize on dashes.  We will also add a bunch of legacy option handling
> to keep the QOM machine object clean.  Extract the loop into a separate
> function, and keep the legacy handling in machine_set_property.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  vl.c | 38 +++++++++++++++++++++++---------------
>  1 file changed, 23 insertions(+), 15 deletions(-)
>
> diff --git a/vl.c b/vl.c
> index dbc99d7..b93217d 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -2617,27 +2617,17 @@ static MachineClass *select_machine(void)
>      return machine_class;
>  }
>
> -static int machine_set_property(void *opaque,
> -                                const char *name, const char *value,
> -                                Error **errp)
> +static int object_parse_property_opt(Object *obj,
> +                                     const char *name, const char *value,
> +                                     const char *skip, Error **errp)
>  {
> -    Object *obj = OBJECT(opaque);
>      Error *local_err = NULL;
> -    char *p, *qom_name;
>
> -    if (strcmp(name, "type") == 0) {
> +    if (g_str_equal(name, skip)) {
>          return 0;
>      }
>
> -    qom_name = g_strdup(name);
> -    for (p = qom_name; *p; p++) {
> -        if (*p == '_') {
> -            *p = '-';
> -        }
> -    }
> -
> -    object_property_parse(obj, value, qom_name, &local_err);
> -    g_free(qom_name);
> +    object_property_parse(obj, value, name, &local_err);
>
>      if (local_err) {
>          error_propagate(errp, local_err);
> @@ -2647,6 +2637,24 @@ static int machine_set_property(void *opaque,
>      return 0;
>  }
>
> +static int machine_set_property(void *opaque,
> +                                const char *name, const char *value,
> +                                Error **errp)
> +{
> +    char *qom_name = g_strdup(name);

Could use g_autofree, and thus return directly without r.



> +    char *p;
> +    int r;
> +
> +    for (p = qom_name; *p; p++) {
> +        if (*p == '_') {
> +            *p = '-';
> +        }
> +    }
> +
> +    r = object_parse_property_opt(opaque, name, value, "type", errp);

You want to pass qom_name, I guess

> +    g_free(qom_name);
> +    return r;
> +}
>
>  /*
>   * Initial object creation happens before all other
> --
> 1.8.3.1
>
>
>


--
Marc-André Lureau
Paolo Bonzini Nov. 14, 2019, 9:46 a.m. UTC | #2
On 14/11/19 09:23, Marc-André Lureau wrote:
>> +{
>> +    char *qom_name = g_strdup(name);
> Could use g_autofree, and thus return directly without r.

And avoid a bunch of memory leaks in the rest of the series.

Paolo

Patch
diff mbox series

diff --git a/vl.c b/vl.c
index dbc99d7..b93217d 100644
--- a/vl.c
+++ b/vl.c
@@ -2617,27 +2617,17 @@  static MachineClass *select_machine(void)
     return machine_class;
 }
 
-static int machine_set_property(void *opaque,
-                                const char *name, const char *value,
-                                Error **errp)
+static int object_parse_property_opt(Object *obj,
+                                     const char *name, const char *value,
+                                     const char *skip, Error **errp)
 {
-    Object *obj = OBJECT(opaque);
     Error *local_err = NULL;
-    char *p, *qom_name;
 
-    if (strcmp(name, "type") == 0) {
+    if (g_str_equal(name, skip)) {
         return 0;
     }
 
-    qom_name = g_strdup(name);
-    for (p = qom_name; *p; p++) {
-        if (*p == '_') {
-            *p = '-';
-        }
-    }
-
-    object_property_parse(obj, value, qom_name, &local_err);
-    g_free(qom_name);
+    object_property_parse(obj, value, name, &local_err);
 
     if (local_err) {
         error_propagate(errp, local_err);
@@ -2647,6 +2637,24 @@  static int machine_set_property(void *opaque,
     return 0;
 }
 
+static int machine_set_property(void *opaque,
+                                const char *name, const char *value,
+                                Error **errp)
+{
+    char *qom_name = g_strdup(name);
+    char *p;
+    int r;
+
+    for (p = qom_name; *p; p++) {
+        if (*p == '_') {
+            *p = '-';
+        }
+    }
+
+    r = object_parse_property_opt(opaque, name, value, "type", errp);
+    g_free(qom_name);
+    return r;
+}
 
 /*
  * Initial object creation happens before all other