mirror of
https://github.com/python/cpython.git
synced 2025-11-13 23:46:24 +00:00
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
2 changed files with 20 additions and 4 deletions
|
|
@ -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)
|
||||||
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;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue