[Python-checkins] python/dist/src/Modules datetimemodule.c, 1.72,
1.73 timemodule.c, 2.141, 2.142
tim_one at users.sourceforge.net
tim_one at users.sourceforge.net
Sat Jun 19 22:50:18 EDT 2004
Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14933/Modules
Modified Files:
datetimemodule.c timemodule.c
Log Message:
Bug 975996: Add _PyTime_DoubleToTimet to C API
New include file timefuncs.h exports private API function
_PyTime_DoubleToTimet() from timemodule.c. timemodule should export
some other functions too (look for painful bits in datetimemodule.c).
Added insane-argument checking to datetime's assorted fromtimestamp()
and utcfromtimestamp() methods. Added insane-argument tests of these
to test_datetime, and insane-argument tests for ctime(), localtime()
and gmtime() to test_time.
Index: datetimemodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/datetimemodule.c,v
retrieving revision 1.72
retrieving revision 1.73
diff -C2 -d -r1.72 -r1.73
*** datetimemodule.c 7 Jun 2004 23:04:33 -0000 1.72
--- datetimemodule.c 20 Jun 2004 02:50:16 -0000 1.73
***************
*** 9,12 ****
--- 9,13 ----
#include <time.h>
+ #include "timefuncs.h"
#include "datetime.h"
***************
*** 2227,2235 ****
/* Return new date from localtime(t). */
static PyObject *
! date_local_from_time_t(PyObject *cls, time_t t)
{
struct tm *tm;
PyObject *result = NULL;
tm = localtime(&t);
if (tm)
--- 2228,2240 ----
/* Return new date from localtime(t). */
static PyObject *
! date_local_from_time_t(PyObject *cls, double ts)
{
struct tm *tm;
+ time_t t;
PyObject *result = NULL;
+ t = _PyTime_DoubleToTimet(ts);
+ if (t == (time_t)-1 && PyErr_Occurred())
+ return NULL;
tm = localtime(&t);
if (tm)
***************
*** 2279,2283 ****
if (PyArg_ParseTuple(args, "d:fromtimestamp", ×tamp))
! result = date_local_from_time_t(cls, (time_t)timestamp);
return result;
}
--- 2284,2288 ----
if (PyArg_ParseTuple(args, "d:fromtimestamp", ×tamp))
! result = date_local_from_time_t(cls, timestamp);
return result;
}
***************
*** 3655,3662 ****
PyObject *tzinfo)
{
! time_t timet = (time_t)timestamp;
! double fraction = timestamp - (double)timet;
! int us = (int)round_to_long(fraction * 1e6);
return datetime_from_timet_and_us(cls, f, timet, us, tzinfo);
}
--- 3660,3672 ----
PyObject *tzinfo)
{
! time_t timet;
! double fraction;
! int us;
+ timet = _PyTime_DoubleToTimet(timestamp);
+ if (timet == (time_t)-1 && PyErr_Occurred())
+ return NULL;
+ fraction = timestamp - (double)timet;
+ us = (int)round_to_long(fraction * 1e6);
return datetime_from_timet_and_us(cls, f, timet, us, tzinfo);
}
Index: timemodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/timemodule.c,v
retrieving revision 2.141
retrieving revision 2.142
diff -C2 -d -r2.141 -r2.142
*** timemodule.c 19 Jun 2004 20:48:43 -0000 2.141
--- timemodule.c 20 Jun 2004 02:50:16 -0000 2.142
***************
*** 4,7 ****
--- 4,8 ----
#include "Python.h"
#include "structseq.h"
+ #include "timefuncs.h"
#include <ctype.h>
***************
*** 85,93 ****
static PyObject *moddict;
! /* Cast double x to time_t, but raise ValueError if x is too large
! * to fit in a time_t. ValueError is set on return iff the return
! * value is (time_t)-1 and PyErr_Occurred().
! */
! static time_t
_PyTime_DoubleToTimet(double x)
{
--- 86,91 ----
static PyObject *moddict;
! /* Exposed in timefuncs.h. */
! time_t
_PyTime_DoubleToTimet(double x)
{
***************
*** 383,387 ****
indexing blindly into some array for a textual representation
by some bad index (fixes bug #897625).
!
No check for year since handled in gettmarg().
*/
--- 381,385 ----
indexing blindly into some array for a textual representation
by some bad index (fixes bug #897625).
!
No check for year since handled in gettmarg().
*/
***************
*** 584,588 ****
inittimezone(m);
Py_DECREF(m);
!
Py_INCREF(Py_None);
return Py_None;
--- 582,586 ----
inittimezone(m);
Py_DECREF(m);
!
Py_INCREF(Py_None);
return Py_None;
More information about the Python-checkins
mailing list