From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41968) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YqoXh-0006GX-Aw for qemu-devel@nongnu.org; Fri, 08 May 2015 16:06:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YqoXe-00020B-0P for qemu-devel@nongnu.org; Fri, 08 May 2015 16:06:41 -0400 Message-ID: <554D174B.4010200@redhat.com> Date: Fri, 08 May 2015 14:06:35 -0600 From: Eric Blake MIME-Version: 1.0 References: <1431105726-3682-1-git-send-email-kwolf@redhat.com> <1431105726-3682-2-git-send-email-kwolf@redhat.com> In-Reply-To: <1431105726-3682-2-git-send-email-kwolf@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="wSNPk6V2Mtgqc8KmSjK9XW1jc0mAjudvq" Subject: Re: [Qemu-devel] [PATCH 01/34] qdict: Add qdict_array_entries() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf , qemu-block@nongnu.org Cc: mreitz@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --wSNPk6V2Mtgqc8KmSjK9XW1jc0mAjudvq Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 05/08/2015 11:21 AM, Kevin Wolf wrote: > Signed-off-by: Kevin Wolf > --- Might want to include mention of what it will be used for in the commit body. > include/qapi/qmp/qdict.h | 1 + > qobject/qdict.c | 68 ++++++++++++++++++++++++++++++++++++++++= +++++--- > 2 files changed, 65 insertions(+), 4 deletions(-) >=20 > @@ -646,7 +647,7 @@ void qdict_array_split(QDict *src, QList **dst) > snprintf_ret =3D snprintf(prefix, 32, "%u.", i); > assert(snprintf_ret < 32); > =20 > - is_subqdict =3D qdict_has_prefixed_entries(src, prefix); > + is_subqdict =3D qdict_count_prefixed_entries(src, prefix); Good thing we require a C99 compiler, where 'bool =3D int' does the right= thing for integers > 1. > /** > + * qdict_array_valid(): Returns the number of direct array entries if = the > + * sub-QDict of src specified by the prefix in subqdict (or src itself= for > + * prefix =3D=3D "") is valid as an array, i.e. the length of the crea= ted list if > + * the sub-QDict would become empty after calling qdict_array_split() = on it. If > + * the array is not valid, -1 is returned. > + */ > +int qdict_array_entries(QDict *src, const char *subqdict) Comment doesn't match function name. > +{ > + const QDictEntry *entry; > + unsigned i; > + unsigned entries =3D 0; > + size_t subqdict_len =3D strlen(subqdict); > + > + assert(!subqdict_len || subqdict[subqdict_len - 1] =3D=3D '.'); > + > + for (i =3D 0; i < UINT_MAX; i++) { > + QObject *subqobj; > + int subqdict_entries; > + size_t slen =3D 32 + subqdict_len; > + char indexstr[slen], prefix[slen]; And more dependence on a working C99 compiler, thanks to variable length array (VLA). > + size_t snprintf_ret; > + > + snprintf_ret =3D snprintf(indexstr, slen, "%s%u", subqdict, i)= ; > + assert(snprintf_ret < slen); Since gcc may compile the allocation of indexstr into a malloc() anyways, would it be any simpler to just use g_strdup_printf() directly, instead of futzing around with VLA and snprintf() ourselves? It might mean less code, as some of the error checking is taken care of on your behalf. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --wSNPk6V2Mtgqc8KmSjK9XW1jc0mAjudvq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJVTRdLAAoJEKeha0olJ0NqYqAIAK3fzY1X7JJc2KLtkCo7bmQ/ 51K4tvQ0sUALqasPLUKlFuIsWwBwj5mh5wzN0LHgVHlWPmuzHWYMMzDk7bKD4mBi TNVCNBhGih5/pnanDwOAlV3vbH5+1XNyW6xfcM3vqhD7H2EXPbd2QUoncF1MRPkA 73TnIWaVXy+JQA63pZDK1waDLMyc1Vi/L9oXyhIkZ6CXhbgot4lNW3NeiZjcyIPQ wmxrl/PwMix5sLzFRCwMvEAMd6LQVJygHSZF+itXk2cat6O+3T5xge6uIbQ0wsoD ZhxAqrGI6KG0K6US1Vipe/xFp9MaNvQA7L91SRzG2ucMxyEVqQ19sRHRf/KG/CM= =SbJ0 -----END PGP SIGNATURE----- --wSNPk6V2Mtgqc8KmSjK9XW1jc0mAjudvq--