[Python-checkins] python/dist/src/Modules datetimemodule.c,1.19,1.20

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
Mon, 30 Dec 2002 13:28:57 -0800


Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv16652/python/Modules

Modified Files:
	datetimemodule.c 
Log Message:
Bite the bullet on all the indirect timetz and datetimetz tzinfo methods:
make the callers figure out the right tzinfo arguments to pass, instead of
making the callees guess.  The code is uglier this way, but it's less
brittle (when the callee guesses, the caller can get surprised).


Index: datetimemodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/datetimemodule.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -d -r1.19 -r1.20
*** datetimemodule.c	30 Dec 2002 20:52:32 -0000	1.19
--- datetimemodule.c	30 Dec 2002 21:28:52 -0000	1.20
***************
*** 804,814 ****
   * to minutes east of UTC (as returned by the tzinfo.utcoffset() method).
   * If the type is offset-naive (or unknown, or error), *offset is set to 0.
   */
  static naivety
! classify_utcoffset(PyObject *op, int *offset)
  {
  	int none;
  	PyObject *tzinfo;
  
  	*offset = 0;
  	tzinfo = get_tzinfo_member(op);	/* NULL means no tzinfo, not error */
--- 804,816 ----
   * to minutes east of UTC (as returned by the tzinfo.utcoffset() method).
   * If the type is offset-naive (or unknown, or error), *offset is set to 0.
+  * tzinfoarg is the argument to pass to the tzinfo.utcoffset() method.
   */
  static naivety
! classify_utcoffset(PyObject *op, PyObject *tzinfoarg, int *offset)
  {
  	int none;
  	PyObject *tzinfo;
  
+ 	assert(tzinfoarg != NULL);
  	*offset = 0;
  	tzinfo = get_tzinfo_member(op);	/* NULL means no tzinfo, not error */
***************
*** 820,826 ****
  		       OFFSET_NAIVE : OFFSET_UNKNOWN;
  	}
! 	*offset = call_utcoffset(tzinfo,
! 				 PyTimeTZ_Check(op) ? Py_None : op,
! 				 &none);
  	if (*offset == -1 && PyErr_Occurred())
  		return OFFSET_ERROR;
--- 822,826 ----
  		       OFFSET_NAIVE : OFFSET_UNKNOWN;
  	}
! 	*offset = call_utcoffset(tzinfo, tzinfoarg, &none);
  	if (*offset == -1 && PyErr_Occurred())
  		return OFFSET_ERROR;
***************
*** 839,843 ****
  static int
  classify_two_utcoffsets(PyObject *o1, int *offset1, naivety *n1,
! 			PyObject *o2, int *offset2, naivety *n2)
  {
  	if (get_tzinfo_member(o1) == get_tzinfo_member(o2)) {
--- 839,845 ----
  static int
  classify_two_utcoffsets(PyObject *o1, int *offset1, naivety *n1,
! 			PyObject *tzinfoarg1,
! 			PyObject *o2, int *offset2, naivety *n2,
! 			PyObject *tzinfoarg2)
  {
  	if (get_tzinfo_member(o1) == get_tzinfo_member(o2)) {
***************
*** 846,853 ****
  	}
  	else {
! 		*n1 = classify_utcoffset(o1, offset1);
  		if (*n1 == OFFSET_ERROR)
  			return -1;
! 		*n2 = classify_utcoffset(o2, offset2);
  		if (*n2 == OFFSET_ERROR)
  			return -1;
--- 848,855 ----
  	}
  	else {
! 		*n1 = classify_utcoffset(o1, tzinfoarg1, offset1);
  		if (*n1 == OFFSET_ERROR)
  			return -1;
! 		*n2 = classify_utcoffset(o2, tzinfoarg2, offset2);
  		if (*n2 == OFFSET_ERROR)
  			return -1;
***************
*** 3178,3182 ****
  
  	if (classify_two_utcoffsets((PyObject *)self, &offset1, &n1,
! 				     other, &offset2, &n2) < 0)
  		return NULL;
  	assert(n1 != OFFSET_UNKNOWN && n2 != OFFSET_UNKNOWN);
--- 3180,3186 ----
  
  	if (classify_two_utcoffsets((PyObject *)self, &offset1, &n1,
! 				    (PyObject *)self,
! 				     other, &offset2, &n2,
! 				     other) < 0)
  		return NULL;
  	assert(n1 != OFFSET_UNKNOWN && n2 != OFFSET_UNKNOWN);
***************
*** 3232,3236 ****
  		PyObject *temp;
  
! 		n = classify_utcoffset((PyObject *)self, &offset);
  		assert(n != OFFSET_UNKNOWN);
  		if (n == OFFSET_ERROR)
--- 3236,3241 ----
  		PyObject *temp;
  
! 		n = classify_utcoffset((PyObject *)self, (PyObject *)self,
! 				       &offset);
  		assert(n != OFFSET_UNKNOWN);
  		if (n == OFFSET_ERROR)
***************
*** 3691,3696 ****
  		return NULL;
  	}
! 	if (classify_two_utcoffsets((PyObject *)self, &offset1, &n1,
! 				     other, &offset2, &n2) < 0)
  		return NULL;
  	assert(n1 != OFFSET_UNKNOWN && n2 != OFFSET_UNKNOWN);
--- 3696,3701 ----
  		return NULL;
  	}
! 	if (classify_two_utcoffsets((PyObject *)self, &offset1, &n1, Py_None,
! 				     other, &offset2, &n2, Py_None) < 0)
  		return NULL;
  	assert(n1 != OFFSET_UNKNOWN && n2 != OFFSET_UNKNOWN);
***************
*** 3740,3744 ****
  		PyObject *temp;
  
! 		n = classify_utcoffset((PyObject *)self, &offset);
  		assert(n != OFFSET_UNKNOWN);
  		if (n == OFFSET_ERROR)
--- 3745,3749 ----
  		PyObject *temp;
  
! 		n = classify_utcoffset((PyObject *)self, Py_None, &offset);
  		assert(n != OFFSET_UNKNOWN);
  		if (n == OFFSET_ERROR)
***************
*** 4629,4634 ****
  			PyDateTime_Delta *delta;
  
! 			if (classify_two_utcoffsets(left, &offset1, &n1,
! 						    right, &offset2, &n2) < 0)
  				return NULL;
  			assert(n1 != OFFSET_UNKNOWN && n2 != OFFSET_UNKNOWN);
--- 4634,4640 ----
  			PyDateTime_Delta *delta;
  
! 			if (classify_two_utcoffsets(left, &offset1, &n1, left,
! 						    right, &offset2, &n2,
! 						    right) < 0)
  				return NULL;
  			assert(n1 != OFFSET_UNKNOWN && n2 != OFFSET_UNKNOWN);