From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, akong@redhat.com, berto@igalia.com,
armbru@redhat.com, mdroth@linux.vnet.ibm.com
Subject: [Qemu-devel] [PATCH v2 1/4] qapi: Fix C identifiers generated for names containing '.'
Date: Sat, 11 Apr 2015 12:09:40 -0600 [thread overview]
Message-ID: <1428775783-18082-2-git-send-email-eblake@redhat.com> (raw)
In-Reply-To: <1428775783-18082-1-git-send-email-eblake@redhat.com>
From: Markus Armbruster <armbru@redhat.com>
c_fun() maps '.' to '_', c_var() doesn't. Nothing prevents '.' in
QAPI names that get passed to c_var().
Which QAPI names get passed to c_fun(), to c_var(), or to both is not
obvious. Names of command parameters and struct type members get
passed to c_var().
c_var() strips a leading '*', but this cannot happen. c_fun()
doesn't.
Fix c_var() to work exactly like c_fun().
Perhaps they should be replaced by a single mapping function.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[add 'import string']
Signed-off-by: Eric Blake <eblake@redhat.com>
---
scripts/qapi.py | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/scripts/qapi.py b/scripts/qapi.py
index fff4462..82bf10d 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -15,6 +15,7 @@ import re
from ordereddict import OrderedDict
import os
import sys
+import string
builtin_types = {
'str': 'QTYPE_QSTRING',
@@ -747,6 +748,8 @@ def camel_case(name):
new_name += ch.lower()
return new_name
+c_var_trans = string.maketrans('.-', '__')
+
def c_var(name, protect=True):
# ANSI X3J11/88-090, 3.1.1
c89_words = set(['auto', 'break', 'case', 'char', 'const', 'continue',
@@ -776,10 +779,10 @@ def c_var(name, protect=True):
polluted_words = set(['unix', 'errno'])
if protect and (name in c89_words | c99_words | c11_words | gcc_words | cpp_words | polluted_words):
return "q_" + name
- return name.replace('-', '_').lstrip("*")
+ return name.translate(c_var_trans)
def c_fun(name, protect=True):
- return c_var(name, protect).replace('.', '_')
+ return c_var(name, protect)
def c_list_type(name):
return '%sList' % name
--
2.1.0
next prev parent reply other threads:[~2015-04-11 18:12 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-11 18:09 [Qemu-devel] [PATCH v2 0/4] Fix C identifiers generated for names containing '.' Eric Blake
2015-04-11 18:09 ` Eric Blake [this message]
2015-04-15 8:01 ` [Qemu-devel] [PATCH v2 1/4] qapi: " Alberto Garcia
2015-04-11 18:09 ` [Qemu-devel] [PATCH v2 2/4] qapi: Drop duplicate c_fun() in favor of c_var() Eric Blake
2015-04-15 8:03 ` Alberto Garcia
2015-04-29 11:04 ` Markus Armbruster
2015-05-01 17:00 ` Eric Blake
2015-04-11 18:09 ` [Qemu-devel] [PATCH v2 3/4] qapi: Correctly handle downstream extensions in more locations Eric Blake
2015-04-29 11:29 ` Markus Armbruster
2015-04-29 15:30 ` Eric Blake
2015-04-30 22:30 ` Eric Blake
2015-05-05 12:33 ` Eric Blake
2015-04-11 18:09 ` [Qemu-devel] [PATCH v2 4/4] qapi: Test name mangling of downstream extensions Eric Blake
2015-04-29 11:32 ` Markus Armbruster
2015-04-29 15:45 ` Eric Blake
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1428775783-18082-2-git-send-email-eblake@redhat.com \
--to=eblake@redhat.com \
--cc=akong@redhat.com \
--cc=armbru@redhat.com \
--cc=berto@igalia.com \
--cc=kwolf@redhat.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).