From patchwork Thu Apr 2 17:28:46 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 457752 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 12B7814007D for ; Fri, 3 Apr 2015 04:37:02 +1100 (AEDT) Received: from localhost ([::1]:59603 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ydj36-00051p-5d for incoming@patchwork.ozlabs.org; Thu, 02 Apr 2015 13:37:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40828) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YdixL-000305-83 for qemu-devel@nongnu.org; Thu, 02 Apr 2015 13:31:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ydix8-00006i-Th for qemu-devel@nongnu.org; Thu, 02 Apr 2015 13:31:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59597) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ydix8-000061-Gs for qemu-devel@nongnu.org; Thu, 02 Apr 2015 13:30:50 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t32HT8o0023314 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 2 Apr 2015 13:29:08 -0400 Received: from blackfin.pond.sub.org (ovpn-116-38.ams2.redhat.com [10.36.116.38]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t32HT4op003069 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 2 Apr 2015 13:29:07 -0400 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id D96063043FD1; Thu, 2 Apr 2015 19:29:03 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 2 Apr 2015 19:28:46 +0200 Message-Id: <1427995743-7865-3-git-send-email-armbru@redhat.com> In-Reply-To: <1427995743-7865-1-git-send-email-armbru@redhat.com> References: <1427995743-7865-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, berto@igalia.com, akong@redhat.com, mdroth@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH RFC 02/19] qapi: Fix C identifiers generated for names containing '.' X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@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 Reviewed-by: Eric Blake --- scripts/qapi.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/qapi.py b/scripts/qapi.py index 8e5b4ad..6d102df 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -693,6 +693,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', @@ -722,10 +724,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