7575#define SET_TD_SECONDS (o , v ) ((o)->seconds = (v))
7676#define SET_TD_MICROSECONDS (o , v ) ((o)->microseconds = (v))
7777
78+ /* p is a pointer to a time or a datetime object; HASTZINFO(p) returns
79+ * p->hastzinfo.
80+ */
81+ #define HASTZINFO (p ) (((_PyDateTime_BaseTZInfo *)(p))->hastzinfo)
82+
7883/* Forward declarations. */
7984static PyTypeObject PyDateTime_DateType ;
8085static PyTypeObject PyDateTime_DateTimeType ;
@@ -606,7 +611,7 @@ get_tzinfo_member(PyObject *self)
606611
607612 if (PyDateTimeTZ_Check (self ))
608613 tzinfo = ((PyDateTime_DateTimeTZ * )self )-> tzinfo ;
609- else if (PyTime_Check (self ) && (( PyDateTime_Time * ) self )-> hastzinfo )
614+ else if (PyTime_Check (self ) && HASTZINFO ( self ))
610615 tzinfo = ((PyDateTime_Time * )self )-> tzinfo ;
611616
612617 return tzinfo ;
@@ -2966,9 +2971,7 @@ datetime_combine(PyObject *cls, PyObject *args, PyObject *kw)
29662971 TIME_GET_MINUTE (time ),
29672972 TIME_GET_SECOND (time ),
29682973 TIME_GET_MICROSECOND (time ));
2969- if (result &&
2970- ((PyDateTime_Time * )time )-> hastzinfo &&
2971- PyDateTimeTZ_Check (result )) {
2974+ if (result && HASTZINFO (time ) && PyDateTimeTZ_Check (result )) {
29722975 /* Copy the tzinfo field. */
29732976 replace_tzinfo (result , ((PyDateTime_Time * )time )-> tzinfo );
29742977 }
@@ -3618,7 +3621,7 @@ time_microsecond(PyDateTime_Time *self, void *unused)
36183621static PyObject *
36193622time_tzinfo (PyDateTime_Time * self , void * unused )
36203623{
3621- PyObject * result = self -> hastzinfo ? self -> tzinfo : Py_None ;
3624+ PyObject * result = HASTZINFO ( self ) ? self -> tzinfo : Py_None ;
36223625 Py_INCREF (result );
36233626 return result ;
36243627}
@@ -3668,7 +3671,7 @@ time_new(PyTypeObject *type, PyObject *args, PyObject *kw)
36683671static void
36693672time_dealloc (PyDateTime_Time * self )
36703673{
3671- if (self -> hastzinfo ) {
3674+ if (HASTZINFO ( self ) ) {
36723675 Py_XDECREF (self -> tzinfo );
36733676 }
36743677 self -> ob_type -> tp_free ((PyObject * )self );
@@ -3681,19 +3684,19 @@ time_dealloc(PyDateTime_Time *self)
36813684/* These are all METH_NOARGS, so don't need to check the arglist. */
36823685static PyObject *
36833686time_utcoffset (PyDateTime_Time * self , PyObject * unused ) {
3684- return offset_as_timedelta (self -> hastzinfo ? self -> tzinfo : Py_None ,
3687+ return offset_as_timedelta (HASTZINFO ( self ) ? self -> tzinfo : Py_None ,
36853688 "utcoffset" , Py_None );
36863689}
36873690
36883691static PyObject *
36893692time_dst (PyDateTime_Time * self , PyObject * unused ) {
3690- return offset_as_timedelta (self -> hastzinfo ? self -> tzinfo : Py_None ,
3693+ return offset_as_timedelta (HASTZINFO ( self ) ? self -> tzinfo : Py_None ,
36913694 "dst" , Py_None );
36923695}
36933696
36943697static PyObject *
36953698time_tzname (PyDateTime_Time * self , PyObject * unused ) {
3696- return call_tzname (self -> hastzinfo ? self -> tzinfo : Py_None ,
3699+ return call_tzname (HASTZINFO ( self ) ? self -> tzinfo : Py_None ,
36973700 Py_None );
36983701}
36993702
@@ -3722,7 +3725,7 @@ time_repr(PyDateTime_Time *self)
37223725 PyOS_snprintf (buffer , sizeof (buffer ),
37233726 "%s(%d, %d)" , typename , h , m );
37243727 result = PyString_FromString (buffer );
3725- if (result != NULL && self -> hastzinfo )
3728+ if (result != NULL && HASTZINFO ( self ) )
37263729 result = append_keyword_tzinfo (result , self -> tzinfo );
37273730 return result ;
37283731}
@@ -3749,7 +3752,7 @@ time_isoformat(PyDateTime_Time *self)
37493752
37503753 isoformat_time (pdatetime , buf , sizeof (buf ));
37513754 result = PyString_FromString (buf );
3752- if (result == NULL || ! self -> hastzinfo || self -> tzinfo == Py_None )
3755+ if (result == NULL || ! HASTZINFO ( self ) || self -> tzinfo == Py_None )
37533756 return result ;
37543757
37553758 /* We need to append the UTC offset. */
@@ -3876,7 +3879,7 @@ time_hash(PyDateTime_Time *self)
38763879 int minute ;
38773880
38783881 assert (n == OFFSET_AWARE );
3879- assert (self -> hastzinfo );
3882+ assert (HASTZINFO ( self ) );
38803883 hour = divmod (TIME_GET_HOUR (self ) * 60 +
38813884 TIME_GET_MINUTE (self ) - offset ,
38823885 60 ,
@@ -3909,7 +3912,7 @@ time_replace(PyDateTime_Time *self, PyObject *args, PyObject *kw)
39093912 int mm = TIME_GET_MINUTE (self );
39103913 int ss = TIME_GET_SECOND (self );
39113914 int us = TIME_GET_MICROSECOND (self );
3912- PyObject * tzinfo = self -> hastzinfo ? self -> tzinfo : Py_None ;
3915+ PyObject * tzinfo = HASTZINFO ( self ) ? self -> tzinfo : Py_None ;
39133916
39143917 if (! PyArg_ParseTupleAndKeywords (args , kw , "|iiiiO:replace" ,
39153918 time_kws ,
@@ -3936,7 +3939,7 @@ time_nonzero(PyDateTime_Time *self)
39363939 return 1 ;
39373940 }
39383941 offset = 0 ;
3939- if (self -> hastzinfo && self -> tzinfo != Py_None ) {
3942+ if (HASTZINFO ( self ) && self -> tzinfo != Py_None ) {
39403943 offset = call_utcoffset (self -> tzinfo , Py_None , & none );
39413944 if (offset == -1 && PyErr_Occurred ())
39423945 return -1 ;
@@ -3961,7 +3964,7 @@ time_getstate(PyDateTime_Time *self)
39613964 basestate = PyString_FromStringAndSize ((char * )self -> data ,
39623965 _PyDateTime_TIME_DATASIZE );
39633966 if (basestate != NULL ) {
3964- if (! self -> hastzinfo || self -> tzinfo == Py_None )
3967+ if (! HASTZINFO ( self ) || self -> tzinfo == Py_None )
39653968 result = Py_BuildValue ("(O)" , basestate );
39663969 else
39673970 result = Py_BuildValue ("OO" , basestate , self -> tzinfo );
@@ -3986,7 +3989,7 @@ time_setstate(PyDateTime_Time *self, PyObject *state)
39863989 "bad argument to time.__setstate__" );
39873990 return NULL ;
39883991 }
3989- if (tzinfo != Py_None && ! self -> hastzinfo ) {
3992+ if (tzinfo != Py_None && ! HASTZINFO ( self ) ) {
39903993 PyErr_SetString (PyExc_ValueError , "time.__setstate__ can't "
39913994 "add a non-None tzinfo to a time object that "
39923995 "doesn't have one already" );
@@ -3996,7 +3999,7 @@ time_setstate(PyDateTime_Time *self, PyObject *state)
39963999 PyString_AsString (basestate ),
39974000 _PyDateTime_TIME_DATASIZE );
39984001 self -> hashcode = -1 ;
3999- if (self -> hastzinfo ) {
4002+ if (HASTZINFO ( self ) ) {
40004003 Py_INCREF (tzinfo );
40014004 Py_XDECREF (self -> tzinfo );
40024005 self -> tzinfo = tzinfo ;
0 commit comments