Mercurial > cpython-lru_cache-weakref
annotate Modules/_time.c @ 71285:8bc9dbc61ba6 3.2
Issue #12326: document the recommended idiom for checking sys.platform on Unix systems.
Also, point to the various alternatives.
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Sat, 09 Jul 2011 15:54:23 +0200 |
| parents | e5f5008fd56d |
| children |
| rev | line source |
|---|---|
|
62364
6d3b05a429b5
Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
1 #include "Python.h" |
|
6d3b05a429b5
Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
2 #include "_time.h" |
|
6d3b05a429b5
Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
3 |
|
6d3b05a429b5
Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
4 /* Exposed in timefuncs.h. */ |
|
6d3b05a429b5
Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
5 time_t |
|
6d3b05a429b5
Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
6 _PyTime_DoubleToTimet(double x) |
|
6d3b05a429b5
Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
7 { |
|
6d3b05a429b5
Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
8 time_t result; |
|
6d3b05a429b5
Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
9 double diff; |
|
6d3b05a429b5
Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
10 |
|
6d3b05a429b5
Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
11 result = (time_t)x; |
|
6d3b05a429b5
Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
12 /* How much info did we lose? time_t may be an integral or |
|
6d3b05a429b5
Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
13 * floating type, and we don't know which. If it's integral, |
|
6d3b05a429b5
Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
14 * we don't know whether C truncates, rounds, returns the floor, |
|
6d3b05a429b5
Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
15 * etc. If we lost a second or more, the C rounding is |
|
6d3b05a429b5
Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
16 * unreasonable, or the input just doesn't fit in a time_t; |
|
6d3b05a429b5
Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
17 * call it an error regardless. Note that the original cast to |
|
6d3b05a429b5
Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
18 * time_t can cause a C error too, but nothing we can do to |
|
62396
e5f5008fd56d
Fixed a typo in a comment.
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
62364
diff
changeset
|
19 * work around that. |
|
62364
6d3b05a429b5
Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
20 */ |
|
6d3b05a429b5
Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
21 diff = x - (double)result; |
|
6d3b05a429b5
Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
22 if (diff <= -1.0 || diff >= 1.0) { |
|
6d3b05a429b5
Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
23 PyErr_SetString(PyExc_ValueError, |
|
6d3b05a429b5
Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
24 "timestamp out of range for platform time_t"); |
|
6d3b05a429b5
Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
25 result = (time_t)-1; |
|
6d3b05a429b5
Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
26 } |
|
6d3b05a429b5
Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
27 return result; |
|
6d3b05a429b5
Issue #9012: "Separate compilation of time and datetime modules."
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
diff
changeset
|
28 } |
