From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51860) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z4sP5-0000eO-0v for qemu-devel@nongnu.org; Tue, 16 Jun 2015 11:03:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z4sP0-0001le-Rv for qemu-devel@nongnu.org; Tue, 16 Jun 2015 11:03:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60768) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z4sP0-0001kt-KY for qemu-devel@nongnu.org; Tue, 16 Jun 2015 11:03:50 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 039D8AED53 for ; Tue, 16 Jun 2015 15:03:49 +0000 (UTC) Message-ID: <55803AD0.9050708@redhat.com> Date: Tue, 16 Jun 2015 09:03:44 -0600 From: Eric Blake MIME-Version: 1.0 References: <1434458200-23440-1-git-send-email-mst@redhat.com> <1434458200-23440-2-git-send-email-mst@redhat.com> In-Reply-To: <1434458200-23440-2-git-send-email-mst@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="iRx5oPwpiCfOPQsn1NuBPBGwuqE9pGQa0" Subject: Re: [Qemu-devel] [PATCH RFC 1/3] error: don't rely on pointer comparisons List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Michael S. Tsirkin" , qemu-devel@nongnu.org Cc: kwolf@redhat.com, armbru@redhat.com, dgilbert@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --iRx5oPwpiCfOPQsn1NuBPBGwuqE9pGQa0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 06/16/2015 06:53 AM, Michael S. Tsirkin wrote: > makes it possible to copy error_abort pointers, > not just pass them on directly. >=20 > Signed-off-by: Michael S. Tsirkin > --- > util/error.c | 16 +++++++++++----- > 1 file changed, 11 insertions(+), 5 deletions(-) >=20 > diff --git a/util/error.c b/util/error.c > index 14f4351..ccf29ea 100644 > --- a/util/error.c > +++ b/util/error.c > @@ -20,7 +20,13 @@ struct Error > ErrorClass err_class; > }; > =20 > -Error *error_abort; > +static Error error_abort_st =3D { .err_class =3D ERROR_CLASS_MAX }; > +Error *error_abort =3D &error_abort_st; Looking at this a bit further, I still wonder if we can do a slightly better job of coming up with something that will SIGSEGV (or SIGBUS) if we (accidentally) try to dereference the pointer (similar to how SIG_IGN is (sighandler_t)1) - because we know that the abort object should never be dereferenced. Something like: Error *error_abort =3D (Error *)1; with no need for error_abort_st. (Might have to spell it as Error *error_abort =3D (void*)(intptr_t)1; to shut up compiler warnings) > + > +static bool error_is_abort(Error **errp) > +{ > + return errp && *errp && (*errp)->err_class =3D=3D ERROR_CLASS_MAX;= > +} and this would be: return errp && *errp =3D=3D error_abort; The rest of this patch is still good. Then in patch 2, you'd have: Error *error_init_local(Error **errp) { return error_is_abort(errp) ? error_abort : NULL; } That is, you still use pointer equality, but at one less level of indirection (equality at the Error* level, not the Error** level). --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --iRx5oPwpiCfOPQsn1NuBPBGwuqE9pGQa0 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/ iQEcBAEBCAAGBQJVgDrQAAoJEKeha0olJ0Nq7vAH/1/ZSrQcCRmn9Fzag43hjCZE nuZ3aWJHUiSiHmoXpPGyP6/sJtEkeg1LfLBqb2wuh19Z8MnmI/GQYna4VL0MrkJc N4sIeaLJnvCCZbUokIO/fk2ABH1PdI2MF94dGRxJ/m/PMzj2GTzYEnUGU1M6hbwZ G1PFmdFt4hYVNj0jyVrTO/wbTI3m2xuz1RtATUG7GDdjdDwoNad+cBmECaLKMihm E6pkYLm/r95/N3XZWR/AHx/WAwAvU70u7vuwSRmVaBRRKMIgOPQKwKdhFJI5pS74 /avHwVAWLK1U+HSRtOPlUCtS/hj0I1YyCKf9sch7+u9waTwVfIg62bSNqMLdXnM= =cGEV -----END PGP SIGNATURE----- --iRx5oPwpiCfOPQsn1NuBPBGwuqE9pGQa0--