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.
This commit is contained in:
Victor Stinner 2013-06-25 22:54:35 +02:00
parent 5ac1b936ef
commit 93037498d1
2 changed files with 20 additions and 4 deletions

View File

@ -4873,9 +4873,16 @@ datetime_timestamp(PyDateTime_DateTime *self)
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;

View File

@ -807,7 +807,16 @@ time_mktime(PyObject *self, PyObject *tup)
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;