w32: Add implementation of gmtime_r, localtime_r
PATCH 1/1 w32: Add implementation of gmtime_r, localtime_r
Those functions are missing in MinGW.
Some versions of MinGW-w64 include defines for gmtime_r and localtime_r. Older versions of these macros are buggy (they return a pointer to a static variable), therefore we don't want them. Newer versions are similar to the code used here, but without the memset.
The implementation which is used here is not strictly reentrant, but sufficiently good for QEMU on w32 or w64.
--- oslib-win32.c | 22 ++++++++++++++++++++++ qemu-os-win32.h | 6 ++++++ 2 files changed, 28 insertions(+)
oslib-win32.c +22 -0
@@ -74,6 +74,28 @@ void qemu_vfree(void *ptr)VirtualFree (ptr,0 ,MEM_RELEASE ); } +struct tm *gmtime_r (const time_t *timep,struct tm *result) +{ +struct tm *p =gmtime (timep); +memset (result,0 ,sizeof (*result)); +if (p) { + *result = *p; + p = result; + } +return p; +} + +struct tm *localtime_r (const time_t *timep,struct tm *result) +{ +struct tm *p =localtime (timep); +memset (result,0 ,sizeof (*result)); +if (p) { + *result = *p; + p = result; + } +return p; +} +void socket_set_block (int fd) {unsigned long opt =0 ;
qemu-os-win32.h +6 -0
@@ -68,6 +68,12 @@/* Declaration of ffs() is missing in MinGW's strings.h. */ int ffs (int i); +/* Missing POSIX functions. Don't use MinGW-w64 macros. */ +#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); +static inline void os_setup_signal_handling (void ) {}static inline void os_daemonize (void ) {}static inline void os_setup_post (void ) {}
Signature · 1 line
1.7.10
Quoted 9 lines · Stefan Weil
Those functions are missing in MinGW.
Some versions of MinGW-w64 include defines for
gmtime_randlocaltime_r. Older versions of these macros are buggy (they return a pointer to a static variable), therefore we don't want them. Newer versions are similar to the code used here, but without the memset.The implementation which is used here is not strictly reentrant, but sufficiently good for QEMU on w32 or w64.
For now, but nothing shows that there is a problem. Adding a few simple locks shouldn't be difficult, or FIXME/XXX comment otherwise.
Quoted 61 lines
Signed-off-by Stefan Weil <[email protected]>--- oslib-win32.c | 22 ++++++++++++++++++++++ qemu-os-win32.h | 6 ++++++ 2 files changed, 28 insertions(+)oslib-win32.c +22
-0@@ -74,6 +74,28 @@ void qemu_vfree(void *ptr)VirtualFree (ptr,0 ,MEM_RELEASE ); } +struct tm *gmtime_r (const time_t *timep,struct tm *result) +{ +struct tm *p =gmtime (timep); +memset (result,0 ,sizeof (*result)); +if (p) { + *result = *p; + p = result; + } +return p; +} + +struct tm *localtime_r (const time_t *timep,struct tm *result) +{ +struct tm *p =localtime (timep); +memset (result,0 ,sizeof (*result)); +if (p) { + *result = *p; + p = result; + } +return p; +} +void socket_set_block (int fd) {unsigned long opt =0 ;qemu-os-win32.h +6
-1@@ -68,6 +68,12 @@/* Declaration of ffs() is missing in MinGW's strings.h. */ int ffs (int i); +/* Missing POSIX functions. Don't use MinGW-w64 macros. */ +#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); +static inline void os_setup_signal_handling (void ) {}static inline void os_daemonize (void ) {}static inline void os_setup_post (void ) {} --1.7.10
Quoted 8 lines · Stefan Weil
Quoted 7 lines
Those functions are missing in MinGW.
Some versions of MinGW-w64 include defines for
gmtime_randlocaltime_r. Older versions of these macros are buggy (they return a pointer to a static variable), therefore we don't want them. Newer versions are similar to the code used here, but without the memset.
Quoted 6 lines
Quoted 2 lines
The implementation which is used here is not strictly reentrant, but sufficiently good for QEMU on w32 or w64.
For now, but nothing shows that there is a problem. Adding a few simple locks shouldn't be difficult, or FIXME/XXX comment otherwise.
Does (or will) QEMU support preemptive scheduling of threads? If not, there is no reentrancy problem because gmtime / localtime don't trigger scheduling.
Of course adding comments is always a good idea. Feel free to add one or wait until I send a v2 patch.
Regards
Stefan
Quoted 11 lines · Stefan Weil
Quoted 11 lines · Stefan Weil
Quoted 9 lines
Those functions are missing in MinGW.
Some versions of MinGW-w64 include defines for
gmtime_randlocaltime_r. Older versions of these macros are buggy (they return a pointer to a static variable), therefore we don't want them. Newer versions are similar to the code used here, but without the memset.The implementation which is used here is not strictly reentrant, but sufficiently good for QEMU on w32 or w64.
Quoted 7 lines
Quoted 3 lines
For now, but nothing shows that there is a problem. Adding a few simple locks shouldn't be difficult, or FIXME/XXX comment otherwise.
Does (or will) QEMU support preemptive scheduling of threads? If not, there is no reentrancy problem because gmtime / localtime don't trigger scheduling.
Right, but it looks like the plan is to use thread safe versions. If not, reverting the original patch that introduced _r versions would have been OK.
Quoted 3 lines
Of course adding comments is always a good idea. Feel free to add one or wait until I send a v2 patch.
OK, I'll add a comment.
Quoted 6 lines
Regards
Stefan
Blue Swirl
AppliedQuoted 11 lines · Stefan Weil
Those functions are missing in MinGW.
Some versions of MinGW-w64 include defines for
gmtime_randlocaltime_r. Older versions of these macros are buggy (they return a pointer to a static variable), therefore we don't want them. Newer versions are similar to the code used here, but without the memset.The implementation which is used here is not strictly reentrant, but sufficiently good for QEMU on w32 or w64.
Signed-off-by Stefan Weil <[email protected]>
Thanks, applied with comment.
Quoted 59 lines
--- oslib-win32.c | 22 ++++++++++++++++++++++ qemu-os-win32.h | 6 ++++++ 2 files changed, 28 insertions(+)oslib-win32.c +22
-0@@ -74,6 +74,28 @@ void qemu_vfree(void *ptr)VirtualFree (ptr,0 ,MEM_RELEASE ); } +struct tm *gmtime_r (const time_t *timep,struct tm *result) +{ +struct tm *p =gmtime (timep); +memset (result,0 ,sizeof (*result)); +if (p) { + *result = *p; + p = result; + } +return p; +} + +struct tm *localtime_r (const time_t *timep,struct tm *result) +{ +struct tm *p =localtime (timep); +memset (result,0 ,sizeof (*result)); +if (p) { + *result = *p; + p = result; + } +return p; +} +void socket_set_block (int fd) {unsigned long opt =0 ;qemu-os-win32.h +6
-1@@ -68,6 +68,12 @@/* Declaration of ffs() is missing in MinGW's strings.h. */ int ffs (int i); +/* Missing POSIX functions. Don't use MinGW-w64 macros. */ +#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); +static inline void os_setup_signal_handling (void ) {}static inline void os_daemonize (void ) {}static inline void os_setup_post (void ) {} --1.7.10