Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d95a586

Browse files
committed
Issue #9012: "Separate compilation of time and datetime modules."
Segregated code shared between time and datetime modules into Modules/_time.c. Added a new header file, Modules/_time.h, which will be used instead of Include/timefuncs.h for declarations shared between time and datetime modules.
1 parent 294f271 commit d95a586

4 files changed

Lines changed: 33 additions & 28 deletions

File tree

Modules/_time.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include "Python.h"
2+
#include "_time.h"
3+
4+
/* Exposed in timefuncs.h. */
5+
time_t
6+
_PyTime_DoubleToTimet(double x)
7+
{
8+
time_t result;
9+
double diff;
10+
11+
result = (time_t)x;
12+
/* How much info did we lose? time_t may be an integral or
13+
* floating type, and we don't know which. If it's integral,
14+
* we don't know whether C truncates, rounds, returns the floor,
15+
* etc. If we lost a second or more, the C rounding is
16+
* unreasonable, or the input just doesn't fit in a time_t;
17+
* call it an error regardless. Note that the original cast to
18+
* time_t can cause a C error too, but nothing we can do to
19+
* worm around that.
20+
*/
21+
diff = x - (double)result;
22+
if (diff <= -1.0 || diff >= 1.0) {
23+
PyErr_SetString(PyExc_ValueError,
24+
"timestamp out of range for platform time_t");
25+
result = (time_t)-1;
26+
}
27+
return result;
28+
}

Modules/_time.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/* XXX: It is probably best to move timefuncs.h content in here, and
2+
remove it but user code may rely on it. */
3+
#include "timefuncs.h"

Modules/timemodule.c

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -90,32 +90,6 @@ static double floattime(void);
9090
/* For Y2K check */
9191
static PyObject *moddict;
9292

93-
/* Exposed in timefuncs.h. */
94-
time_t
95-
_PyTime_DoubleToTimet(double x)
96-
{
97-
time_t result;
98-
double diff;
99-
100-
result = (time_t)x;
101-
/* How much info did we lose? time_t may be an integral or
102-
* floating type, and we don't know which. If it's integral,
103-
* we don't know whether C truncates, rounds, returns the floor,
104-
* etc. If we lost a second or more, the C rounding is
105-
* unreasonable, or the input just doesn't fit in a time_t;
106-
* call it an error regardless. Note that the original cast to
107-
* time_t can cause a C error too, but nothing we can do to
108-
* worm around that.
109-
*/
110-
diff = x - (double)result;
111-
if (diff <= -1.0 || diff >= 1.0) {
112-
PyErr_SetString(PyExc_ValueError,
113-
"timestamp out of range for platform time_t");
114-
result = (time_t)-1;
115-
}
116-
return result;
117-
}
118-
11993
static PyObject *
12094
time_time(PyObject *self, PyObject *unused)
12195
{

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,9 +450,9 @@ def detect_modules(self):
450450
depends=['_math.h'],
451451
libraries=math_libs) )
452452
# time operations and variables
453-
exts.append( Extension('time', ['timemodule.c'],
453+
exts.append( Extension('time', ['timemodule.c', '_time.c'],
454454
libraries=math_libs) )
455-
exts.append( Extension('datetime', ['datetimemodule.c', 'timemodule.c'],
455+
exts.append( Extension('datetime', ['datetimemodule.c', '_time.c'],
456456
libraries=math_libs) )
457457
# fast iterator tools implemented in C
458458
exts.append( Extension("itertools", ["itertoolsmodule.c"]) )

0 commit comments

Comments
 (0)