annotate Python/pytime.c @ 76597:76d2e0761d18

Issue #14428, #14397: Implement the PEP 418 * Rename time.steady() to time.monotonic() * On Windows, time.monotonic() uses GetTickCount/GetTickCount64() instead of QueryPerformanceCounter() * time.monotonic() uses CLOCK_HIGHRES if available * Add time.get_clock_info(), time.perf_counter() and time.process_time() functions
author Victor Stinner <victor.stinner@gmail.com>
date Sun, 29 Apr 2012 02:41:27 +0200
parents f554043badec
children 47c84e3f08ae
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
63757
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
1 #include "Python.h"
74821
bee7943d38c6 Issue #13845: time.time() now uses GetSystemTimeAsFileTime() instead of ftime()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 63757
diff changeset
2 #ifdef MS_WINDOWS
bee7943d38c6 Issue #13845: time.time() now uses GetSystemTimeAsFileTime() instead of ftime()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 63757
diff changeset
3 #include <windows.h>
bee7943d38c6 Issue #13845: time.time() now uses GetSystemTimeAsFileTime() instead of ftime()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 63757
diff changeset
4 #endif
63757
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
5
74821
bee7943d38c6 Issue #13845: time.time() now uses GetSystemTimeAsFileTime() instead of ftime()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 63757
diff changeset
6 #if defined(__APPLE__) && defined(HAVE_GETTIMEOFDAY) && defined(HAVE_FTIME)
63757
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
7 /*
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
8 * _PyTime_gettimeofday falls back to ftime when getttimeofday fails because the latter
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
9 * might fail on some platforms. This fallback is unwanted on MacOSX because
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
10 * that makes it impossible to use a binary build on OSX 10.4 on earlier
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
11 * releases of the OS. Therefore claim we don't support ftime.
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
12 */
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
13 # undef HAVE_FTIME
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
14 #endif
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
15
74821
bee7943d38c6 Issue #13845: time.time() now uses GetSystemTimeAsFileTime() instead of ftime()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 63757
diff changeset
16 #if defined(HAVE_FTIME) && !defined(MS_WINDOWS)
63757
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
17 #include <sys/timeb.h>
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
18 extern int ftime(struct timeb *);
74821
bee7943d38c6 Issue #13845: time.time() now uses GetSystemTimeAsFileTime() instead of ftime()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 63757
diff changeset
19 #endif
63757
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
20
76597
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
21 static void
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
22 pygettimeofday(_PyTime_timeval *tp, _Py_clock_info_t *info)
63757
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
23 {
74821
bee7943d38c6 Issue #13845: time.time() now uses GetSystemTimeAsFileTime() instead of ftime()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 63757
diff changeset
24 #ifdef MS_WINDOWS
bee7943d38c6 Issue #13845: time.time() now uses GetSystemTimeAsFileTime() instead of ftime()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 63757
diff changeset
25 FILETIME system_time;
bee7943d38c6 Issue #13845: time.time() now uses GetSystemTimeAsFileTime() instead of ftime()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 63757
diff changeset
26 ULARGE_INTEGER large;
74834
90eda29a8e03 Backout f8409b3d6449: the PEP 410 is not accepted yet
Victor Stinner <victor.stinner@haypocalc.com>
parents: 74832
diff changeset
27 ULONGLONG microseconds;
74821
bee7943d38c6 Issue #13845: time.time() now uses GetSystemTimeAsFileTime() instead of ftime()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 63757
diff changeset
28
bee7943d38c6 Issue #13845: time.time() now uses GetSystemTimeAsFileTime() instead of ftime()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 63757
diff changeset
29 GetSystemTimeAsFileTime(&system_time);
bee7943d38c6 Issue #13845: time.time() now uses GetSystemTimeAsFileTime() instead of ftime()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 63757
diff changeset
30 large.u.LowPart = system_time.dwLowDateTime;
bee7943d38c6 Issue #13845: time.time() now uses GetSystemTimeAsFileTime() instead of ftime()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 63757
diff changeset
31 large.u.HighPart = system_time.dwHighDateTime;
74834
90eda29a8e03 Backout f8409b3d6449: the PEP 410 is not accepted yet
Victor Stinner <victor.stinner@haypocalc.com>
parents: 74832
diff changeset
32 /* 11,644,473,600,000,000: number of microseconds between
74821
bee7943d38c6 Issue #13845: time.time() now uses GetSystemTimeAsFileTime() instead of ftime()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 63757
diff changeset
33 the 1st january 1601 and the 1st january 1970 (369 years + 89 leap
bee7943d38c6 Issue #13845: time.time() now uses GetSystemTimeAsFileTime() instead of ftime()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 63757
diff changeset
34 days). */
74834
90eda29a8e03 Backout f8409b3d6449: the PEP 410 is not accepted yet
Victor Stinner <victor.stinner@haypocalc.com>
parents: 74832
diff changeset
35 microseconds = large.QuadPart / 10 - 11644473600000000;
90eda29a8e03 Backout f8409b3d6449: the PEP 410 is not accepted yet
Victor Stinner <victor.stinner@haypocalc.com>
parents: 74832
diff changeset
36 tp->tv_sec = microseconds / 1000000;
90eda29a8e03 Backout f8409b3d6449: the PEP 410 is not accepted yet
Victor Stinner <victor.stinner@haypocalc.com>
parents: 74832
diff changeset
37 tp->tv_usec = microseconds % 1000000;
76597
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
38 if (info) {
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
39 DWORD timeAdjustment, timeIncrement;
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
40 BOOL isTimeAdjustmentDisabled;
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
41
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
42 info->implementation = "GetSystemTimeAsFileTime()";
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
43 info->is_monotonic = 0;
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
44 (void) GetSystemTimeAdjustment(&timeAdjustment, &timeIncrement,
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
45 &isTimeAdjustmentDisabled);
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
46 info->resolution = timeIncrement * 1e-7;
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
47 if (isTimeAdjustmentDisabled)
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
48 info->is_adjusted = 0;
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
49 else
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
50 info->is_adjusted = 1;
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
51 }
74821
bee7943d38c6 Issue #13845: time.time() now uses GetSystemTimeAsFileTime() instead of ftime()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 63757
diff changeset
52 #else
63757
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
53 /* There are three ways to get the time:
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
54 (1) gettimeofday() -- resolution in microseconds
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
55 (2) ftime() -- resolution in milliseconds
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
56 (3) time() -- resolution in seconds
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
57 In all cases the return value in a timeval struct.
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
58 Since on some systems (e.g. SCO ODT 3.0) gettimeofday() may
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
59 fail, so we fall back on ftime() or time().
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
60 Note: clock resolution does not imply clock accuracy! */
74821
bee7943d38c6 Issue #13845: time.time() now uses GetSystemTimeAsFileTime() instead of ftime()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 63757
diff changeset
61
63757
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
62 #ifdef HAVE_GETTIMEOFDAY
76597
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
63 int err;
63757
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
64 #ifdef GETTIMEOFDAY_NO_TZ
76597
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
65 err = gettimeofday(tp);
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
66 #else
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
67 err = gettimeofday(tp, (struct timezone *)NULL);
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
68 #endif
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
69 if (err == 0) {
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
70 if (info) {
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
71 info->implementation = "gettimeofday()";
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
72 info->resolution = 1e-6;
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
73 info->is_monotonic = 0;
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
74 info->is_adjusted = 1;
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
75 }
74834
90eda29a8e03 Backout f8409b3d6449: the PEP 410 is not accepted yet
Victor Stinner <victor.stinner@haypocalc.com>
parents: 74832
diff changeset
76 return;
76597
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
77 }
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
78 #endif /* HAVE_GETTIMEOFDAY */
74821
bee7943d38c6 Issue #13845: time.time() now uses GetSystemTimeAsFileTime() instead of ftime()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 63757
diff changeset
79
63757
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
80 #if defined(HAVE_FTIME)
74834
90eda29a8e03 Backout f8409b3d6449: the PEP 410 is not accepted yet
Victor Stinner <victor.stinner@haypocalc.com>
parents: 74832
diff changeset
81 {
90eda29a8e03 Backout f8409b3d6449: the PEP 410 is not accepted yet
Victor Stinner <victor.stinner@haypocalc.com>
parents: 74832
diff changeset
82 struct timeb t;
90eda29a8e03 Backout f8409b3d6449: the PEP 410 is not accepted yet
Victor Stinner <victor.stinner@haypocalc.com>
parents: 74832
diff changeset
83 ftime(&t);
90eda29a8e03 Backout f8409b3d6449: the PEP 410 is not accepted yet
Victor Stinner <victor.stinner@haypocalc.com>
parents: 74832
diff changeset
84 tp->tv_sec = t.time;
90eda29a8e03 Backout f8409b3d6449: the PEP 410 is not accepted yet
Victor Stinner <victor.stinner@haypocalc.com>
parents: 74832
diff changeset
85 tp->tv_usec = t.millitm * 1000;
76597
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
86 if (info) {
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
87 info->implementation = "ftime()";
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
88 info->resolution = 1e-3;
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
89 info->is_monotonic = 0;
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
90 info->is_adjusted = 1;
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
91 }
74834
90eda29a8e03 Backout f8409b3d6449: the PEP 410 is not accepted yet
Victor Stinner <victor.stinner@haypocalc.com>
parents: 74832
diff changeset
92 }
63757
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
93 #else /* !HAVE_FTIME */
74834
90eda29a8e03 Backout f8409b3d6449: the PEP 410 is not accepted yet
Victor Stinner <victor.stinner@haypocalc.com>
parents: 74832
diff changeset
94 tp->tv_sec = time(NULL);
90eda29a8e03 Backout f8409b3d6449: the PEP 410 is not accepted yet
Victor Stinner <victor.stinner@haypocalc.com>
parents: 74832
diff changeset
95 tp->tv_usec = 0;
76597
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
96 if (info) {
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
97 info->implementation = "time()";
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
98 info->resolution = 1.0;
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
99 info->is_monotonic = 0;
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
100 info->is_adjusted = 1;
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
101 }
63757
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
102 #endif /* !HAVE_FTIME */
74821
bee7943d38c6 Issue #13845: time.time() now uses GetSystemTimeAsFileTime() instead of ftime()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 63757
diff changeset
103
bee7943d38c6 Issue #13845: time.time() now uses GetSystemTimeAsFileTime() instead of ftime()
Victor Stinner <victor.stinner@haypocalc.com>
parents: 63757
diff changeset
104 #endif /* MS_WINDOWS */
63757
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
105 }
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
106
76597
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
107 void
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
108 _PyTime_gettimeofday(_PyTime_timeval *tp)
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
109 {
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
110 pygettimeofday(tp, NULL);
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
111 }
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
112
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
113 void
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
114 _PyTime_gettimeofday_info(_PyTime_timeval *tp, _Py_clock_info_t *info)
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
115 {
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
116 pygettimeofday(tp, info);
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
117 }
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
118
75590
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
119 static void
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
120 error_time_t_overflow(void)
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
121 {
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
122 PyErr_SetString(PyExc_OverflowError,
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
123 "timestamp out of range for platform time_t");
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
124 }
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
125
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
126 static time_t
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
127 _PyLong_AsTime_t(PyObject *obj)
75372
67d9595a833c Issue #13964: signal.sigtimedwait() timeout is now a float instead of a tuple
Victor Stinner <victor.stinner@gmail.com>
parents: 74834
diff changeset
128 {
75590
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
129 #if defined(HAVE_LONG_LONG) && SIZEOF_TIME_T == SIZEOF_LONG_LONG
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
130 PY_LONG_LONG val;
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
131 val = PyLong_AsLongLong(obj);
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
132 #else
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
133 long val;
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
134 assert(sizeof(time_t) <= sizeof(long));
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
135 val = PyLong_AsLong(obj);
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
136 #endif
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
137 if (val == -1 && PyErr_Occurred()) {
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
138 if (PyErr_ExceptionMatches(PyExc_OverflowError))
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
139 error_time_t_overflow();
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
140 return -1;
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
141 }
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
142 return (time_t)val;
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
143 }
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
144
76423
f554043badec Issue #14127: Add st_{cma}time_ns fields to os.stat() result object.
Larry Hastings <larry@hastings.org>
parents: 75595
diff changeset
145 PyObject *
f554043badec Issue #14127: Add st_{cma}time_ns fields to os.stat() result object.
Larry Hastings <larry@hastings.org>
parents: 75595
diff changeset
146 _PyLong_FromTime_t(time_t t)
f554043badec Issue #14127: Add st_{cma}time_ns fields to os.stat() result object.
Larry Hastings <larry@hastings.org>
parents: 75595
diff changeset
147 {
f554043badec Issue #14127: Add st_{cma}time_ns fields to os.stat() result object.
Larry Hastings <larry@hastings.org>
parents: 75595
diff changeset
148 #if defined(HAVE_LONG_LONG) && SIZEOF_TIME_T == SIZEOF_LONG_LONG
f554043badec Issue #14127: Add st_{cma}time_ns fields to os.stat() result object.
Larry Hastings <larry@hastings.org>
parents: 75595
diff changeset
149 return PyLong_FromLongLong((PY_LONG_LONG)t);
f554043badec Issue #14127: Add st_{cma}time_ns fields to os.stat() result object.
Larry Hastings <larry@hastings.org>
parents: 75595
diff changeset
150 #else
f554043badec Issue #14127: Add st_{cma}time_ns fields to os.stat() result object.
Larry Hastings <larry@hastings.org>
parents: 75595
diff changeset
151 assert(sizeof(time_t) <= sizeof(long));
f554043badec Issue #14127: Add st_{cma}time_ns fields to os.stat() result object.
Larry Hastings <larry@hastings.org>
parents: 75595
diff changeset
152 return PyLong_FromLong((long)t);
f554043badec Issue #14127: Add st_{cma}time_ns fields to os.stat() result object.
Larry Hastings <larry@hastings.org>
parents: 75595
diff changeset
153 #endif
f554043badec Issue #14127: Add st_{cma}time_ns fields to os.stat() result object.
Larry Hastings <larry@hastings.org>
parents: 75595
diff changeset
154 }
f554043badec Issue #14127: Add st_{cma}time_ns fields to os.stat() result object.
Larry Hastings <larry@hastings.org>
parents: 75595
diff changeset
155
75590
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
156 static int
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
157 _PyTime_ObjectToDenominator(PyObject *obj, time_t *sec, long *numerator,
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
158 double denominator)
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
159 {
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
160 assert(denominator <= LONG_MAX);
75372
67d9595a833c Issue #13964: signal.sigtimedwait() timeout is now a float instead of a tuple
Victor Stinner <victor.stinner@gmail.com>
parents: 74834
diff changeset
161 if (PyFloat_Check(obj)) {
75595
9d69a2418d80 Issue #14180: Fix an invalid rounding when compiler optimization are enabled
Victor Stinner <vstinner@wyplay.com>
parents: 75591
diff changeset
162 double d, intpart, err;
9d69a2418d80 Issue #14180: Fix an invalid rounding when compiler optimization are enabled
Victor Stinner <vstinner@wyplay.com>
parents: 75591
diff changeset
163 /* volatile avoids unsafe optimization on float enabled by gcc -O3 */
9d69a2418d80 Issue #14180: Fix an invalid rounding when compiler optimization are enabled
Victor Stinner <vstinner@wyplay.com>
parents: 75591
diff changeset
164 volatile double floatpart;
75372
67d9595a833c Issue #13964: signal.sigtimedwait() timeout is now a float instead of a tuple
Victor Stinner <victor.stinner@gmail.com>
parents: 74834
diff changeset
165
67d9595a833c Issue #13964: signal.sigtimedwait() timeout is now a float instead of a tuple
Victor Stinner <victor.stinner@gmail.com>
parents: 74834
diff changeset
166 d = PyFloat_AsDouble(obj);
67d9595a833c Issue #13964: signal.sigtimedwait() timeout is now a float instead of a tuple
Victor Stinner <victor.stinner@gmail.com>
parents: 74834
diff changeset
167 floatpart = modf(d, &intpart);
67d9595a833c Issue #13964: signal.sigtimedwait() timeout is now a float instead of a tuple
Victor Stinner <victor.stinner@gmail.com>
parents: 74834
diff changeset
168 if (floatpart < 0) {
67d9595a833c Issue #13964: signal.sigtimedwait() timeout is now a float instead of a tuple
Victor Stinner <victor.stinner@gmail.com>
parents: 74834
diff changeset
169 floatpart = 1.0 + floatpart;
67d9595a833c Issue #13964: signal.sigtimedwait() timeout is now a float instead of a tuple
Victor Stinner <victor.stinner@gmail.com>
parents: 74834
diff changeset
170 intpart -= 1.0;
67d9595a833c Issue #13964: signal.sigtimedwait() timeout is now a float instead of a tuple
Victor Stinner <victor.stinner@gmail.com>
parents: 74834
diff changeset
171 }
67d9595a833c Issue #13964: signal.sigtimedwait() timeout is now a float instead of a tuple
Victor Stinner <victor.stinner@gmail.com>
parents: 74834
diff changeset
172
67d9595a833c Issue #13964: signal.sigtimedwait() timeout is now a float instead of a tuple
Victor Stinner <victor.stinner@gmail.com>
parents: 74834
diff changeset
173 *sec = (time_t)intpart;
67d9595a833c Issue #13964: signal.sigtimedwait() timeout is now a float instead of a tuple
Victor Stinner <victor.stinner@gmail.com>
parents: 74834
diff changeset
174 err = intpart - (double)*sec;
75590
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
175 if (err <= -1.0 || err >= 1.0) {
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
176 error_time_t_overflow();
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
177 return -1;
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
178 }
75372
67d9595a833c Issue #13964: signal.sigtimedwait() timeout is now a float instead of a tuple
Victor Stinner <victor.stinner@gmail.com>
parents: 74834
diff changeset
179
75590
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
180 floatpart *= denominator;
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
181 *numerator = (long)floatpart;
75372
67d9595a833c Issue #13964: signal.sigtimedwait() timeout is now a float instead of a tuple
Victor Stinner <victor.stinner@gmail.com>
parents: 74834
diff changeset
182 return 0;
67d9595a833c Issue #13964: signal.sigtimedwait() timeout is now a float instead of a tuple
Victor Stinner <victor.stinner@gmail.com>
parents: 74834
diff changeset
183 }
67d9595a833c Issue #13964: signal.sigtimedwait() timeout is now a float instead of a tuple
Victor Stinner <victor.stinner@gmail.com>
parents: 74834
diff changeset
184 else {
75590
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
185 *sec = _PyLong_AsTime_t(obj);
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
186 if (*sec == (time_t)-1 && PyErr_Occurred())
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
187 return -1;
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
188 *numerator = 0;
75372
67d9595a833c Issue #13964: signal.sigtimedwait() timeout is now a float instead of a tuple
Victor Stinner <victor.stinner@gmail.com>
parents: 74834
diff changeset
189 return 0;
67d9595a833c Issue #13964: signal.sigtimedwait() timeout is now a float instead of a tuple
Victor Stinner <victor.stinner@gmail.com>
parents: 74834
diff changeset
190 }
75590
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
191 }
75372
67d9595a833c Issue #13964: signal.sigtimedwait() timeout is now a float instead of a tuple
Victor Stinner <victor.stinner@gmail.com>
parents: 74834
diff changeset
192
75590
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
193 int
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
194 _PyTime_ObjectToTime_t(PyObject *obj, time_t *sec)
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
195 {
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
196 if (PyFloat_Check(obj)) {
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
197 double d, intpart, err;
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
198
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
199 d = PyFloat_AsDouble(obj);
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
200 (void)modf(d, &intpart);
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
201
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
202 *sec = (time_t)intpart;
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
203 err = intpart - (double)*sec;
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
204 if (err <= -1.0 || err >= 1.0) {
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
205 error_time_t_overflow();
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
206 return -1;
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
207 }
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
208 return 0;
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
209 }
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
210 else {
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
211 *sec = _PyLong_AsTime_t(obj);
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
212 if (*sec == (time_t)-1 && PyErr_Occurred())
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
213 return -1;
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
214 return 0;
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
215 }
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
216 }
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
217
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
218 int
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
219 _PyTime_ObjectToTimespec(PyObject *obj, time_t *sec, long *nsec)
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
220 {
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
221 return _PyTime_ObjectToDenominator(obj, sec, nsec, 1e9);
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
222 }
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
223
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
224 int
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
225 _PyTime_ObjectToTimeval(PyObject *obj, time_t *sec, long *usec)
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
226 {
1e9cc1a03365 Close #14180: Factorize code to convert a number of seconds to time_t, timeval or timespec
Victor Stinner <vstinner@wyplay.com>
parents: 75372
diff changeset
227 return _PyTime_ObjectToDenominator(obj, sec, usec, 1e6);
75372
67d9595a833c Issue #13964: signal.sigtimedwait() timeout is now a float instead of a tuple
Victor Stinner <victor.stinner@gmail.com>
parents: 74834
diff changeset
228 }
67d9595a833c Issue #13964: signal.sigtimedwait() timeout is now a float instead of a tuple
Victor Stinner <victor.stinner@gmail.com>
parents: 74834
diff changeset
229
63757
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
230 void
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
231 _PyTime_Init()
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
232 {
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
233 /* Do nothing. Needed to force linking. */
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
234 }