[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v9 04/26] win32: Simplify gmtime_r detection direct base on _
From: |
Daniel P . Berrangé |
Subject: |
Re: [PATCH v9 04/26] win32: Simplify gmtime_r detection direct base on _POSIX_THREAD_SAFE_FUNCTIONS. |
Date: |
Tue, 15 Sep 2020 14:00:01 +0100 |
User-agent: |
Mutt/1.14.6 (2020-07-11) |
On Tue, Sep 15, 2020 at 08:12:56PM +0800, Yonggang Luo wrote:
> First, this reduce the size of configure, configure are tending to removal in
> future,
> and this didn't introduce any new feature or remove any exist feature.
> Second, the current localtime_r detection are conflict with ncursesw
> detection in
> mingw, when ncursesw detected, it will provide the following compile flags
> pkg-config --cflags ncursesw
> -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=199506L
> -IC:/CI-Tools/msys64/mingw64/include/ncursesw
> And the compile flag _POSIX_C_SOURCE will always cause
> _POSIX_THREAD_SAFE_FUNCTIONS to
> be defined, in new version of mingw, that's will cause localtime_r to be
> defined.
> But the configure script didn't provide _POSIX_C_SOURCE macro, and that's
> will result
> localtime_r not detected because localtime_r are defined in forceinline
> manner.
ncursesw is just one of the three curses impls we can select for
building against, so it doesn't feel right to make an assumption
that _POSIX_C_SOURCE is always defined.
>
> And finally cause conflict between QEMU defined localtime_r
> struct tm *localtime_r(const time_t *timep, struct tm *result);
> with mingw defined localtime_r
>
> ```
> #if defined(_POSIX_C_SOURCE) && !defined(_POSIX_THREAD_SAFE_FUNCTIONS)
> #define _POSIX_THREAD_SAFE_FUNCTIONS 200112L
> #endif
>
> #ifdef _POSIX_THREAD_SAFE_FUNCTIONS
> __forceinline struct tm *__CRTDECL localtime_r(const time_t *_Time, struct tm
> *_Tm) {
> return localtime_s(_Tm, _Time) ? NULL : _Tm;
> }
> __forceinline struct tm *__CRTDECL gmtime_r(const time_t *_Time, struct tm
> *_Tm) {
> return gmtime_s(_Tm, _Time) ? NULL : _Tm;
> }
> __forceinline char *__CRTDECL ctime_r(const time_t *_Time, char *_Str) {
> return ctime_s(_Str, 0x7fffffff, _Time) ? NULL : _Str;
> }
> __forceinline char *__CRTDECL asctime_r(const struct tm *_Tm, char * _Str) {
> return asctime_s(_Str, 0x7fffffff, _Tm) ? NULL : _Str;
> }
> #endif
> ```
>
> So I suggest remove this configure script, and restrict msys2/mingw version
> to easy to maintain.
> And use _POSIX_THREAD_SAFE_FUNCTIONS to guard the localtime_r and counterpart
> functions
>
> Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
> ---
> configure | 34 ----------------------------------
> include/sysemu/os-win32.h | 4 ++--
> util/oslib-win32.c | 2 +-
> 3 files changed, 3 insertions(+), 37 deletions(-)
>
> diff --git a/configure b/configure
> index dc4b7a2e55..bac48b5b49 100755
> --- a/configure
> +++ b/configure
> @@ -2496,37 +2496,6 @@ if test "$vhost_net" = ""; then
> test "$vhost_kernel" = "yes" && vhost_net=yes
> fi
>
> -##########################################
> -# MinGW / Mingw-w64 localtime_r/gmtime_r check
> -
> -if test "$mingw32" = "yes"; then
> - # Some versions of MinGW / Mingw-w64 lack localtime_r
> - # and gmtime_r entirely.
> - #
> - # Some versions of Mingw-w64 define a macro for
> - # localtime_r/gmtime_r.
> - #
> - # Some versions of Mingw-w64 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
>
> @@ -7088,9 +7057,6 @@ if [ "$bsd" = "yes" ] ; then
> echo "CONFIG_BSD=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
> diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h
> index d8978e28c0..3ac8a53bac 100644
> --- a/include/sysemu/os-win32.h
> +++ b/include/sysemu/os-win32.h
> @@ -48,12 +48,12 @@
> #define siglongjmp(env, val) longjmp(env, val)
>
> /* Missing POSIX functions. Don't use MinGW-w64 macros. */
> -#ifndef CONFIG_LOCALTIME_R
> +#ifndef _POSIX_THREAD_SAFE_FUNCTIONS
> #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 */
> +#endif
>
> static inline void os_setup_signal_handling(void) {}
> static inline void os_daemonize(void) {}
> diff --git a/util/oslib-win32.c b/util/oslib-win32.c
> index c654dafd93..f2fa9a3549 100644
> --- a/util/oslib-win32.c
> +++ b/util/oslib-win32.c
> @@ -106,7 +106,7 @@ void qemu_anon_ram_free(void *ptr, size_t size)
> }
> }
>
> -#ifndef CONFIG_LOCALTIME_R
> +#ifndef _POSIX_THREAD_SAFE_FUNCTIONS
> /* FIXME: add proper locking */
> struct tm *gmtime_r(const time_t *timep, struct tm *result)
> {
> --
> 2.28.0.windows.1
>
>
Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
- [PATCH v9 00/26] W32, W64 msys2/mingw patches, Yonggang Luo, 2020/09/15
- [PATCH v9 01/26] rcu: Implement drain_call_rcu, Yonggang Luo, 2020/09/15
- [PATCH v9 02/26] ci: fixes msys2 build by upgrading capstone to 4.0.2, Yonggang Luo, 2020/09/15
- [PATCH v9 03/26] configure: Fixes ncursesw detection under msys2/mingw and enable curses, Yonggang Luo, 2020/09/15
- [PATCH v9 04/26] win32: Simplify gmtime_r detection direct base on _POSIX_THREAD_SAFE_FUNCTIONS., Yonggang Luo, 2020/09/15
- Re: [PATCH v9 04/26] win32: Simplify gmtime_r detection direct base on _POSIX_THREAD_SAFE_FUNCTIONS.,
Daniel P . Berrangé <=
- [PATCH v9 05/26] curses: Fixes curses compiling errors., Yonggang Luo, 2020/09/15
- [PATCH v9 06/26] tests: disable /char/stdio/* tests in test-char.c on win32, Yonggang Luo, 2020/09/15
- [PATCH v9 07/26] tests: Fixes test-replication.c on msys2/mingw., Yonggang Luo, 2020/09/15
- [PATCH v9 08/26] tests: test-replication disable /replication/secondary/* on msys2/mingw., Yonggang Luo, 2020/09/15
- [PATCH v9 09/26] osdep: file locking functions are not available on Win32, Yonggang Luo, 2020/09/15
- [PATCH v9 10/26] meson: Use -b to ignore CR vs. CR-LF issues on Windows, Yonggang Luo, 2020/09/15
- [PATCH v9 11/26] gcrypt: test_tls_psk_init should write binary file instead text file., Yonggang Luo, 2020/09/15
- [PATCH v9 12/26] tests: Enable crypto tests under msys2/mingw, Yonggang Luo, 2020/09/15