Commit 93037498 authored by Victor Stinner's avatar Victor Stinner

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.
parent 5ac1b936
...@@ -4873,9 +4873,16 @@ datetime_timestamp(PyDateTime_DateTime *self) ...@@ -4873,9 +4873,16 @@ datetime_timestamp(PyDateTime_DateTime *self)
time.tm_wday = -1; time.tm_wday = -1;
time.tm_isdst = -1; time.tm_isdst = -1;
timestamp = mktime(&time); timestamp = mktime(&time);
/* Return value of -1 does not necessarily mean an error, but tm_wday if (timestamp == (time_t)(-1)
* cannot remain set to -1 if mktime succeeded. */ #ifndef _AIX
if (timestamp == (time_t)(-1) && time.tm_wday == -1) { /* 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, PyErr_SetString(PyExc_OverflowError,
"timestamp out of range"); "timestamp out of range");
return NULL; return NULL;
......
...@@ -807,7 +807,16 @@ time_mktime(PyObject *self, PyObject *tup) ...@@ -807,7 +807,16 @@ time_mktime(PyObject *self, PyObject *tup)
tt = mktime(&buf); tt = mktime(&buf);
/* Return value of -1 does not necessarily mean an error, but tm_wday /* Return value of -1 does not necessarily mean an error, but tm_wday
* cannot remain set to -1 if mktime succeeded. */ * 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, PyErr_SetString(PyExc_OverflowError,
"mktime argument out of range"); "mktime argument out of range");
return NULL; return NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment