On Tue, Apr 20, 2010 at 2:03 PM, Kai Tietz <[email protected]> wrote: > 2010/4/20 Ozkan Sezer <[email protected]>: >> On Tue, Apr 20, 2010 at 12:41 PM, Ozkan Sezer <[email protected]> wrote: >>> On Tue, Apr 20, 2010 at 7:37 AM, Kai Tietz <[email protected]> wrote: >>>> Hi Patrick, >>>> >>>> 2010/4/20 Patrick Galbraith <[email protected]>: >>>>> Hi all, >>>>> >>>>> I've stumbled across an issue with gettimeofday() returning an incorrect >>>>> value with mingw-w64. A simple code sample: >>>>> >>>>> #include <stdio.h> >>>>> #include <sys/time.h> >>>>> >>>>> int main (void) >>>>> { >>>>> struct timeval timer; >>>>> int retval; >>>>> retval= gettimeofday(&timer,NULL); >>>>> fprintf(stderr, "retval: %d\n", retval); >>>>> fprintf(stderr, "now: %ld\n", time(0)); >>>>> fprintf(stderr, "now: %ld\n", timer.tv_sec); >>>>> return(0); >>>>> >>>>> } >>>>> >>>>> When compiled using - >>>>> >>>>> regular mingw (correct output) >>>>> >>>>> Patrick galbra...@win-7a3e68a2d98 ~/dev/stuff >>>>> $ gcc -o mtime mtime.c >>>>> >>>>> Patrick galbra...@win-7a3e68a2d98 ~/dev/stuff >>>>> $ ./mtime.exe >>>>> retval: 0 >>>>> now: 1271722468 >>>>> now: 1271722468 >>>>> >>>>> mingw-w64: >>>>> >>>>> >>>>> Patrick galbra...@win-7a3e68a2d98 ~/dev/stuff >>>>> $ /c/mingw/bin/x86_64-w64-mingw32-gcc -o mtime mtime.c >>>>> >>>>> Patrick galbra...@win-7a3e68a2d98 ~/dev/stuff >>>>> $ ./mtime.exe >>>>> retval: 0 >>>>> now: 1271722480 >>>>> now: 31293027 >>>>> >>>>> Are there any known issues with gettimeofday() with mingw-w64? >>>>> >>>>> Thanks! >>>>> >>>>> Patrick >>>> >>>> what you are seeing here is that time_t type has changed for x64. x64 >>>> doesn't use any longer a 32-bit time_t type. I use 64-bit wide scalar >>>> instead. >>>> If you want to have 32-bit time_t the use please the <timefunction>32 >>>> function set and use instead tim32_t type. >>>> >>>> Regards, >>>> Kai >>> >>> I can't see the use of a time_t type anywhere in the report? >>> Is there a misunderstanding somewhere? >>> >>> The problem may be due to strict aliasing violations. >>> A warning doesn't appear with default CFLAGS, but >>> after adding -Wstrict-aliasing=2, you get >>> >>> gettimeofday.c: In function 'getntptimeofday': >>> gettimeofday.c:42: warning: dereferencing type-punned pointer will >>> break strict-aliasing rules >>> >>> The mingw.org version of gettimeofday.c doesn't exhibit >>> such an issue. Proper use of a union as it the mingw.org >>> version might be a solution. >>> >>> -- >>> Ozkan >>> >> >> Hmm, changing the FILETIME_1970 macro from 11644473600ull >> to 116444736000000000ULL in gettimeofday.c as in the mingw.org >> version seems to make the testcase output the same value. >> >> Kai, is this correct? (see attached g3.diff.) Please verify. >> >> -- >> Ozkan >> > > yeah, it is ok for apply and looks right. > > Thanks, > Kai
Applied to trunk as rev. 2259, and to the v1.0 branch as rev. 2260. Patrick, please verify that all your uses work as expected. -- Ozkan ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
