From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42685) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDKZy-0001Bw-Bt for qemu-devel@nongnu.org; Wed, 15 Jun 2016 19:50:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bDKZu-00046U-1c for qemu-devel@nongnu.org; Wed, 15 Jun 2016 19:50:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34371) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDKZt-00046P-PY for qemu-devel@nongnu.org; Wed, 15 Jun 2016 19:50:33 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 087ED81F07 for ; Wed, 15 Jun 2016 23:50:33 +0000 (UTC) References: <1466023310-13221-1-git-send-email-armbru@redhat.com> <1466023310-13221-3-git-send-email-armbru@redhat.com> From: Eric Blake Message-ID: <5761E9C8.3040507@redhat.com> Date: Wed, 15 Jun 2016 17:50:32 -0600 MIME-Version: 1.0 In-Reply-To: <1466023310-13221-3-git-send-email-armbru@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="vbqkCxthrtoJIgdEcepqJ7fnFX8mKbDl7" Subject: Re: [Qemu-devel] [PATCH RFC 2/4] range: Eliminate direct Range member access List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster , qemu-devel@nongnu.org Cc: mst@redhat.com, pbonzini@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --vbqkCxthrtoJIgdEcepqJ7fnFX8mKbDl7 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 06/15/2016 02:41 PM, Markus Armbruster wrote: > Users of struct Range mess liberally with its members, which makes > refactoring hard. Create a set of methods, and convert all users to > call them instead of accessing members. The methods have carefully > worded contracts, and use assertions to check them. >=20 > To help with tracking down the places that access members of struct > Range directly, hide the implementation of struct Range outside of > range.c by trickery. The trickery will be dropped in the next commit. Can't we just make Range an opaque type, and move its definition into range.c? Oh, except we have inline functions that would no longer be inline, unless we also had a range-impl.h private header. >=20 > Signed-off-by: Markus Armbruster > --- > @@ -2015,7 +2017,8 @@ build_dsdt(GArray *table_data, BIOSLinker *linker= , > 0, 0x000A0000, 0x000BFFFF, 0, 0x00020000)); > =20 > crs_replace_with_free_ranges(mem_ranges, > - pci_hole->begin, pci_hole->end - 1); > + range_lob(pci_hole), > + range_upb(pci_hole)); Changes like this are nice, isolating us from what the actual struct stor= es. > +++ b/include/qemu/range.h > @@ -30,18 +30,110 @@ > * - this can not represent a full 0 to ~0x0LL range. > */ > =20 > +bool range_is_empty(Range *range); > +bool range_contains(Range *range, uint64_t val); > +void range_make_empty(Range *range); > +void range_set_bounds(Range *range, uint64_t lob, uint64_t upb); > +void range_set_bounds1(Range *range, uint64_t lob, uint64_t upb_plus1)= ; > +uint64_t range_lob(Range *range); > +uint64_t range_upb(Range *range); > +void range_extend(Range *range, Range *extend_by); > +#ifdef RANGE_IMPL > + > /* A structure representing a range of addresses. */ > struct Range { > uint64_t begin; /* First byte of the range, or 0 if empty. */ > uint64_t end; /* 1 + the last byte. 0 if range empty or ends at = ~0x0LL. */ > }; > =20 > +static inline void range_invariant(Range *range) > +{ > + assert((!range->begin && !range->end) /* empty */ > + || range->begin <=3D range->end - 1); /* non-empty */ > +} > + > +#define static > +#define inline Yeah, that's a bit of a hack. I can live with it though. The other alternative is to squash 2 and 3 into a single patch on commit; but having them separate was a nice review aid. Reviewed-by: Eric Blake --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --vbqkCxthrtoJIgdEcepqJ7fnFX8mKbDl7 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/ iQEcBAEBCAAGBQJXYenIAAoJEKeha0olJ0NqAnAH/2vrbm8zwsjLD0O6+RisS8Jx T83cO56zlx+vn2WPJR1Sjr6PpWHlBm6DNQSkdLfWOCYz6akEkBWXFSstehHgcP6N COThuwjr2Cq4gwOUrIlRgRvfnIWK3zazO9x/mg2Lwnj375E4WsRYrI11bjDPcUGX 4WmlMOT2E+8VijXgOJBXOfTOTaLPI6x84cNcy3lYkqPonSuSZGHlKSWDBCEfClAE EMZ4qEZ2UMUeiFfTABsH+fjA4CrMGBclE4S+xmMLrg0blN9rHXwOvxzomSMZCryu 4BZlvjID183KD4THfkmFv31QFH4FWmy/eFEVgioNCrGxQTZHEWHEfw1zoPcOIFQ= =brFy -----END PGP SIGNATURE----- --vbqkCxthrtoJIgdEcepqJ7fnFX8mKbDl7--