[Python-checkins] cpython: Fix time.mktime() and datetime.datetime.timestamp() on AIX
victor.stinner
python-checkins at python.org
Tue Jun 25 22:56:21 CEST 2013
http://hg.python.org/cpython/rev/035d8fed07ad
changeset: 84347:035d8fed07ad
user: Victor Stinner <victor.stinner at gmail.com>
date: Tue Jun 25 22:54:35 2013 +0200
summary:
Fix time.mktime() and datetime.datetime.timestamp() on AIX
On AIX, the C function mktime() alwaysd sets tm_wday, even on error. So tm_wday
cannot be used as a sentinel to detect an error, we can only check if the
result is (time_t)-1.
files:
Modules/_datetimemodule.c | 13 ++++++++++---
Modules/timemodule.c | 11 ++++++++++-
2 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -4873,9 +4873,16 @@
time.tm_wday = -1;
time.tm_isdst = -1;
timestamp = mktime(&time);
- /* Return value of -1 does not necessarily mean an error, but tm_wday
- * cannot remain set to -1 if mktime succeeded. */
- if (timestamp == (time_t)(-1) && time.tm_wday == -1) {
+ if (timestamp == (time_t)(-1)
+#ifndef _AIX
+ /* Return value of -1 does not necessarily mean an error,
+ * but tm_wday cannot remain set to -1 if mktime succeeded. */
+ && time.tm_wday == -1
+#else
+ /* on AIX, tm_wday is always sets, even on error */
+#endif
+ )
+ {
PyErr_SetString(PyExc_OverflowError,
"timestamp out of range");
return NULL;
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -807,7 +807,16 @@
tt = mktime(&buf);
/* Return value of -1 does not necessarily mean an error, but tm_wday
* cannot remain set to -1 if mktime succeeded. */
- if (tt == (time_t)(-1) && buf.tm_wday == -1) {
+ if (tt == (time_t)(-1)
+#ifndef _AIX
+ /* Return value of -1 does not necessarily mean an error, but
+ * tm_wday cannot remain set to -1 if mktime succeeded. */
+ && buf.tm_wday == -1
+#else
+ /* on AIX, tm_wday is always sets, even on error */
+#endif
+ )
+ {
PyErr_SetString(PyExc_OverflowError,
"mktime argument out of range");
return NULL;
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list