]> granicus.if.org Git - python/commitdiff
Issue #9012: "Separate compilation of time and datetime modules."
authorAlexander Belopolsky <alexander.belopolsky@gmail.com>
Wed, 16 Jun 2010 22:38:15 +0000 (22:38 +0000)
committerAlexander Belopolsky <alexander.belopolsky@gmail.com>
Wed, 16 Jun 2010 22:38:15 +0000 (22:38 +0000)
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.

Modules/_time.c [new file with mode: 0644]
Modules/_time.h [new file with mode: 0644]
Modules/timemodule.c
setup.py

diff --git a/Modules/_time.c b/Modules/_time.c
new file mode 100644 (file)
index 0000000..9b63c20
--- /dev/null
@@ -0,0 +1,28 @@
+#include "Python.h"
+#include "_time.h"
+
+/* Exposed in timefuncs.h. */
+time_t
+_PyTime_DoubleToTimet(double x)
+{
+    time_t result;
+    double diff;
+
+    result = (time_t)x;
+    /* How much info did we lose?  time_t may be an integral or
+     * floating type, and we don't know which.  If it's integral,
+     * we don't know whether C truncates, rounds, returns the floor,
+     * etc.  If we lost a second or more, the C rounding is
+     * unreasonable, or the input just doesn't fit in a time_t;
+     * call it an error regardless.  Note that the original cast to
+     * time_t can cause a C error too, but nothing we can do to
+     * worm around that.
+     */
+    diff = x - (double)result;
+    if (diff <= -1.0 || diff >= 1.0) {
+        PyErr_SetString(PyExc_ValueError,
+                        "timestamp out of range for platform time_t");
+        result = (time_t)-1;
+    }
+    return result;
+}
diff --git a/Modules/_time.h b/Modules/_time.h
new file mode 100644 (file)
index 0000000..816593b
--- /dev/null
@@ -0,0 +1,3 @@
+/* XXX: It is probably best to move timefuncs.h content in here, and
+   remove it but user code may rely on it. */
+#include "timefuncs.h"
index 18fe13f2ef8208bd14af408bd8489c321459d4dd..c4b50144bded863ba0b2785ec7f8e78b54ed18d2 100644 (file)
@@ -90,32 +90,6 @@ static double floattime(void);
 /* For Y2K check */
 static PyObject *moddict;
 
-/* Exposed in timefuncs.h. */
-time_t
-_PyTime_DoubleToTimet(double x)
-{
-    time_t result;
-    double diff;
-
-    result = (time_t)x;
-    /* How much info did we lose?  time_t may be an integral or
-     * floating type, and we don't know which.  If it's integral,
-     * we don't know whether C truncates, rounds, returns the floor,
-     * etc.  If we lost a second or more, the C rounding is
-     * unreasonable, or the input just doesn't fit in a time_t;
-     * call it an error regardless.  Note that the original cast to
-     * time_t can cause a C error too, but nothing we can do to
-     * worm around that.
-     */
-    diff = x - (double)result;
-    if (diff <= -1.0 || diff >= 1.0) {
-        PyErr_SetString(PyExc_ValueError,
-                        "timestamp out of range for platform time_t");
-        result = (time_t)-1;
-    }
-    return result;
-}
-
 static PyObject *
 time_time(PyObject *self, PyObject *unused)
 {
index 18e1cd6034792f465edc4c2a177db2b74c745ea0..ab7909e1306d634e0559a175cf1187c907fb2878 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -450,9 +450,9 @@ class PyBuildExt(build_ext):
                                depends=['_math.h'],
                                libraries=math_libs) )
         # time operations and variables
-        exts.append( Extension('time', ['timemodule.c'],
+        exts.append( Extension('time', ['timemodule.c', '_time.c'],
                                libraries=math_libs) )
-        exts.append( Extension('datetime', ['datetimemodule.c', 'timemodule.c'],
+        exts.append( Extension('datetime', ['datetimemodule.c', '_time.c'],
                                libraries=math_libs) )
         # fast iterator tools implemented in C
         exts.append( Extension("itertools", ["itertoolsmodule.c"]) )