Received: from eggs.gnu.org ([2001:4830:134:3::10]:53013) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhzpJ-0004sV-Bz for qemu-devel@nongnu.org; Thu, 08 Sep 2016 09:57:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bhzpG-0003o4-6B for qemu-devel@nongnu.org; Thu, 08 Sep 2016 09:57:13 -0400 Received: from mx5-phx2.redhat.com ([209.132.183.37]:57806) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhzpF-0003nw-Sz for qemu-devel@nongnu.org; Thu, 08 Sep 2016 09:57:10 -0400 Date: Thu, 8 Sep 2016 09:57:07 -0400 (EDT) From: =?utf-8?Q?Marc-Andr=C3=A9?= Lureau Message-ID: <713199828.881587.1473343027546.JavaMail.zimbra@redhat.com> In-Reply-To: <869f8b57-873e-217b-bb9d-bd44d0e82bb8@redhat.com> References: <20160908084036.5938-1-marcandre.lureau@redhat.com> <869f8b57-873e-217b-bb9d-bd44d0e82bb8@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCHv5] tests: add qtest_add_data_func_full List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: =?utf-8?Q?Marc-Andr=C3=A9?= Lureau , qemu-devel@nongnu.org, armbru@redhat.com, peter maydell Hi ----- Original Message ----- > On 09/08/2016 03:40 AM, Marc-Andr=C3=A9 Lureau wrote: > > Allows one to specify a destroy function for the test data. > >=20 > > Add a fallback using glib g_test_add_vtable() internal function, whose > > signature changed over time. Tested with glib 2.22, 2.26 and 2.48, whic= h > > according to git log should be enough to cover all variations. > >=20 > > Signed-off-by: Marc-Andr=C3=A9 Lureau > > --- > > tests/libqtest.c | 19 +++++++++++++++++++ > > tests/libqtest.h | 17 +++++++++++++++++ > > 2 files changed, 36 insertions(+) > >=20 > > diff --git a/tests/libqtest.c b/tests/libqtest.c > > index eb00f13..5f4450f 100644 > > --- a/tests/libqtest.c > > +++ b/tests/libqtest.c > > @@ -758,6 +758,25 @@ void qtest_add_func(const char *str, void (*fn)(vo= id)) > > g_free(path); > > } > > =20 > > +void qtest_add_data_func_full(const char *str, void *data, > > + void (*fn)(const void *), > > + GDestroyNotify data_free_func) > > +{ > > + gchar *path =3D g_strdup_printf("/%s/%s", qtest_get_arch(), str); > > +#if GLIB_CHECK_VERSION(2, 34, 0) > > + g_test_add_data_func_full(path, data, fn, data_free_func); > > +#elif GLIB_CHECK_VERSION(2, 26, 0) > > + /* back-compat casts, remove this once we can require new-enough g= lib > > */ > > + g_test_add_vtable(path, 0, data, NULL, > > + (GTestFixtureFunc)fn, (GTestFixtureFunc) > > data_free_func); > > +#elif GLIB_CHECK_VERSION(2, 22, 0) >=20 > Perhaps this could be written as #else, since we have no further > alternatives (2.22.0 being our minimum). Up to the maintainer if it is > worth changing. Otherwise I think the end result is reasonable, and you > were able to avoid the leaks. >=20 > Reviewed-by: Eric Blake Ack, I'll change it. thanks