annotate Include/pytime.h @ 79691:05c8928362ee

Merge __next__ method link fixes with 3.3.
author Ezio Melotti <ezio.melotti@gmail.com>
date Fri, 12 Oct 2012 13:46:37 +0300
parents 0e46e0cd368f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
66664
62b61abd02b8 Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents: 64988
diff changeset
1 #ifndef Py_LIMITED_API
63757
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
2 #ifndef Py_PYTIME_H
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
3 #define Py_PYTIME_H
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
4
74834
90eda29a8e03 Backout f8409b3d6449: the PEP 410 is not accepted yet
Victor Stinner <victor.stinner@haypocalc.com>
parents: 74832
diff changeset
5 #include "pyconfig.h" /* include for defines */
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
6 #include "object.h"
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 /**************************************************************************
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
9 Symbols and macros to supply platform-independent interfaces to time related
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
10 functions and constants
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
11 **************************************************************************/
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
12 #ifdef __cplusplus
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
13 extern "C" {
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
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
16 #ifdef HAVE_GETTIMEOFDAY
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
17 typedef struct timeval _PyTime_timeval;
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
18 #else
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
19 typedef struct {
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
20 time_t tv_sec; /* seconds since Jan. 1, 1970 */
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
21 long tv_usec; /* and microseconds */
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
22 } _PyTime_timeval;
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
23 #endif
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
24
76597
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
25 /* Structure used by time.get_clock_info() */
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
26 typedef struct {
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
27 const char *implementation;
76695
47c84e3f08ae strip is_ prefixes on clock_info fields
Benjamin Peterson <benjamin@python.org>
parents: 76597
diff changeset
28 int monotonic;
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
29 int adjustable;
76597
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
30 double resolution;
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
31 } _Py_clock_info_t;
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
32
63757
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
33 /* Similar to POSIX gettimeofday but cannot fail. If system gettimeofday
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
34 * fails or is not available, fall back to lower resolution clocks.
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
35 */
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
36 PyAPI_FUNC(void) _PyTime_gettimeofday(_PyTime_timeval *tp);
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
37
76597
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
38 /* Similar to _PyTime_gettimeofday() but retrieve also information on the
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
39 * clock used to get the current time. */
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
40 PyAPI_FUNC(void) _PyTime_gettimeofday_info(
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
41 _PyTime_timeval *tp,
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
42 _Py_clock_info_t *info);
76d2e0761d18 Issue #14428, #14397: Implement the PEP 418
Victor Stinner <victor.stinner@gmail.com>
parents: 76423
diff changeset
43
64988
0f8c2eb89f46 Issue #9090: When a socket with a timeout fails with EWOULDBLOCK or EAGAIN,
Antoine Pitrou <solipsis@pitrou.net>
parents: 63951
diff changeset
44 #define _PyTime_ADD_SECONDS(tv, interval) \
0f8c2eb89f46 Issue #9090: When a socket with a timeout fails with EWOULDBLOCK or EAGAIN,
Antoine Pitrou <solipsis@pitrou.net>
parents: 63951
diff changeset
45 do { \
0f8c2eb89f46 Issue #9090: When a socket with a timeout fails with EWOULDBLOCK or EAGAIN,
Antoine Pitrou <solipsis@pitrou.net>
parents: 63951
diff changeset
46 tv.tv_usec += (long) (((long) interval - interval) * 1000000); \
0f8c2eb89f46 Issue #9090: When a socket with a timeout fails with EWOULDBLOCK or EAGAIN,
Antoine Pitrou <solipsis@pitrou.net>
parents: 63951
diff changeset
47 tv.tv_sec += (time_t) interval + (time_t) (tv.tv_usec / 1000000); \
0f8c2eb89f46 Issue #9090: When a socket with a timeout fails with EWOULDBLOCK or EAGAIN,
Antoine Pitrou <solipsis@pitrou.net>
parents: 63951
diff changeset
48 tv.tv_usec %= 1000000; \
0f8c2eb89f46 Issue #9090: When a socket with a timeout fails with EWOULDBLOCK or EAGAIN,
Antoine Pitrou <solipsis@pitrou.net>
parents: 63951
diff changeset
49 } while (0)
0f8c2eb89f46 Issue #9090: When a socket with a timeout fails with EWOULDBLOCK or EAGAIN,
Antoine Pitrou <solipsis@pitrou.net>
parents: 63951
diff changeset
50
0f8c2eb89f46 Issue #9090: When a socket with a timeout fails with EWOULDBLOCK or EAGAIN,
Antoine Pitrou <solipsis@pitrou.net>
parents: 63951
diff changeset
51 #define _PyTime_INTERVAL(tv_start, tv_end) \
0f8c2eb89f46 Issue #9090: When a socket with a timeout fails with EWOULDBLOCK or EAGAIN,
Antoine Pitrou <solipsis@pitrou.net>
parents: 63951
diff changeset
52 ((tv_end.tv_sec - tv_start.tv_sec) + \
0f8c2eb89f46 Issue #9090: When a socket with a timeout fails with EWOULDBLOCK or EAGAIN,
Antoine Pitrou <solipsis@pitrou.net>
parents: 63951
diff changeset
53 (tv_end.tv_usec - tv_start.tv_usec) * 0.000001)
0f8c2eb89f46 Issue #9090: When a socket with a timeout fails with EWOULDBLOCK or EAGAIN,
Antoine Pitrou <solipsis@pitrou.net>
parents: 63951
diff changeset
54
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
55 #ifndef Py_LIMITED_API
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
56 /* Convert a number of seconds, int or float, to 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
57 PyAPI_FUNC(int) _PyTime_ObjectToTime_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
58 PyObject *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
59 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
60
76423
f554043badec Issue #14127: Add st_{cma}time_ns fields to os.stat() result object.
Larry Hastings <larry@hastings.org>
parents: 75590
diff changeset
61 /* Convert a time_t to a PyLong. */
f554043badec Issue #14127: Add st_{cma}time_ns fields to os.stat() result object.
Larry Hastings <larry@hastings.org>
parents: 75590
diff changeset
62 PyAPI_FUNC(PyObject *) _PyLong_FromTime_t(
f554043badec Issue #14127: Add st_{cma}time_ns fields to os.stat() result object.
Larry Hastings <larry@hastings.org>
parents: 75590
diff changeset
63 time_t sec);
f554043badec Issue #14127: Add st_{cma}time_ns fields to os.stat() result object.
Larry Hastings <larry@hastings.org>
parents: 75590
diff changeset
64
76725
bba131e48852 Issue #14127: Add ns= parameter to utime, futimes, and lutimes.
Larry Hastings <larry@hastings.org>
parents: 76695
diff changeset
65 /* Convert a PyLong to a time_t. */
bba131e48852 Issue #14127: Add ns= parameter to utime, futimes, and lutimes.
Larry Hastings <larry@hastings.org>
parents: 76695
diff changeset
66 PyAPI_FUNC(time_t) _PyLong_AsTime_t(
bba131e48852 Issue #14127: Add ns= parameter to utime, futimes, and lutimes.
Larry Hastings <larry@hastings.org>
parents: 76695
diff changeset
67 PyObject *obj);
bba131e48852 Issue #14127: Add ns= parameter to utime, futimes, and lutimes.
Larry Hastings <larry@hastings.org>
parents: 76695
diff changeset
68
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
69 /* Convert a number of seconds, int or float, to a timeval structure.
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
70 usec is in the range [0; 999999] and rounded towards zero.
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
71 For example, -1.2 is converted to (-2, 800000). */
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
72 PyAPI_FUNC(int) _PyTime_ObjectToTimeval(
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
73 PyObject *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
74 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
75 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
76
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
77 /* Convert a number of seconds, int or float, to a timespec structure.
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
78 nsec is in the range [0; 999999999] and rounded towards zero.
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
79 For example, -1.2 is converted to (-2, 800000000). */
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
80 PyAPI_FUNC(int) _PyTime_ObjectToTimespec(
67d9595a833c Issue #13964: signal.sigtimedwait() timeout is now a float instead of a tuple
Victor Stinner <victor.stinner@gmail.com>
parents: 74834
diff changeset
81 PyObject *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
82 time_t *sec,
67d9595a833c Issue #13964: signal.sigtimedwait() timeout is now a float instead of a tuple
Victor Stinner <victor.stinner@gmail.com>
parents: 74834
diff changeset
83 long *nsec);
67d9595a833c Issue #13964: signal.sigtimedwait() timeout is now a float instead of a tuple
Victor Stinner <victor.stinner@gmail.com>
parents: 74834
diff changeset
84 #endif
67d9595a833c Issue #13964: signal.sigtimedwait() timeout is now a float instead of a tuple
Victor Stinner <victor.stinner@gmail.com>
parents: 74834
diff changeset
85
63757
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
86 /* Dummy to force linking. */
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
87 PyAPI_FUNC(void) _PyTime_Init(void);
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
88
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
89 #ifdef __cplusplus
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
90 }
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
91 #endif
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
92
c16803bbd790 Issue #9079: Added _PyTime_gettimeofday(_PyTime_timeval *tp) to C API
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff changeset
93 #endif /* Py_PYTIME_H */
66664
62b61abd02b8 Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents: 64988
diff changeset
94 #endif /* Py_LIMITED_API */