From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44026) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMhWX-0002Lc-N2 for qemu-devel@nongnu.org; Fri, 22 Jan 2016 14:37:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aMhWW-000288-K1 for qemu-devel@nongnu.org; Fri, 22 Jan 2016 14:37:33 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35044) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMhWW-000283-CU for qemu-devel@nongnu.org; Fri, 22 Jan 2016 14:37:32 -0500 References: <1453219845-30939-1-git-send-email-eblake@redhat.com> <1453219845-30939-27-git-send-email-eblake@redhat.com> <8737tpfmec.fsf@blackfin.pond.sub.org> From: Eric Blake Message-ID: <56A284FB.50502@redhat.com> Date: Fri, 22 Jan 2016 12:37:31 -0700 MIME-Version: 1.0 In-Reply-To: <8737tpfmec.fsf@blackfin.pond.sub.org> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="folpet0in2bUCKU2g1ERf4W6A8puFKOtC" Subject: Re: [Qemu-devel] [PATCH v9 26/37] qapi: Simplify excess input reporting in input visitors List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: marcandre.lureau@redhat.com, Laszlo Ersek , qemu-devel@nongnu.org, Michael Roth This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --folpet0in2bUCKU2g1ERf4W6A8puFKOtC Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 01/22/2016 12:24 PM, Markus Armbruster wrote: > Eric Blake writes: >=20 >> When reporting that an unvisited member remains at the end of an >> input visit for a struct, we were using g_hash_table_find() >> coupled with a callback function that always returns true, to >> locate an arbitrary member of the hash table. But if all we >> need is an arbitrary entry, we can get that from a single-use >> iterator, without needing a tautological callback function. >=20 > Good idea. >=20 >> Suggested-by: Markus Armbruster >=20 > Whoops, it's even mine! I forgot... %-) >=20 >> Signed-off-by: Eric Blake >> Reviewed-by: Marc-Andr=C3=A9 Lureau >> >> --- >> GQueue *any; >> >> if (--ov->depth > 0) { >> @@ -174,8 +168,8 @@ opts_end_struct(Visitor *v, Error **errp) >> } >> >> /* we should have processed all (distinct) QemuOpt instances */ >> - any =3D g_hash_table_find(ov->unprocessed_opts, &ghr_true, NULL);= >> - if (any) { >> + g_hash_table_iter_init(&iter, ov->unprocessed_opts); >> + if (g_hash_table_iter_next(&iter, NULL, (void **)&any)) { >=20 > Is this cast kosher? You may have a point that it violates some corner of C99, but I'm not the first such user: hw/i386/intel_iommu.c: while (g_hash_table_iter_next (&bus_it, NULL, (void**)&vtd_bus)) { qom/object.c: while (g_hash_table_iter_next(&iter, NULL, (gpointer *)&prop)) { Conceptually, it seems fine - void* can be assigned to any pointer, and 'any' qualifies as such a pointer. We are then taking the address of that (or void**) to pass by reference. I suppose a stricter version would be: void *wrap; GQueue *any; if (g_hash_table_iter_next(&iter, NULL, &wrap)) { any =3D wrap; =2E.. but is it worth the bother? Put another way, will a compiler ever do the wrong thing to us because C99 might have some corner case? Laszlo, what's your take? >> if (top_ht) { >> - if (g_hash_table_size(top_ht)) { >> - const char *key; >> - g_hash_table_find(top_ht, always_true, &key); >> + GHashTableIter iter; >> + const char *key; >> + >> + g_hash_table_iter_init(&iter, top_ht); >> + if (g_hash_table_iter_next(&iter, (void **)&key, NULL)) {= >=20 > Is this cast kosher? Here, in addition to the above argument, we also needed to cast away cons= t. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --folpet0in2bUCKU2g1ERf4W6A8puFKOtC 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/ iQEcBAEBCAAGBQJWooT7AAoJEKeha0olJ0NqqjQH/2SX/gxclCgG7kLRTC3W2Eia VI9W+Xpfk9SGGfFsHPuigj7fwzokM0HYLiToRWF2Z7/MCDM5rzidAFGW+joOHHJ2 SR6JtqvaNNaWo+Orea2g7aPNUjfDu0xXGtcLhgGPHUkdjNzQlqMDZRYEtZj9U/dD wxEj1KGrAM4S7fEPGfEy6AYEEpYyJd+BmXiEsONxaVYlImSjWeQZZGWoGX8NNAZM JJl2hLhWe4g5351tPWexAfnCV6SnmGc2N54bY5zYULsutHn8jieWwwziDQHcf7LI fW45C7E7lkUEm021pj1ap2C5bTvBt30vmb++9v/+494mEgu/4D3XbRGmXTSs+b0= =kLkg -----END PGP SIGNATURE----- --folpet0in2bUCKU2g1ERf4W6A8puFKOtC--