[Python-checkins] python/nondist/sandbox/datetime obj_datetime.c,1.50,1.51 obj_datetimetz.c,1.7,1.8
tim_one@users.sourceforge.net
tim_one@users.sourceforge.net
Fri, 13 Dec 2002 17:14:02 -0800
Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory sc8-pr-cvs1:/tmp/cvs-serv30825
Modified Files:
obj_datetime.c obj_datetimetz.c
Log Message:
Steps toward getting datetimetz.__hash__ working.
Index: obj_datetime.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/obj_datetime.c,v
retrieving revision 1.50
retrieving revision 1.51
diff -C2 -d -r1.50 -r1.51
*** obj_datetime.c 13 Dec 2002 22:19:25 -0000 1.50
--- obj_datetime.c 14 Dec 2002 01:13:59 -0000 1.51
***************
*** 483,490 ****
{
if (self->hashcode == -1) {
! PyObject *temp = datetime_getstate(self);
! if (temp != NULL) {
! self->hashcode = PyObject_Hash(temp);
! Py_DECREF(temp);
}
}
--- 483,525 ----
{
if (self->hashcode == -1) {
! naivety n;
! long offset;
!
! n = classify_object((PyObject *)self, &offset);
! assert(n != OFFSET_UNKNOWN);
! if (n == OFFSET_ERROR)
! return -1;
! if (n == OFFSET_NAIVE) {
! PyObject *temp = datetime_getstate(self);
! if (temp != NULL) {
! self->hashcode = PyObject_Hash(temp);
! Py_DECREF(temp);
! }
! }
! else {
! long minutes;
!
! assert(n == OFFSET_AWARE);
! assert(PyTimeTZ_Check(self));
! /* It doesn't really matter what we do now, except
! * that we have to ensure that datetimetz objects that
! * compare equal have equal hashcodes. So something
! * based on subtracting offset minutes is needed.
! * CAUTION: it's not OK to return right away if
! * offset==0: we need to go thru the whole business
! * below so that, e.g., a datetimetz with hour=5 and
! * offset=-60 gets the same hash code as a datetimetz
! * with hour=6 and offset=0.
! */
! /* XXX This code makes no sense -- repair it. */
! minutes = TIME_GET_HOUR(self) * 60L +
! TIME_GET_MINUTE(self) - offset;
! /* The multipliers below are arbitrary. */
! self->hashcode = minutes * 3601L +
! TIME_GET_SECOND(self) * 61L +
! TIME_GET_MICROSECOND(self);
! if (self->hashcode == -1)
! self->hashcode = -2;
!
}
}
Index: obj_datetimetz.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/obj_datetimetz.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** obj_datetimetz.c 14 Dec 2002 00:49:39 -0000 1.7
--- obj_datetimetz.c 14 Dec 2002 01:14:00 -0000 1.8
***************
*** 444,463 ****
/* Miscellaneous methods. */
! /* Note: tp_richcompare is inherited from datetime. */
!
! static PyObject *datetimetz_getstate(PyDateTime_DateTimeTZ *self);
!
! static long
! datetimetz_hash(PyDateTime_DateTimeTZ *self)
! {
! if (self->hashcode == -1) {
! PyObject *temp = datetimetz_getstate(self);
! if (temp != NULL) {
! self->hashcode = PyObject_Hash(temp);
! Py_DECREF(temp);
! }
! }
! return self->hashcode;
! }
static PyObject *
--- 444,448 ----
/* Miscellaneous methods. */
! /* Note: tp_richcompare and tp_hash are inherited from datetime. */
static PyObject *
***************
*** 660,667 ****
};
- /* Note: we don't inherit datetime_richcompare automatically, because we're
- * overriding datetime's tp_hash. That's why tp_richcompare is filled in
- * here explicitly.
- */
statichere PyTypeObject PyDateTime_DateTimeTZType = {
PyObject_HEAD_INIT(NULL)
--- 645,648 ----
***************
*** 680,684 ****
0, /* tp_as_sequence */
0, /* tp_as_mapping */
! (hashfunc)datetimetz_hash, /* tp_hash */
0, /* tp_call */
(reprfunc)datetimetz_str, /* tp_str */
--- 661,665 ----
0, /* tp_as_sequence */
0, /* tp_as_mapping */
! 0, /* tp_hash */
0, /* tp_call */
(reprfunc)datetimetz_str, /* tp_str */
***************
*** 691,695 ****
0, /* tp_traverse */
0, /* tp_clear */
! (richcmpfunc)datetime_richcompare, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
--- 672,676 ----
0, /* tp_traverse */
0, /* tp_clear */
! 0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */