[{"id":1771376,"web_url":"http://patchwork.ozlabs.org/comment/1771376/","msgid":"<f9ef8d51-0fac-efa0-a358-8c3a3e92e894@redhat.com>","list_archive_url":null,"date":"2017-09-19T20:48:35","subject":"Re: [Qemu-devel] [RFC 02/15] qobject: allow NULL for\n\tqstring_get_str()","submitter":{"id":6591,"url":"http://patchwork.ozlabs.org/api/people/6591/","name":"Eric Blake","email":"eblake@redhat.com"},"content":"On 09/14/2017 02:50 AM, Peter Xu wrote:\n> Then I can get NULL rather than crash when calling things like:\n> \n>   qstring_get_str(qobject_to_qstring(object));\n> \n> when key does not exist.\n\nRight now, qdict_get_str() is documented as:\n\n * This function assumes that 'key' exists and it stores a\n * QString object.\n\nYour code changes that, by making it now return NULL instead of crashing\non what used to be usage in violation of the contract; compared to\nqdict_get_try_str() which gracefully returns NULL, but which could use\nyour new semantics for doing so in fewer lines of code.\n\nI'm not necessarily opposed to the change, but I worry that it has\nsubtle ramifications that we haven't thought about, as well as\nconsistency with the rest of the QObject APIs.  It may be better to just\nintroduce qstring_get_try_str(), which gracefully handles NULL input,\nand leave the existing function alone; and if you do introduce a new\nhelper, it may be worth converting existing clients (perhaps with help\nfrom Coccinelle) to take advantage of the helper.\n\n> +++ b/qobject/qstring.c\n> @@ -125,7 +125,7 @@ QString *qobject_to_qstring(const QObject *obj)\n>   */\n>  const char *qstring_get_str(const QString *qstring)\n>  {\n> -    return qstring->string;\n> +    return qstring ? qstring->string : NULL;\n>  }\n>  \n>  /**\n>","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ext-mx08.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx08.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=eblake@redhat.com"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xxZkB2QVTz9sBW\n\tfor <incoming@patchwork.ozlabs.org>;\n\tWed, 20 Sep 2017 06:49:38 +1000 (AEST)","from localhost ([::1]:45364 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1duPSa-0004ph-Dt\n\tfor incoming@patchwork.ozlabs.org; Tue, 19 Sep 2017 16:49:36 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:33453)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <eblake@redhat.com>) id 1duPRn-0004o9-4b\n\tfor qemu-devel@nongnu.org; Tue, 19 Sep 2017 16:48:49 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <eblake@redhat.com>) id 1duPRj-0000YB-TG\n\tfor qemu-devel@nongnu.org; Tue, 19 Sep 2017 16:48:47 -0400","from mx1.redhat.com ([209.132.183.28]:55972)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <eblake@redhat.com>) id 1duPRj-0000XI-Jv\n\tfor qemu-devel@nongnu.org; Tue, 19 Sep 2017 16:48:43 -0400","from smtp.corp.redhat.com\n\t(int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id A089CC0587E4;\n\tTue, 19 Sep 2017 20:48:42 +0000 (UTC)","from [10.10.124.97] (ovpn-124-97.rdu2.redhat.com [10.10.124.97])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id C08265D9CB;\n\tTue, 19 Sep 2017 20:48:36 +0000 (UTC)"],"DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com A089CC0587E4","To":"Peter Xu <peterx@redhat.com>, qemu-devel@nongnu.org","References":"<1505375436-28439-1-git-send-email-peterx@redhat.com>\n\t<1505375436-28439-3-git-send-email-peterx@redhat.com>","From":"Eric Blake <eblake@redhat.com>","Openpgp":"url=http://people.redhat.com/eblake/eblake.gpg","Organization":"Red Hat, Inc.","Message-ID":"<f9ef8d51-0fac-efa0-a358-8c3a3e92e894@redhat.com>","Date":"Tue, 19 Sep 2017 15:48:35 -0500","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101\n\tThunderbird/52.3.0","MIME-Version":"1.0","In-Reply-To":"<1505375436-28439-3-git-send-email-peterx@redhat.com>","Content-Type":"multipart/signed; micalg=pgp-sha256;\n\tprotocol=\"application/pgp-signature\";\n\tboundary=\"bew4aSDvhoVNcNHFNrLWcStCGRTkmGbLt\"","X-Scanned-By":"MIMEDefang 2.79 on 10.5.11.14","X-Greylist":"Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.32]);\n\tTue, 19 Sep 2017 20:48:42 +0000 (UTC)","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]\n\t[fuzzy]","X-Received-From":"209.132.183.28","X-Content-Filtered-By":"Mailman/MimeDel 2.1.21","Subject":"Re: [Qemu-devel] [RFC 02/15] qobject: allow NULL for\n\tqstring_get_str()","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"Laurent Vivier <lvivier@redhat.com>, Fam Zheng <famz@redhat.com>, Juan\n\tQuintela <quintela@redhat.com>, Markus Armbruster <armbru@redhat.com>,\n\tmdroth@linux.vnet.ibm.com, \tStefan Hajnoczi <shajnocz@redhat.com>,\n\t=?utf-8?q?Marc-Andr=C3=A9_Lure?= =?utf-8?q?au?=\n\t<marcandre.lureau@gmail.com>, \tPaolo Bonzini <pbonzini@redhat.com>,\n\t\"Dr . David Alan Gilbert\" <dgilbert@redhat.com>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}},{"id":1771564,"web_url":"http://patchwork.ozlabs.org/comment/1771564/","msgid":"<20170920050252.GT3617@pxdev.xzpeter.org>","list_archive_url":null,"date":"2017-09-20T05:02:52","subject":"Re: [Qemu-devel] [RFC 02/15] qobject: allow NULL for\n\tqstring_get_str()","submitter":{"id":67717,"url":"http://patchwork.ozlabs.org/api/people/67717/","name":"Peter Xu","email":"peterx@redhat.com"},"content":"On Tue, Sep 19, 2017 at 03:48:35PM -0500, Eric Blake wrote:\n> On 09/14/2017 02:50 AM, Peter Xu wrote:\n> > Then I can get NULL rather than crash when calling things like:\n> > \n> >   qstring_get_str(qobject_to_qstring(object));\n> > \n> > when key does not exist.\n> \n> Right now, qdict_get_str() is documented as:\n> \n>  * This function assumes that 'key' exists and it stores a\n>  * QString object.\n> \n> Your code changes that, by making it now return NULL instead of crashing\n> on what used to be usage in violation of the contract; compared to\n> qdict_get_try_str() which gracefully returns NULL, but which could use\n> your new semantics for doing so in fewer lines of code.\n> \n> I'm not necessarily opposed to the change, but I worry that it has\n> subtle ramifications that we haven't thought about, as well as\n> consistency with the rest of the QObject APIs.  It may be better to just\n> introduce qstring_get_try_str(), which gracefully handles NULL input,\n> and leave the existing function alone; and if you do introduce a new\n> helper, it may be worth converting existing clients (perhaps with help\n> from Coccinelle) to take advantage of the helper.\n\nI'll take your suggestion.\n\nThough I didn't see much existing codes that can use the new\nqstring_get_try_str().  One I found is object_property_get_str().\nI can add one more patch to convert its usage.\n\nThanks,\n\n> \n> > +++ b/qobject/qstring.c\n> > @@ -125,7 +125,7 @@ QString *qobject_to_qstring(const QObject *obj)\n> >   */\n> >  const char *qstring_get_str(const QString *qstring)\n> >  {\n> > -    return qstring->string;\n> > +    return qstring ? qstring->string : NULL;\n> >  }\n> >  \n> >  /**\n> > \n> \n> -- \n> Eric Blake, Principal Software Engineer\n> Red Hat, Inc.           +1-919-301-3266\n> Virtualization:  qemu.org | libvirt.org\n>","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ext-mx06.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx06.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=peterx@redhat.com"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xxnh40zhFz9s82\n\tfor <incoming@patchwork.ozlabs.org>;\n\tWed, 20 Sep 2017 15:03:27 +1000 (AEST)","from localhost ([::1]:46708 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1duXAT-0003g7-89\n\tfor incoming@patchwork.ozlabs.org; Wed, 20 Sep 2017 01:03:25 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:42465)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <peterx@redhat.com>) id 1duXAA-0003fw-2u\n\tfor qemu-devel@nongnu.org; Wed, 20 Sep 2017 01:03:07 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <peterx@redhat.com>) id 1duXA6-0007kZ-Pg\n\tfor qemu-devel@nongnu.org; Wed, 20 Sep 2017 01:03:05 -0400","from mx1.redhat.com ([209.132.183.28]:35268)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <peterx@redhat.com>) id 1duXA6-0007ey-JJ\n\tfor qemu-devel@nongnu.org; Wed, 20 Sep 2017 01:03:02 -0400","from smtp.corp.redhat.com\n\t(int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id 43927356E8;\n\tWed, 20 Sep 2017 05:03:01 +0000 (UTC)","from pxdev.xzpeter.org (dhcp-15-224.nay.redhat.com [10.66.15.224])\n\tby smtp.corp.redhat.com (Postfix) with ESMTPS id 34D0D600C2;\n\tWed, 20 Sep 2017 05:02:54 +0000 (UTC)"],"DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com 43927356E8","Date":"Wed, 20 Sep 2017 13:02:52 +0800","From":"Peter Xu <peterx@redhat.com>","To":"Eric Blake <eblake@redhat.com>","Message-ID":"<20170920050252.GT3617@pxdev.xzpeter.org>","References":"<1505375436-28439-1-git-send-email-peterx@redhat.com>\n\t<1505375436-28439-3-git-send-email-peterx@redhat.com>\n\t<f9ef8d51-0fac-efa0-a358-8c3a3e92e894@redhat.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<f9ef8d51-0fac-efa0-a358-8c3a3e92e894@redhat.com>","User-Agent":"Mutt/1.5.24 (2015-08-30)","X-Scanned-By":"MIMEDefang 2.79 on 10.5.11.11","X-Greylist":"Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.30]);\n\tWed, 20 Sep 2017 05:03:01 +0000 (UTC)","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]\n\t[fuzzy]","X-Received-From":"209.132.183.28","Subject":"Re: [Qemu-devel] [RFC 02/15] qobject: allow NULL for\n\tqstring_get_str()","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"Laurent Vivier <lvivier@redhat.com>, Fam Zheng <famz@redhat.com>,\n\tmdroth@linux.vnet.ibm.com, Juan Quintela <quintela@redhat.com>,\n\tMarkus Armbruster <armbru@redhat.com>, qemu-devel@nongnu.org, Stefan\n\tHajnoczi <shajnocz@redhat.com>, =?utf-8?q?Marc-Andr=C3=A9?=\n\tLureau <marcandre.lureau@gmail.com>,\n\tPaolo Bonzini <pbonzini@redhat.com>, \"Dr . David Alan Gilbert\"\n\t<dgilbert@redhat.com>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}}]