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:
parent
5ac1b936ef
commit
93037498d1
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue