From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39150) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YtAvU-0005p3-Vy for qemu-devel@nongnu.org; Fri, 15 May 2015 04:25:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YtAvQ-0004UY-1r for qemu-devel@nongnu.org; Fri, 15 May 2015 04:25:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44811) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YtAvP-0004Tg-Pm for qemu-devel@nongnu.org; Fri, 15 May 2015 04:24:55 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t4F8OsJH012188 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Fri, 15 May 2015 04:24:55 -0400 From: Markus Armbruster Date: Fri, 15 May 2015 10:24:29 +0200 Message-Id: <1431678292-17692-4-git-send-email-armbru@redhat.com> In-Reply-To: <1431678292-17692-1-git-send-email-armbru@redhat.com> References: <1431678292-17692-1-git-send-email-armbru@redhat.com> Subject: [Qemu-devel] [PULL 03/26] qapi: Fix C identifiers generated for names containing '.' List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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 [add 'import string'] Signed-off-by: Eric Blake Reviewed-by: Alberto Garcia --- scripts/qapi.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/qapi.py b/scripts/qapi.py index 166b74f..4b07805 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', @@ -752,6 +753,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', @@ -781,10 +784,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 -- 1.9.3