提交 c43567c1 编写于 作者: E Eric Blake 提交者: Markus Armbruster

qapi: Fix c_name() munging

The method c_name() is supposed to do two different actions: munge
'-' into '_', and add a 'q_' prefix to ticklish names.  But it did
these steps out of order, making it possible to submit input that
is not ticklish until after munging, where the output then lacked
the desired prefix.

The failure is exposed easily if you have a compiler that recognizes
C11 keywords, and try to name a member '_Thread-local', as it would
result in trying to compile the declaration 'uint64_t _Thread_local;'
which is not valid.  However, this name violates our conventions
(ultimately, want to enforce that no qapi names start with single
underscore), so the test is slightly weaker by instead testing
'wchar-t'; the declaration 'uint64_t wchar_t;' is valid in C (where
wchar_t is only a typedef) but would fail with a C++ compiler (where
it is a keyword).

Fix things by reversing the order of actions within c_name().
Signed-off-by: NEric Blake <eblake@redhat.com>
Message-Id: <1447836791-369-18-git-send-email-eblake@redhat.com>
Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
上级 27b60ab9
...@@ -1482,10 +1482,11 @@ def c_name(name, protect=True): ...@@ -1482,10 +1482,11 @@ def c_name(name, protect=True):
'not_eq', 'or', 'or_eq', 'xor', 'xor_eq']) 'not_eq', 'or', 'or_eq', 'xor', 'xor_eq'])
# namespace pollution: # namespace pollution:
polluted_words = set(['unix', 'errno']) polluted_words = set(['unix', 'errno'])
name = name.translate(c_name_trans)
if protect and (name in c89_words | c99_words | c11_words | gcc_words if protect and (name in c89_words | c99_words | c11_words | gcc_words
| cpp_words | polluted_words): | cpp_words | polluted_words):
return "q_" + name return "q_" + name
return name.translate(c_name_trans) return name
eatspace = '\033EATSPACE.' eatspace = '\033EATSPACE.'
pointer_suffix = ' *' + eatspace pointer_suffix = ' *' + eatspace
......
...@@ -152,12 +152,13 @@ ...@@ -152,12 +152,13 @@
{ 'event': 'EVENT_D', { 'event': 'EVENT_D',
'data': { 'a' : 'EventStructOne', 'b' : 'str', '*c': 'str', '*enum3': 'EnumOne' } } 'data': { 'a' : 'EventStructOne', 'b' : 'str', '*c': 'str', '*enum3': 'EnumOne' } }
# test that we correctly compile downstream extensions # test that we correctly compile downstream extensions, as well as munge
# ticklish names
{ 'enum': '__org.qemu_x-Enum', 'data': [ '__org.qemu_x-value' ] } { 'enum': '__org.qemu_x-Enum', 'data': [ '__org.qemu_x-value' ] }
{ 'struct': '__org.qemu_x-Base', { 'struct': '__org.qemu_x-Base',
'data': { '__org.qemu_x-member1': '__org.qemu_x-Enum' } } 'data': { '__org.qemu_x-member1': '__org.qemu_x-Enum' } }
{ 'struct': '__org.qemu_x-Struct', 'base': '__org.qemu_x-Base', { 'struct': '__org.qemu_x-Struct', 'base': '__org.qemu_x-Base',
'data': { '__org.qemu_x-member2': 'str' } } 'data': { '__org.qemu_x-member2': 'str', '*wchar-t': 'int' } }
{ 'union': '__org.qemu_x-Union1', 'data': { '__org.qemu_x-branch': 'str' } } { 'union': '__org.qemu_x-Union1', 'data': { '__org.qemu_x-branch': 'str' } }
{ 'struct': '__org.qemu_x-Struct2', { 'struct': '__org.qemu_x-Struct2',
'data': { 'array': ['__org.qemu_x-Union1'] } } 'data': { 'array': ['__org.qemu_x-Union1'] } }
......
...@@ -185,6 +185,7 @@ enum __org.qemu_x-Enum ['__org.qemu_x-value'] ...@@ -185,6 +185,7 @@ enum __org.qemu_x-Enum ['__org.qemu_x-value']
object __org.qemu_x-Struct object __org.qemu_x-Struct
base __org.qemu_x-Base base __org.qemu_x-Base
member __org.qemu_x-member2: str optional=False member __org.qemu_x-member2: str optional=False
member wchar-t: int optional=True
object __org.qemu_x-Struct2 object __org.qemu_x-Struct2
member array: __org.qemu_x-Union1List optional=False member array: __org.qemu_x-Union1List optional=False
object __org.qemu_x-Union1 object __org.qemu_x-Union1
......
...@@ -65,6 +65,10 @@ __org_qemu_x_Union1 *qmp___org_qemu_x_command(__org_qemu_x_EnumList *a, ...@@ -65,6 +65,10 @@ __org_qemu_x_Union1 *qmp___org_qemu_x_command(__org_qemu_x_EnumList *a,
ret->type = ORG_QEMU_X_UNION1_KIND___ORG_QEMU_X_BRANCH; ret->type = ORG_QEMU_X_UNION1_KIND___ORG_QEMU_X_BRANCH;
ret->u.__org_qemu_x_branch = strdup("blah1"); ret->u.__org_qemu_x_branch = strdup("blah1");
/* Also test that 'wchar-t' was munged to 'q_wchar_t' */
if (b && b->value && !b->value->has_q_wchar_t) {
b->value->q_wchar_t = 1;
}
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册