From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41482) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WNLKz-0002nB-Rp for qemu-devel@nongnu.org; Tue, 11 Mar 2014 07:59:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WNLKu-0003gg-VM for qemu-devel@nongnu.org; Tue, 11 Mar 2014 07:59:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52087) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WNLKu-0003gM-Mj for qemu-devel@nongnu.org; Tue, 11 Mar 2014 07:59:08 -0400 Message-ID: <531EFA88.8010003@redhat.com> Date: Tue, 11 Mar 2014 05:59:04 -0600 From: Eric Blake MIME-Version: 1.0 References: <1394436721-21812-1-git-send-email-cyliu@suse.com> <1394436721-21812-6-git-send-email-cyliu@suse.com> <531E4A99.8050306@redhat.com> In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="gjqNWjkfTvXl2Jg22NjRw0dNT4NsjG6M7" Subject: Re: [Qemu-devel] [PATCH v22 05/25] add some QemuOpts functions for replace work List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Chunyan Liu Cc: Kevin Wolf , Dong Xu Wang , qemu-devel@nongnu.org, stefanha@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --gjqNWjkfTvXl2Jg22NjRw0dNT4NsjG6M7 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 03/10/2014 11:29 PM, Chunyan Liu wrote: >> >> Why are your later callers using a common helper function, but >> qemu_opt_get_del() repeating a lot of the body of qemu_opt_get()? >> Shouldn't qemu_opt_get() and qemu_opt_get_del() call into a common hel= per? >> >> qemu_opt_get_del must return (char *), but the existing qemu_opt_get > returns > (const char *). Could also change qemu_opt_get return value to (char *)= > type, > then these two functions could use a common helper function. But there = are > too > many places using qemu_opt_get already, if the return value type change= s, > it will > affect a lot. Going from 'char *' to 'const char *' is automatic. Have your helper return 'char *', and qemu_opt_get can call it just fine and give its callers their desired const char *. >> >> Same problem as in 4/25 - I don't think you can rely on >> opt->value.boolean being valid if you don't track the union >> discriminator, and right now, the union discriminator is tracked only >> via opt->desc. >=20 >=20 > Couldn't find a reliable way if the option is passed through > opts_accept_any, > just no way to check the option type. >=20 Like I said in 4/25, if the option is passed through opts_accept_any, treat it as string only; and make the opt_get_bool function either reject it outright, or to always do the string-to-bool conversion at the time of the lookup: if (opt->desc) { assert(opt->desc->type =3D=3D QEMU_OPT_BOOL); return opt->value.boolean; } else { code to parse opt->str } >> > Could be if changing qemu_opt_get return value type, but just as said > before, > that will affect many codes. Also, changing an existing function that returns 'const char *' into now returning 'char *' will NOT break any callers if the semantics remain unchanged (what WILL break is if the semantics change where the callers must now free the result). But in general, it should still be just fine to have qemu_opt_get return 'const char *' even if the common helper returns 'char *'. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --gjqNWjkfTvXl2Jg22NjRw0dNT4NsjG6M7 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJTHvqIAAoJEKeha0olJ0Nq3r0H/2vXblJZGM46ukOPYkeWbTLK 7U+W5G+lrtz35eUygK1EWZ9xUwCq8YcNTbkjYFYwxBjOEsTy1PoFgWVXvtcYv/KA FNBRTadkXG0iHAxYpQtj929rjqPNdz/xPwMBW7hqMYLqwYPoxTIUIYaW35t+v8P4 z+zF9zykSlz6TXLzZvdsCXAa13/eedJGJi0/TLzZTDWd6YAOaw1ScghRmyufO2u5 kWtFOYT4wHp6u2/WYecPpAjMmB0wudgj1BDptOC9vCBJ1JFOPDBmEN7BpiY7wfzp 2fd0UCJNKeWnzI5wL4y8eM/sfPDW1ytxvBqvjFhATSQc5TBSvgJdcXZFF+mHYgE= =aupA -----END PGP SIGNATURE----- --gjqNWjkfTvXl2Jg22NjRw0dNT4NsjG6M7--