From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40708) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZeRhW-0006YN-OQ for qemu-devel@nongnu.org; Tue, 22 Sep 2015 13:49:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZeRhT-0001me-Ek for qemu-devel@nongnu.org; Tue, 22 Sep 2015 13:49:58 -0400 Received: from [2a03:4000:1::4e2f:c7ac:d] (port=48905 helo=v220110690675601.yourvserver.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZeRhT-0001lI-4Z for qemu-devel@nongnu.org; Tue, 22 Sep 2015 13:49:55 -0400 Message-ID: <560194B4.7060201@weilnetz.de> Date: Tue, 22 Sep 2015 19:49:40 +0200 From: Stefan Weil MIME-Version: 1.0 References: <1442931206-869-1-git-send-email-berrange@redhat.com> In-Reply-To: <1442931206-869-1-git-send-email-berrange@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="3ltRDQqetLP35dTvxpUF547P4LGlCdLU4" Subject: Re: [Qemu-devel] [PATCH v2 REPOST] oslib-win32: only provide localtime_r/gmtime_r if missing List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Daniel P. Berrange" , qemu-devel@nongnu.org Cc: Kevin Wolf , Peter Maydell , "Michael S. Tsirkin" , Stefan Hajnoczi , "Denis V. Lunev" , Igor Mammedov This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --3ltRDQqetLP35dTvxpUF547P4LGlCdLU4 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: quoted-printable Hi, I suggest cleaning some comments, mostly using the "official" spellings for MinGW and Mingw-w64. Am 22.09.2015 um 16:13 schrieb Daniel P. Berrange: > The oslib-win32 file currently provides a localtime_r and > gmtime_r replacement unconditionally. Some versions of > Mingw64 would provide crude macros for localtime_r/gmtime_r MinGW / Mingw-w64 > which QEMU takes care to disable. Latest versions of Mingw64 Mingw-w64 > now provide actual functions for localtime_r/gmtime_r, but > with a twist that you have to include unistd.h or pthread.h > before including time.h. By luck some files in QEMU have > such an include order, resulting in compile errors: >=20 > CC util/osdep.o > In file included from include/qemu-common.h:48:0, > from util/osdep.c:48: > include/sysemu/os-win32.h:77:12: error: redundant redeclaration of 'gmt= ime_r' [-Werror=3Dredundant-decls] > struct tm *gmtime_r(const time_t *timep, struct tm *result); > ^ > In file included from include/qemu-common.h:35:0, > from util/osdep.c:48: > /usr/i686-w64-mingw32/sys-root/mingw/include/time.h:272:107: note: prev= ious definition of 'gmtime_r' was here > In file included from include/qemu-common.h:48:0, > from util/osdep.c:48: > include/sysemu/os-win32.h:79:12: error: redundant redeclaration of 'loc= altime_r' [-Werror=3Dredundant-decls] > struct tm *localtime_r(const time_t *timep, struct tm *result); > ^ > In file included from include/qemu-common.h:35:0, > from util/osdep.c:48: > /usr/i686-w64-mingw32/sys-root/mingw/include/time.h:269:107: note: prev= ious definition of 'localtime_r' was here >=20 > This change adds a configure test to see if localtime_r > exits, and only enables the QEMU impl if missing. We also > re-arrange qemu-common.h try attempt to guarantee that all > source files get unistd.h before time.h and thus see the > localtime_r/gmtime_r defs. >=20 > Signed-off-by: Daniel P. Berrange > --- > configure | 34 ++++++++++++++++++++++++++++++++++ > include/qemu/osdep.h | 4 +++- > include/sysemu/os-win32.h | 2 ++ > util/oslib-win32.c | 2 ++ > 4 files changed, 41 insertions(+), 1 deletion(-) >=20 > diff --git a/configure b/configure > index 52f5b79..4654be8 100755 > --- a/configure > +++ b/configure > @@ -1737,6 +1737,37 @@ else > fi > =20 > ########################################## > +# Mingw64 localtime_r/gmtime_r check MinGW / Mingw-w64 > + > +if test "$mingw32" =3D "yes"; then > + # Some versions of Mingw32/64 lack localtime_r MinGW / Mingw-w64 > + # and gmtime_r entirely Missing . > + # > + # Some versions of Mingw64 define a macro for Mingw-w64 > + # localtime_r/gmtime_r/etc Why etc? Missing . > + # > + # Some versions of Ming64 will define functions > + # for localtime_r/gmtime_r, but only if you have > + # _POSIX_THREAD_SAFE_FUNCTIONS defined. For fun > + # though, unistd.h and pthread.h both define > + # that for you. > + # > + # So this #undef localtime_r and #include > + # are not in fact redundant Missing . > +cat > $TMPC << EOF > +#include > +#include > +#undef localtime_r > +int main(void) { localtime_r(NULL, NULL); return 0; } > +EOF > + if compile_prog "" "" ; then > + localtime_r=3D"yes" > + else > + localtime_r=3D"no" > + fi > +fi > + > +########################################## > # pkg-config probe > =20 > if ! has "$pkg_config_exe"; then > @@ -5050,6 +5081,9 @@ fi > if test "$zero_malloc" =3D "yes" ; then > echo "CONFIG_ZERO_MALLOC=3Dy" >> $config_host_mak > fi > +if test "$localtime_r" =3D "yes" ; then > + echo "CONFIG_LOCALTIME_R=3Dy" >> $config_host_mak > +fi > if test "$qom_cast_debug" =3D "yes" ; then > echo "CONFIG_QOM_CAST_DEBUG=3Dy" >> $config_host_mak > fi > diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h > index ab3c876..e490028 100644 > --- a/include/qemu/osdep.h > +++ b/include/qemu/osdep.h > @@ -38,10 +38,12 @@ > #include > #include > #include > +/* Put unistd.h before time.h as that triggers localtime_r/gmtime_r > + * function availability on recentish Mingw64 platforms */ Mingw-w64. I'm not sure how long this hack will work. A future patch could add -DPOSIX_C_SOURCE to the compiler options if configure has set $localtime_r. > +#include > #include > #include > #include > -#include > #include > #include > #include > diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h > index 706d85a..13dcef6 100644 > --- a/include/sysemu/os-win32.h > +++ b/include/sysemu/os-win32.h > @@ -73,10 +73,12 @@ > #define siglongjmp(env, val) longjmp(env, val) > =20 > /* Missing POSIX functions. Don't use MinGW-w64 macros. */ > +#ifndef CONFIG_LOCALTIME_R > #undef gmtime_r > struct tm *gmtime_r(const time_t *timep, struct tm *result); > #undef localtime_r > struct tm *localtime_r(const time_t *timep, struct tm *result); > +#endif /* CONFIG_LOCALTIME_R */ > =20 > =20 > static inline void os_setup_signal_handling(void) {} > diff --git a/util/oslib-win32.c b/util/oslib-win32.c > index 730a670..08f5a9c 100644 > --- a/util/oslib-win32.c > +++ b/util/oslib-win32.c > @@ -95,6 +95,7 @@ void qemu_anon_ram_free(void *ptr, size_t size) > } > } > =20 > +#ifndef CONFIG_LOCALTIME_R > /* FIXME: add proper locking */ > struct tm *gmtime_r(const time_t *timep, struct tm *result) > { > @@ -118,6 +119,7 @@ struct tm *localtime_r(const time_t *timep, struct = tm *result) > } > return p; > } > +#endif /* CONFIG_LOCALTIME_R */ > =20 > void qemu_set_block(int fd) > { >=20 Otherwise this patch looks good. If you agree, I'd clean the comments before I add the patch to my patch queue for Windows (git://qemu.weilnetz.de/qemu.git wxx). Regards Stefan --3ltRDQqetLP35dTvxpUF547P4LGlCdLU4 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 iQIcBAEBCAAGBQJWAZS7AAoJEOCMIdVndFCtCUkQAIPGfgHrK592h8N747bSA1M5 yNblYuJYTGS/tiqMtbTyHkKp/plhcDQhgrZvfOLk2LxgDzboziEWRrW2aQkOi0+6 uQfcRohWQ2sJK9PFVwxU4CU0J+QwbaYfgdHekYDNP0aRYhvZBpJ4RKfPevd5jnuR qv50frb/5d1s91p0jCPg+X9dG1AKxaIAGXHA5TJko7OPbBRWs7Akg43aQZY8h2/5 ABbHa9RdQHbQJ8c1SsiLCRBjaRvnj65+/qi214w9MjjSbqIHEDw2DgGmmGY4jkK1 SiBadW12tL4A0An9foh4hpw40iLMqrArXppUjKuzK3cIS1OCUbKlY/Rtwndev3Sg bfVqBLms/kl4l/Kc/kgnZb5u0W6bE1EnHYWtwHNB5khY7Tg8368ofz0fJKPPjNvd CQnPS7llO0VoAuwp86HnJUaEOzNURXXaQ0cVp9wF91cRDIhiUtnxGYhB6MPTbN27 Ju+5NPTdl+NE7Mzt9ne4VnJ1zWYTo1ANuon3sWONu+dZ6bFJmVAw0cxbyibjnJ40 0WaiZUeqvt9LbVWu05/fNy4ecal7LaqEpQKnHaQTTQWxGTewSTM2doXS+zGAfp4F 4ZTV0hbAjWs/0slvZJngu3Es9yqEomEs6BIQ/7bjXZluUvMYNQfPzxkTCRVjaBmm bYLbptmWVGtpUzrB6YUl =YsUt -----END PGP SIGNATURE----- --3ltRDQqetLP35dTvxpUF547P4LGlCdLU4--