oslib-win32: only provide localtime_r/gmtime_r if missing
PATCH v2 1/1 oslib-win32: only provide localtime_r/gmtime_r if missing
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 which QEMU takes care to disable. Latest versions of Mingw64 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:
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 'gmtime_r' [-Werror=redundant-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: previous 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 'localtime_r' [-Werror=redundant-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: previous definition of 'localtime_r' was here
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.
--- 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(-)
configure +34 -0
@@ -1737,6 +1737,37 @@ else fi ########################################## +# Mingw64 localtime_r/gmtime_r check + +if test "$mingw32" = "yes"; then + # Some versions of Mingw32/64 lack localtime_r + # and gmtime_r entirely + # + # Some versions of Mingw64 define a macro for + # localtime_r/gmtime_r/etc + # + # 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 <unistd.h> + # are not in fact redundant +cat > $TMPC << EOF +#include <unistd.h> +#include <time.h> +#undef localtime_r +int main(void) { localtime_r(NULL, NULL); return 0; } +EOF + if compile_prog "" "" ; then + localtime_r="yes" + else + localtime_r="no" + fi +fi + +########################################## # pkg-config probe if ! has "$pkg_config_exe"; then
@@ -5050,6 +5081,9 @@ fi if test "$zero_malloc" = "yes" ; then echo "CONFIG_ZERO_MALLOC=y" >> $config_host_mak fi +if test "$localtime_r" = "yes" ; then + echo "CONFIG_LOCALTIME_R=y" >> $config_host_mak +fi if test "$qom_cast_debug" = "yes" ; then echo "CONFIG_QOM_CAST_DEBUG=y" >> $config_host_mak fi
include/qemu/osdep.h +3 -1
@@ -38,10 +38,12 @@#include <strings.h> #include <inttypes.h> #include <limits.h> +/* Put unistd.h before time.h as that triggers localtime_r/gmtime_r +* function availability on recentish Mingw64 platforms */ +#include <unistd.h> #include <time.h> #include <ctype.h> #include <errno.h> -#include <unistd.h> #include <fcntl.h> #include <sys/stat.h> #include <sys/time.h>
include/sysemu/os-win32.h +2 -0
@@ -73,10 +73,12 @@#define siglongjmp (env, val) longjmp(env, val)/* Missing POSIX functions. Don't use MinGW-w64 macros. */ +#ifndef CONFIG_LOCALTIME_R #undef gmtime_rstruct tm *gmtime_r (const time_t *timep,struct tm *result);#undef localtime_rstruct tm *localtime_r (const time_t *timep,struct tm *result); +#endif /* CONFIG_LOCALTIME_R */ static inline void os_setup_signal_handling (void ) {}
util/oslib-win32.c +2 -0
@@ -95,6 +95,7 @@ void qemu_anon_ram_free(void *ptr, size_t size) } } +#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 */ void qemu_set_block (int fd) {
Signature · 1 line
2.4.3
Quoted 141 lines · Daniel P. Berrange
The oslib-win32 file currently provides a
localtime_randgmtime_rreplacement unconditionally. Some versions of Mingw64 would provide crude macros for localtime_r/gmtime_r which QEMU takes care to disable. Latest versions of Mingw64 now provide actual functions for localtime_r/gmtime_r, but with a twist that you have to includeunistd.horpthread.hbefore includingtime.h. By luck some files in QEMU have such an include order, resulting in compile errors:CC
util/osdep.o
In file included frominclude/qemu-common.h:48:0,from util/osdep.c:48: include/sysemu/os-win32.h:77:12: error: redundant redeclaration of 'gmtime_r' [-Werror=redundant-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: previous 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 'localtime_r' [-Werror=redundant-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: previous definition of 'localtime_r' was hereThis change adds a configure test to see if
localtime_rexits, and only enables the QEMU impl if missing. We also re-arrangeqemu-common.htry attempt to guarantee that all source files getunistd.hbeforetime.hand thus see the localtime_r/gmtime_r defs.Signed-off-by Daniel P. Berrange <[email protected]>--- 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(-)configure +34
-0@@ -1737,6 +1737,37 @@ else fi ########################################## +# Mingw64 localtime_r/gmtime_r check + +if test "$mingw32" = "yes"; then + # Some versions of Mingw32/64 lack localtime_r + # and gmtime_r entirely + # + # Some versions of Mingw64 define a macro for + # localtime_r/gmtime_r/etc + # + # 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 <unistd.h> + # are not in fact redundant +cat > $TMPC << EOF +#include <unistd.h> +#include <time.h> +#undef localtime_r +int main(void) { localtime_r(NULL, NULL); return 0; } +EOF + if compile_prog "" "" ; then + localtime_r="yes" + else + localtime_r="no" + fi +fi + +########################################## # pkg-config probe if ! has "$pkg_config_exe"; then@@ -5050,6 +5081,9 @@ fi if test "$zero_malloc" = "yes" ; then echo "CONFIG_ZERO_MALLOC=y" >> $config_host_mak fi +if test "$localtime_r" = "yes" ; then + echo "CONFIG_LOCALTIME_R=y" >> $config_host_mak +fi if test "$qom_cast_debug" = "yes" ; then echo "CONFIG_QOM_CAST_DEBUG=y" >> $config_host_mak fiinclude/qemu/osdep.h +3
-1@@ -38,10 +38,12 @@#include <strings.h> #include <inttypes.h> #include <limits.h> +/* Put unistd.h before time.h as that triggers localtime_r/gmtime_r +* function availability on recentish Mingw64 platforms */ +#include <unistd.h> #include <time.h> #include <ctype.h> #include <errno.h> -#include <unistd.h> #include <fcntl.h> #include <sys/stat.h> #include <sys/time.h> include/sysemu/os-win32.h +2
-0@@ -73,10 +73,12 @@#define siglongjmp (env, val) longjmp(env, val)/* Missing POSIX functions. Don't use MinGW-w64 macros. */ +#ifndef CONFIG_LOCALTIME_R #undef gmtime_rstruct tm *gmtime_r (const time_t *timep,struct tm *result);#undef localtime_rstruct tm *localtime_r (const time_t *timep,struct tm *result); +#endif /* CONFIG_LOCALTIME_R */ static inline void os_setup_signal_handling (void ) {}util/oslib-win32.c +1
-0@@ -95,6 +95,7 @@ void qemu_anon_ram_free(void *ptr, size_t size) } } +#ifndef CONFIG_LOCALTIME_R /* FIXME: add proper locking */ struct tm *gmtime_r (const time_t *timep,struct tm *result) {
util/oslib-win32.c struct tm *localtime_r(const time_t *timep, struct tm *result) · line 125
Quoted 7 lines
util/oslib-win32.c +1
-0@@ -118,6 +119,7 @@ struct tm *localtime_r(const time_t *timep, struct tm *result) }return p; } +#endif /* CONFIG_LOCALTIME_R */ void qemu_set_block (int fd) {
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:
Quoted 3 lines
The oslib-win32 file currently provides a
localtime_randgmtime_rreplacement unconditionally. Some versions of Mingw64 would provide crude macros for localtime_r/gmtime_r
MinGW / Mingw-w64
Quoted 1 line
which QEMU takes care to disable. Latest versions of Mingw64
Mingw-w64
Quoted 42 lines
now provide actual functions for localtime_r/gmtime_r, but with a twist that you have to include
unistd.horpthread.hbefore includingtime.h. By luck some files in QEMU have such an include order, resulting in compile errors:CC
util/osdep.o
In file included frominclude/qemu-common.h:48:0,from util/osdep.c:48: include/sysemu/os-win32.h:77:12: error: redundant redeclaration of 'gmtime_r' [-Werror=redundant-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: previous 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 'localtime_r' [-Werror=redundant-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: previous definition of 'localtime_r' was hereThis change adds a configure test to see if
localtime_rexits, and only enables the QEMU impl if missing. We also re-arrangeqemu-common.htry attempt to guarantee that all source files getunistd.hbeforetime.hand thus see the localtime_r/gmtime_r defs.Signed-off-by Daniel P. Berrange <[email protected]>--- 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(-)configure +0
-0
configure else · line 1740
Quoted 4 lines
configure +1
-0@@ -1737,6 +1737,37 @@ else fi ########################################## +# Mingw64 localtime_r/gmtime_r check
MinGW / Mingw-w64
configure else · line 1743
Quoted 3 lines
configure +3
-0+ +if test "$mingw32" = "yes"; then + # Some versions of Mingw32/64 lack localtime_r
MinGW / Mingw-w64
configure else · line 1744
Quoted 1 line
configure +1
-0+ # and gmtime_r entirely
Missing .
configure else · line 1746
Quoted 2 lines
configure +2
-0+ # + # Some versions of Mingw64 define a macro for
Mingw-w64
configure else · line 1747
Quoted 1 line
configure +1
-0+ # localtime_r/gmtime_r/etc
Why etc? Missing .
configure else · line 1756
Quoted 9 lines
configure +9
-0+ # + # 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 <unistd.h> + # are not in fact redundant
Missing .
Quoted 32 lines
configure +17
-0+cat > $TMPC << EOF +#include <unistd.h> +#include <time.h> +#undef localtime_r +int main(void) { localtime_r(NULL, NULL); return 0; } +EOF + if compile_prog "" "" ; then + localtime_r="yes" + else + localtime_r="no" + fi +fi + +########################################## # pkg-config probe if ! has "$pkg_config_exe"; then@@ -5050,6 +5081,9 @@ fi if test "$zero_malloc" = "yes" ; then echo "CONFIG_ZERO_MALLOC=y" >> $config_host_mak fi +if test "$localtime_r" = "yes" ; then + echo "CONFIG_LOCALTIME_R=y" >> $config_host_mak +fi if test "$qom_cast_debug" = "yes" ; then echo "CONFIG_QOM_CAST_DEBUG=y" >> $config_host_mak fiinclude/qemu/osdep.h +0
-0
include/qemu/osdep.h line 42
Quoted 5 lines
include/qemu/osdep.h +2
-0@@ -38,10 +38,12 @@#include <strings.h> #include <inttypes.h> #include <limits.h> +/* 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.
Quoted 39 lines
include/qemu/osdep.h +1
-1+#include <unistd.h> #include <time.h> #include <ctype.h> #include <errno.h> -#include <unistd.h> #include <fcntl.h> #include <sys/stat.h> #include <sys/time.h> include/sysemu/os-win32.h +2
-0@@ -73,10 +73,12 @@#define siglongjmp (env, val) longjmp(env, val)/* Missing POSIX functions. Don't use MinGW-w64 macros. */ +#ifndef CONFIG_LOCALTIME_R #undef gmtime_rstruct tm *gmtime_r (const time_t *timep,struct tm *result);#undef localtime_rstruct tm *localtime_r (const time_t *timep,struct tm *result); +#endif /* CONFIG_LOCALTIME_R */ static inline void os_setup_signal_handling (void ) {}util/oslib-win32.c +1
-0@@ -95,6 +95,7 @@ void qemu_anon_ram_free(void *ptr, size_t size) } } +#ifndef CONFIG_LOCALTIME_R /* FIXME: add proper locking */ struct tm *gmtime_r (const time_t *timep,struct tm *result) {
util/oslib-win32.c struct tm *localtime_r(const time_t *timep, struct tm *result) · line 125
Quoted 7 lines
util/oslib-win32.c +1
-0@@ -118,6 +119,7 @@ struct tm *localtime_r(const time_t *timep, struct tm *result) }return p; } +#endif /* CONFIG_LOCALTIME_R */ void qemu_set_block (int fd) {
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
Quoted 75 lines · Stefan Weil
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:
Quoted 3 lines
The oslib-win32 file currently provides a
localtime_randgmtime_rreplacement unconditionally. Some versions of Mingw64 would provide crude macros for localtime_r/gmtime_rMinGW / Mingw-w64
Quoted 1 line
which QEMU takes care to disable. Latest versions of Mingw64
Mingw-w64
Quoted 42 lines
now provide actual functions for localtime_r/gmtime_r, but with a twist that you have to include
unistd.horpthread.hbefore includingtime.h. By luck some files in QEMU have such an include order, resulting in compile errors:CC
util/osdep.o
In file included frominclude/qemu-common.h:48:0,from util/osdep.c:48: include/sysemu/os-win32.h:77:12: error: redundant redeclaration of 'gmtime_r' [-Werror=redundant-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: previous 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 'localtime_r' [-Werror=redundant-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: previous definition of 'localtime_r' was hereThis change adds a configure test to see if
localtime_rexits, and only enables the QEMU impl if missing. We also re-arrangeqemu-common.htry attempt to guarantee that all source files getunistd.hbeforetime.hand thus see the localtime_r/gmtime_r defs.Signed-off-by Daniel P. Berrange <[email protected]>--- 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(-)configure +0
-0configure else · line 1740
Quoted 4 lines
configure +1
-0@@ -1737,6 +1737,37 @@ else fi ########################################## +# Mingw64 localtime_r/gmtime_r checkMinGW / Mingw-w64
configure else · line 1743
Quoted 3 lines
configure +3
-0+ +if test "$mingw32" = "yes"; then + # Some versions of Mingw32/64 lack localtime_rMinGW / Mingw-w64
configure else · line 1744
Quoted 1 line
configure +1
-0+ # and gmtime_r entirelyMissing .
Quoted 8 lines
configure else · line 1746
Quoted 2 lines
configure +2
-0+ # + # Some versions of Mingw64 define a macro forMingw-w64
configure else · line 1747
Quoted 1 line
configure +1
-0+ # localtime_r/gmtime_r/etcWhy etc? Missing .
They also define macros for some other functions, but they don't cause us problems, so we're not dealing with them here. Simpler to just remove the /etc though.
Quoted 12 lines
configure else · line 1756
Quoted 10 lines
configure +9
-0+ # + # 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 <unistd.h> + # are not in fact redundant
Quoted 5 lines
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.gitwxx).
Yes, I'm fine with you applying it to your queue and adding the fixes mentioned.
Regards,
Daniel
Signature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Am 23.09.2015 um 10:33 schrieb Daniel P. Berrange:
Quoted 5 lines · Stefan Weil
Quoted 4 lines
Hi,
I suggest cleaning some comments, mostly using the "official" spellings for MinGW and Mingw-w64.
[...]
Quoted 11 lines
Quoted 5 lines
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.gitwxx).Yes, I'm fine with you applying it to your queue and adding the fixes mentioned.
Regards,
Daniel
Thanks. Your patch with the fixes is now applied togit://qemu.weilnetz.de/qemu.git wxx.
Stefan