Mercurial > cpython-lru_cache-weakref
annotate Python/pytime.c @ 87690:66c1c9f32567 default tip
Add use_weakref option to functools.lru_cache
The use_weakref option makes lru_cache create weak references to the function
arguments when creating the cache key, which prevents them from staying in the
memory forever even after all other references to them are gone.
This is a proof of concept for http://bugs.python.org/issue19859
| author | Radomir Dopieralski <devel@sheep.art.pl> |
|---|---|
| date | Tue, 03 Dec 2013 16:02:48 +0100 |
| parents | 0e46e0cd368f |
| children |
| 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()"; |
|
76695
47c84e3f08ae
strip is_ prefixes on clock_info fields
Benjamin Peterson <benjamin@python.org>
parents:
76597
diff
changeset
|
43 info->monotonic = 0; |
|
76597
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; |
|
77415
0e46e0cd368f
PEP 418: Rename adjusted attribute to adjustable in time.get_clock_info() result
Victor Stinner <victor.stinner@gmail.com>
parents:
76725
diff
changeset
|
47 info->adjustable = 1; |
|
76597
76d2e0761d18
Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents:
76423
diff
changeset
|
48 } |
|
74821
bee7943d38c6
Issue #13845: time.time() now uses GetSystemTimeAsFileTime() instead of ftime()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
63757
diff
changeset
|
49 #else |
|
63757
c16803bbd790
Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
50 /* 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
|
51 (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
|
52 (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
|
53 (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
|
54 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
|
55 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
|
56 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
|
57 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
|
58 |
|
63757
c16803bbd790
Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
59 #ifdef HAVE_GETTIMEOFDAY |
|
76597
76d2e0761d18
Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents:
76423
diff
changeset
|
60 int err; |
|
63757
c16803bbd790
Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
61 #ifdef GETTIMEOFDAY_NO_TZ |
|
76597
76d2e0761d18
Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents:
76423
diff
changeset
|
62 err = gettimeofday(tp); |
|
76d2e0761d18
Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents:
76423
diff
changeset
|
63 #else |
|
76d2e0761d18
Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents:
76423
diff
changeset
|
64 err = gettimeofday(tp, (struct timezone *)NULL); |
|
76d2e0761d18
Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents:
76423
diff
changeset
|
65 #endif |
|
76d2e0761d18
Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents:
76423
diff
changeset
|
66 if (err == 0) { |
|
76d2e0761d18
Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents:
76423
diff
changeset
|
67 if (info) { |
|
76d2e0761d18
Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents:
76423
diff
changeset
|
68 info->implementation = "gettimeofday()"; |
|
76d2e0761d18
Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents:
76423
diff
changeset
|
69 info->resolution = 1e-6; |
|
76695
47c84e3f08ae
strip is_ prefixes on clock_info fields
Benjamin Peterson <benjamin@python.org>
parents:
76597
diff
changeset
|
70 info->monotonic = 0; |
|
77415
0e46e0cd368f
PEP 418: Rename adjusted attribute to adjustable in time.get_clock_info() result
Victor Stinner <victor.stinner@gmail.com>
parents:
76725
diff
changeset
|
71 info->adjustable = 1; |
|
76597
76d2e0761d18
Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents:
76423
diff
changeset
|
72 } |
|
74834
90eda29a8e03
Backout f8409b3d6449: the PEP 410 is not accepted yet
Victor Stinner <victor.stinner@haypocalc.com>
parents:
74832
diff
changeset
|
73 return; |
|
76597
76d2e0761d18
Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents:
76423
diff
changeset
|
74 } |
|
76d2e0761d18
Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents:
76423
diff
changeset
|
75 #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
|
76 |
|
63757
c16803bbd790
Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
77 #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
|
78 { |
|
90eda29a8e03
Backout f8409b3d6449: the PEP 410 is not accepted yet
Victor Stinner <victor.stinner@haypocalc.com>
parents:
74832
diff
changeset
|
79 struct timeb t; |
|
90eda29a8e03
Backout f8409b3d6449: the PEP 410 is not accepted yet
Victor Stinner <victor.stinner@haypocalc.com>
parents:
74832
diff
changeset
|
80 ftime(&t); |
|
90eda29a8e03
Backout f8409b3d6449: the PEP 410 is not accepted yet
Victor Stinner <victor.stinner@haypocalc.com>
parents:
74832
diff
changeset
|
81 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
|
82 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
|
83 if (info) { |
|
76d2e0761d18
Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents:
76423
diff
changeset
|
84 info->implementation = "ftime()"; |
|
76d2e0761d18
Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents:
76423
diff
changeset
|
85 info->resolution = 1e-3; |
|
76695
47c84e3f08ae
strip is_ prefixes on clock_info fields
Benjamin Peterson <benjamin@python.org>
parents:
76597
diff
changeset
|
86 info->monotonic = 0; |
|
77415
0e46e0cd368f
PEP 418: Rename adjusted attribute to adjustable in time.get_clock_info() result
Victor Stinner <victor.stinner@gmail.com>
parents:
76725
diff
changeset
|
87 info->adjustable = 1; |
|
76597
76d2e0761d18
Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents:
76423
diff
changeset
|
88 } |
|
74834
90eda29a8e03
Backout f8409b3d6449: the PEP 410 is not accepted yet
Victor Stinner <victor.stinner@haypocalc.com>
parents:
74832
diff
changeset
|
89 } |
|
63757
c16803bbd790
Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
90 #else /* !HAVE_FTIME */ |
|
74834
90eda29a8e03
Backout f8409b3d6449: the PEP 410 is not accepted yet
Victor Stinner <victor.stinner@haypocalc.com>
parents:
74832
diff
changeset
|
91 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
|
92 tp->tv_usec = 0; |
|
76597
76d2e0761d18
Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents:
76423
diff
changeset
|
93 if (info) { |
|
76d2e0761d18
Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents:
76423
diff
changeset
|
94 info->implementation = "time()"; |
|
76d2e0761d18
Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents:
76423
diff
changeset
|
95 info->resolution = 1.0; |
|
76695
47c84e3f08ae
strip is_ prefixes on clock_info fields
Benjamin Peterson <benjamin@python.org>
parents:
76597
diff
changeset
|
96 info->monotonic = 0; |
|
77415
0e46e0cd368f
PEP 418: Rename adjusted attribute to adjustable in time.get_clock_info() result
Victor Stinner <victor.stinner@gmail.com>
parents:
76725
diff
changeset
|
97 info->adjustable = 1; |
|
76597
76d2e0761d18
Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents:
76423
diff
changeset
|
98 } |
|
63757
c16803bbd790
Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
99 #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
|
100 |
|
bee7943d38c6
Issue #13845: time.time() now uses GetSystemTimeAsFileTime() instead of ftime()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
63757
diff
changeset
|
101 #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
|
102 } |
|
c16803bbd790
Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
103 |
|
76597
76d2e0761d18
Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents:
76423
diff
changeset
|
104 void |
|
76d2e0761d18
Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents:
76423
diff
changeset
|
105 _PyTime_gettimeofday(_PyTime_timeval *tp) |
|
76d2e0761d18
Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents:
76423
diff
changeset
|
106 { |
|
76d2e0761d18
Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents:
76423
diff
changeset
|
107 pygettimeofday(tp, NULL); |
|
76d2e0761d18
Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents:
76423
diff
changeset
|
108 } |
|
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 void |
|
76d2e0761d18
Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents:
76423
diff
changeset
|
111 _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
|
112 { |
|
76d2e0761d18
Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents:
76423
diff
changeset
|
113 pygettimeofday(tp, info); |
|
76d2e0761d18
Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents:
76423
diff
changeset
|
114 } |
|
76d2e0761d18
Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents:
76423
diff
changeset
|
115 |
|
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
|
116 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
|
117 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
|
118 { |
|
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 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
|
120 "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
|
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 |
|
76725
bba131e48852
Issue #14127: Add ns= parameter to utime, futimes, and lutimes.
Larry Hastings <larry@hastings.org>
parents:
76695
diff
changeset
|
123 time_t |
|
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
|
124 _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
|
125 { |
|
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
|
126 #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
|
127 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
|
128 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
|
129 #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
|
130 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 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
|
132 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
|
133 #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
|
134 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
|
135 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
|
136 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
|
137 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
|
138 } |
|
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 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
|
140 } |
|
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 |
|
76423
f554043badec
Issue #14127: Add st_{cma}time_ns fields to os.stat() result object.
Larry Hastings <larry@hastings.org>
parents:
75595
diff
changeset
|
142 PyObject * |
|
f554043badec
Issue #14127: Add st_{cma}time_ns fields to os.stat() result object.
Larry Hastings <larry@hastings.org>
parents:
75595
diff
changeset
|
143 _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
|
144 { |
|
f554043badec
Issue #14127: Add st_{cma}time_ns fields to os.stat() result object.
Larry Hastings <larry@hastings.org>
parents:
75595
diff
changeset
|
145 #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
|
146 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
|
147 #else |
|
f554043badec
Issue #14127: Add st_{cma}time_ns fields to os.stat() result object.
Larry Hastings <larry@hastings.org>
parents:
75595
diff
changeset
|
148 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
|
149 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
|
150 #endif |
|
f554043badec
Issue #14127: Add st_{cma}time_ns fields to os.stat() result object.
Larry Hastings <larry@hastings.org>
parents:
75595
diff
changeset
|
151 } |
|
f554043badec
Issue #14127: Add st_{cma}time_ns fields to os.stat() result object.
Larry Hastings <larry@hastings.org>
parents:
75595
diff
changeset
|
152 |
|
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
|
153 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
|
154 _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
|
155 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
|
156 { |
|
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 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
|
158 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
|
159 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
|
160 /* 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
|
161 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
|
162 |
|
67d9595a833c
Issue #13964: signal.sigtimedwait() timeout is now a float instead of a tuple
Victor Stinner <victor.stinner@gmail.com>
parents:
74834
diff
changeset
|
163 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
|
164 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
|
165 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
|
166 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
|
167 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
|
168 } |
|
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 |
|
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 *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
|
171 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
|
172 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
|
173 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
|
174 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
|
175 } |
|
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
|
176 |
|
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
|
177 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
|
178 *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
|
179 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
|
180 } |
|
67d9595a833c
Issue #13964: signal.sigtimedwait() timeout is now a float instead of a tuple
Victor Stinner <victor.stinner@gmail.com>
parents:
74834
diff
changeset
|
181 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
|
182 *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
|
183 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
|
184 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
|
185 *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
|
186 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
|
187 } |
|
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
|
188 } |
|
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 |
|
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
|
190 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
|
191 _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
|
192 { |
|
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 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
|
194 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
|
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 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
|
197 (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
|
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 *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
|
200 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
|
201 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
|
202 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
|
203 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
|
204 } |
|
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 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
|
206 } |
|
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 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
|
208 *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
|
209 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
|
210 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
|
211 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
|
212 } |
|
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 } |
|
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 |
|
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 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
|
216 _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
|
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 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
|
219 } |
|
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 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
|
222 _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
|
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 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
|
225 } |
|
67d9595a833c
Issue #13964: signal.sigtimedwait() timeout is now a float instead of a tuple
Victor Stinner <victor.stinner@gmail.com>
parents:
74834
diff
changeset
|
226 |
|
63757
c16803bbd790
Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
227 void |
|
c16803bbd790
Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
228 _PyTime_Init() |
|
c16803bbd790
Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
229 { |
|
c16803bbd790
Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
230 /* 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
|
231 } |
