diff mbox

[v2,2/4] qapi: Drop duplicate c_fun() in favor of c_var()

Message ID 1428775783-18082-3-git-send-email-eblake@redhat.com
State New
Headers show

Commit Message

Eric Blake April 11, 2015, 6:09 p.m. UTC
Now that the two functions are identical, we only need one of them.

Signed-off-by: Eric Blake <eblake@redhat.com>
---
 scripts/qapi-commands.py | 15 ++++++++-------
 scripts/qapi-event.py    |  2 +-
 scripts/qapi-types.py    |  4 ++--
 scripts/qapi-visit.py    |  4 ++--
 scripts/qapi.py          |  5 +----
 5 files changed, 14 insertions(+), 16 deletions(-)

Comments

Alberto Garcia April 15, 2015, 8:03 a.m. UTC | #1
On Sáb 11 Abr 2015 20:09:41 CEST, Eric Blake wrote:
> Now that the two functions are identical, we only need one of them.
>
> Signed-off-by: Eric Blake <eblake@redhat.com>
> ---
>  scripts/qapi-commands.py | 15 ++++++++-------
>  scripts/qapi-event.py    |  2 +-
>  scripts/qapi-types.py    |  4 ++--
>  scripts/qapi-visit.py    |  4 ++--
>  scripts/qapi.py          |  5 +----
>  5 files changed, 14 insertions(+), 16 deletions(-)

Reviewed-by: Alberto Garcia <berto@igalia.com>

Berto
Markus Armbruster April 29, 2015, 11:04 a.m. UTC | #2
Eric Blake <eblake@redhat.com> writes:

> Now that the two functions are identical, we only need one of them.
>
> Signed-off-by: Eric Blake <eblake@redhat.com>

c_var() isn't the possible best name, but it'll do.

Reviewed-by: Markus Armbruster <armbru@redhat.com>
Eric Blake May 1, 2015, 5 p.m. UTC | #3
On 04/29/2015 05:04 AM, Markus Armbruster wrote:
> Eric Blake <eblake@redhat.com> writes:
> 
>> Now that the two functions are identical, we only need one of them.
>>
>> Signed-off-by: Eric Blake <eblake@redhat.com>
> 
> c_var() isn't the possible best name, but it'll do.

I'm looking at using c_name() in my v3.
diff mbox

Patch

diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py
index db81044..af1e1a1 100644
--- a/scripts/qapi-commands.py
+++ b/scripts/qapi-commands.py
@@ -36,7 +36,8 @@  def generate_command_decl(name, args, ret_type):
     return mcgen('''
 %(ret_type)s qmp_%(name)s(%(args)sError **errp);
 ''',
-                 ret_type=c_type(ret_type), name=c_fun(name), args=arglist).strip()
+                 ret_type=c_type(ret_type), name=c_var(name),
+                 args=arglist).strip()

 def gen_err_check(errvar):
     if errvar:
@@ -62,7 +63,7 @@  def gen_sync_call(name, args, ret_type, indent=0):
 %(retval)sqmp_%(name)s(%(args)s&local_err);

 ''',
-                name=c_fun(name), args=arglist, retval=retval).rstrip()
+                name=c_var(name), args=arglist, retval=retval).rstrip()
     if ret_type:
         ret += "\n" + gen_err_check('local_err')
         ret += "\n" + mcgen(''''
@@ -76,7 +77,7 @@  def gen_sync_call(name, args, ret_type, indent=0):
 def gen_marshal_output_call(name, ret_type):
     if not ret_type:
         return ""
-    return "qmp_marshal_output_%s(retval, ret, &local_err);" % c_fun(name)
+    return "qmp_marshal_output_%s(retval, ret, &local_err);" % c_var(name)

 def gen_visitor_input_containers_decl(args, obj):
     ret = ""
@@ -198,16 +199,16 @@  out:
     qapi_dealloc_visitor_cleanup(md);
 }
 ''',
-                c_ret_type=c_type(ret_type), c_name=c_fun(name),
+                c_ret_type=c_type(ret_type), c_name=c_var(name),
                 visitor=type_visitor(ret_type))

     return ret

 def gen_marshal_input_decl(name, args, ret_type, middle_mode):
     if middle_mode:
-        return 'int qmp_marshal_input_%s(Monitor *mon, const QDict *qdict, QObject **ret)' % c_fun(name)
+        return 'int qmp_marshal_input_%s(Monitor *mon, const QDict *qdict, QObject **ret)' % c_var(name)
     else:
-        return 'static void qmp_marshal_input_%s(QDict *args, QObject **ret, Error **errp)' % c_fun(name)
+        return 'static void qmp_marshal_input_%s(QDict *args, QObject **ret, Error **errp)' % c_var(name)



@@ -309,7 +310,7 @@  def gen_registry(commands):
         registry += mcgen('''
 qmp_register_command("%(name)s", qmp_marshal_input_%(c_name)s, %(opts)s);
 ''',
-                     name=cmd['command'], c_name=c_fun(cmd['command']),
+                     name=cmd['command'], c_name=c_var(cmd['command']),
                      opts=options)
     pop_indent()
     ret = mcgen('''
diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py
index 47dc041..bed809b 100644
--- a/scripts/qapi-event.py
+++ b/scripts/qapi-event.py
@@ -17,7 +17,7 @@  import getopt
 import errno

 def _generate_event_api_name(event_name, params):
-    api_name = "void qapi_event_send_%s(" % c_fun(event_name).lower();
+    api_name = "void qapi_event_send_%s(" % c_var(event_name).lower();
     l = len(api_name)

     if params:
diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index 2bf8145..8cf6349 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -184,7 +184,7 @@  const int %(name)s_qtypes[QTYPE_MAX] = {
 ''',
         qtype = qtype,
         abbrev = de_camel_case(name).upper(),
-        enum = c_fun(de_camel_case(key),False).upper())
+        enum = c_var(de_camel_case(key),False).upper())

     ret += mcgen('''
 };
@@ -221,7 +221,7 @@  struct %(name)s
         %(c_type)s %(c_name)s;
 ''',
                      c_type=c_type(typeinfo[key]),
-                     c_name=c_fun(key))
+                     c_name=c_var(key))

     ret += mcgen('''
     };
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index 6156162..f24dcfa 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -247,7 +247,7 @@  void visit_type_%(name)s(Visitor *m, %(name)s **obj, const char *name, Error **e
 ''',
                 enum_full_value = enum_full_value,
                 c_type = type_name(members[key]),
-                c_name = c_fun(key))
+                c_name = c_var(key))

     ret += mcgen('''
     default:
@@ -348,7 +348,7 @@  void visit_type_%(name)s(Visitor *m, %(name)s **obj, const char *name, Error **e
 ''',
                 enum_full_value = enum_full_value,
                 c_type=type_name(members[key]),
-                c_name=c_fun(key))
+                c_name=c_var(key))

     ret += mcgen('''
         default:
diff --git a/scripts/qapi.py b/scripts/qapi.py
index 82bf10d..1d64c62 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -781,9 +781,6 @@  def c_var(name, protect=True):
         return "q_" + name
     return name.translate(c_var_trans)

-def c_fun(name, protect=True):
-    return c_var(name, protect)
-
 def c_list_type(name):
     return '%sList' % name

@@ -940,7 +937,7 @@  def guardend(name):
 # ENUM_NAME -> ENUM_NAME, ENUM_NAME1 -> ENUM_NAME1, ENUM_Name2 -> ENUM_NAME2
 # ENUM24_Name -> ENUM24_NAME
 def _generate_enum_string(value):
-    c_fun_str = c_fun(value, False)
+    c_fun_str = c_var(value, False)
     if value.isupper():
         return c_fun_str