Patchwork [3/9] qmisc: Introduce qobject_from_va()

login
register
mail settings
Submitter Luiz Capitulino
Date Oct. 13, 2009, 4:57 p.m.
Message ID <1255453026-18637-4-git-send-email-lcapitulino@redhat.com>
Download mbox | patch
Permalink /patch/35876/
State New
Headers show

Comments

Luiz Capitulino - Oct. 13, 2009, 4:57 p.m.
It will be used by the (to be introduced) QError module.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 qmisc.c |   44 +++++++++++++++++++++++++++++++-------------
 qmisc.h |    2 ++
 2 files changed, 33 insertions(+), 13 deletions(-)
Markus Armbruster - Oct. 13, 2009, 9:52 p.m.
Luiz Capitulino <lcapitulino@redhat.com> writes:

> It will be used by the (to be introduced) QError module.
>
> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
> ---
>  qmisc.c |   44 +++++++++++++++++++++++++++++++-------------
>  qmisc.h |    2 ++
>  2 files changed, 33 insertions(+), 13 deletions(-)
>
> diff --git a/qmisc.c b/qmisc.c
> index 42b6f22..2bca278 100644
> --- a/qmisc.c
> +++ b/qmisc.c
> @@ -172,6 +172,36 @@ static QObject *build_qobject(const char **fmt, va_list *args)
>  }
>  
>  /**
> + * qobject_from_va(): Create a QObject from the specified va_list
> + *
> + * Same as qobject_from_fmt(), but with a va_list argument.
> + */
> +QObject *qobject_from_va(const char *format, va_list va)
> +{
> +    va_list lva;
> +    QObject *obj;
> +    const char *fmt = format;
> +
> +    va_copy(lva, va);


Why copy?  Just curious...

[...]
Luiz Capitulino - Oct. 14, 2009, 1:40 p.m.
On Tue, 13 Oct 2009 23:52:18 +0200
Markus Armbruster <armbru@redhat.com> wrote:

> Luiz Capitulino <lcapitulino@redhat.com> writes:
> 
> > It will be used by the (to be introduced) QError module.
> >
> > Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
> > ---
> >  qmisc.c |   44 +++++++++++++++++++++++++++++++-------------
> >  qmisc.h |    2 ++
> >  2 files changed, 33 insertions(+), 13 deletions(-)
> >
> > diff --git a/qmisc.c b/qmisc.c
> > index 42b6f22..2bca278 100644
> > --- a/qmisc.c
> > +++ b/qmisc.c
> > @@ -172,6 +172,36 @@ static QObject *build_qobject(const char **fmt, va_list *args)
> >  }
> >  
> >  /**
> > + * qobject_from_va(): Create a QObject from the specified va_list
> > + *
> > + * Same as qobject_from_fmt(), but with a va_list argument.
> > + */
> > +QObject *qobject_from_va(const char *format, va_list va)
> > +{
> > +    va_list lva;
> > +    QObject *obj;
> > +    const char *fmt = format;
> > +
> > +    va_copy(lva, va);
> 
> 
> Why copy?  Just curious...

 Because I'm using va_arg(), not sure if matters though.
Paolo Bonzini - Oct. 14, 2009, 2:27 p.m.
>>> +QObject *qobject_from_va(const char *format, va_list va)
>>> +{
>>> +    va_list lva;
>>> +    QObject *obj;
>>> +    const char *fmt = format;
>>> +
>>> +    va_copy(lva, va);
>>
>>
>> Why copy?  Just curious...
>
>   Because I'm using va_arg(), not sure if matters though.

No, you do not need that.  The va_arg will be destructive, but anyway 
you're not going to do more than one pass on the va_list.

Paolo

Patch

diff --git a/qmisc.c b/qmisc.c
index 42b6f22..2bca278 100644
--- a/qmisc.c
+++ b/qmisc.c
@@ -172,6 +172,36 @@  static QObject *build_qobject(const char **fmt, va_list *args)
 }
 
 /**
+ * qobject_from_va(): Create a QObject from the specified va_list
+ *
+ * Same as qobject_from_fmt(), but with a va_list argument.
+ */
+QObject *qobject_from_va(const char *format, va_list va)
+{
+    va_list lva;
+    QObject *obj;
+    const char *fmt = format;
+
+    va_copy(lva, va);
+
+    switch (*fmt) {
+        case '[':
+            fmt++;
+            obj = do_mklist(&fmt, &lva, ']', count_format(fmt, ']'));
+            break;
+        case '{':
+            fmt++;
+            obj = do_mkdict(&fmt, &lva, '}', count_format(fmt, '}'));
+            break;
+        default:
+            obj = build_qobject(&fmt, &lva);
+            break;
+    }
+
+    return obj;
+}
+
+/**
  * qobject_from_fmt(): build QObjects from a specified format.
  *
  * Valid characters of the format:
@@ -203,19 +233,7 @@  QObject *qobject_from_fmt(const char *fmt, ...)
     QObject *obj;
 
     va_start(args, fmt);
-    switch (*fmt) {
-        case '[':
-            fmt++;
-            obj = do_mklist(&fmt, &args, ']', count_format(fmt, ']'));
-            break;
-        case '{':
-            fmt++;
-            obj = do_mkdict(&fmt, &args, '}', count_format(fmt, '}'));
-            break;
-        default:
-            obj = build_qobject(&fmt, &args);
-            break;
-    }
+    obj = qobject_from_va(fmt, args);
     va_end(args);
 
     return obj;
diff --git a/qmisc.h b/qmisc.h
index ac481fe..16070f9 100644
--- a/qmisc.h
+++ b/qmisc.h
@@ -12,8 +12,10 @@ 
 #ifndef QMISC_H
 #define QMISC_H
 
+#include <stdarg.h>
 #include "qobject.h"
 
+QObject *qobject_from_va(const char *format, va_list va);
 QObject *qobject_from_fmt(const char *fmt, ...);
 
 #endif /* QMISC_H */