From nobody Tue Feb 10 16:22:44 2026 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@gnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@gnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506958265606776.9976813253902; Mon, 2 Oct 2017 08:31:05 -0700 (PDT) Received: from localhost ([::1]:52841 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dz2g8-0003F2-Tj for importer@patchew.org; Mon, 02 Oct 2017 11:30:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38867) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dz2bf-00080R-KT for qemu-devel@nongnu.org; Mon, 02 Oct 2017 11:26:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dz2bd-0007zP-H6 for qemu-devel@nongnu.org; Mon, 02 Oct 2017 11:26:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38782) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dz2bd-0007yk-A5 for qemu-devel@nongnu.org; Mon, 02 Oct 2017 11:26:05 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 478DA80463; Mon, 2 Oct 2017 15:26:04 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-91.ams2.redhat.com [10.36.116.91]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 26D1B5D720; Mon, 2 Oct 2017 15:26:02 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id C3C4511562E9; Mon, 2 Oct 2017 17:25:52 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 478DA80463 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=armbru@redhat.com From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 2 Oct 2017 17:25:42 +0200 Message-Id: <20171002152552.27999-23-armbru@redhat.com> In-Reply-To: <20171002152552.27999-1-armbru@redhat.com> References: <20171002152552.27999-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 02 Oct 2017 15:26:04 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC PATCH 22/32] qapi: New helper c_string() X-BeenThere: qemu-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@gnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Use new c_string() to replace qapi-introspect's more limited to_c_string(). Signed-off-by: Markus Armbruster --- scripts/qapi-introspect.py | 8 ++------ scripts/qapi.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/scripts/qapi-introspect.py b/scripts/qapi-introspect.py index 89365449b0..52404b07ab 100644 --- a/scripts/qapi-introspect.py +++ b/scripts/qapi-introspect.py @@ -35,10 +35,6 @@ def to_json(obj, level=3D0): return ret =20 =20 -def to_c_string(string): - return '"' + string.replace('\\', r'\\').replace('"', r'\"') + '"' - - class QAPISchemaGenIntrospectVisitor(QAPISchemaVisitor): def __init__(self, unmask): self._unmask =3D unmask @@ -70,12 +66,12 @@ extern const char %(c_name)s[]; ''', c_name=3Dc_name(name)) lines =3D to_json(jsons).split('\n') - c_string =3D '\n '.join([to_c_string(line) for line in lines]) self.defn =3D mcgen(''' const char %(c_name)s[] =3D %(c_string)s; ''', c_name=3Dc_name(name), - c_string=3Dc_string) + c_string=3D'\n '.join([c_string(line) + for line in lines])) self._schema =3D None self._jsons =3D None self._used_types =3D None diff --git a/scripts/qapi.py b/scripts/qapi.py index efc128eee0..958249fbd8 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -1915,6 +1915,21 @@ def c_name(name, protect=3DTrue): return 'q_' + name return name =20 + +def c_string(string): + def escape_ch(match): + ch =3D match.group(0) + esc =3D {'\a': 'a', '\b': 'b', '\f': 'f', '\n': 'n', '\r': 'r', + '\t': 't', '\v': 'v', '"': r'"', '\\': '\\'}.get(ch) + if not esc: + esc =3D 'x%02x' % ord(ch) + return '\\' + esc + + if string is None: + return "NULL" + return '"' + re.sub(r'[\0-\37"\\\177]', escape_ch, string) + '"' + + eatspace =3D '\033EATSPACE.' pointer_suffix =3D ' *' + eatspace =20 --=20 2.13.6