[Python-checkins] python/nondist/sandbox/datetime datetime.c,1.30,1.31 obj_delta.c,1.12,1.13

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
2002年12月01日 16:57:06 -0800


Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory sc8-pr-cvs1:/tmp/cvs-serv11595
Modified Files:
	datetime.c obj_delta.c 
Log Message:
delta_new(): Don't make a special case out of 1 anymore, and introduced
a trivial local macro to reduce the mind-numbing repetition.
Index: datetime.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/datetime.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -d -r1.30 -r1.31
*** datetime.c	1 Dec 2002 23:49:56 -0000	1.30
--- datetime.c	2 Dec 2002 00:57:04 -0000	1.31
***************
*** 469,480 ****
 }
 
! static PyObject *us_per_ms = NULL;
! static PyObject *us_per_second = NULL;
! static PyObject *us_per_minute = NULL;
! static PyObject *us_per_hour = NULL;
! static PyObject *us_per_day = NULL;
! static PyObject *us_per_week = NULL;
 
! static PyObject *seconds_per_day = NULL;
 
 /* Create a date instance with no range checking. */
--- 469,481 ----
 }
 
! static PyObject *us_per_us = NULL;	/* 1 */
! static PyObject *us_per_ms = NULL;	/* 1000 */
! static PyObject *us_per_second = NULL;	/* 1000000 */
! static PyObject *us_per_minute = NULL;	/* 1e6 * 60 as Python int */
! static PyObject *us_per_hour = NULL;	/* 1e6 * 3600 as Python long */
! static PyObject *us_per_day = NULL;	/* 1e6 * 3600 * 24 as Python long */
! static PyObject *us_per_week = NULL;	/* 1e6*3600*24*7 as Python long */
 
! static PyObject *seconds_per_day = NULL; /* 3600*24 as Python int */
 
 /* Create a date instance with no range checking. */
***************
*** 616,619 ****
--- 617,621 ----
 	assert(DI100Y == days_before_year(100+1));
 
+ 	us_per_us = PyInt_FromLong(1);
 	us_per_ms = PyInt_FromLong(1000);
 	us_per_second = PyInt_FromLong(1000000);
Index: obj_delta.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/obj_delta.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** obj_delta.c	2 Dec 2002 00:49:50 -0000	1.12
--- obj_delta.c	2 Dec 2002 00:57:04 -0000	1.13
***************
*** 458,513 ****
 		goto Done;
 
 	if (us) {
! 		PyObject *one = PyInt_FromLong(1);
! 		if (one == NULL)
! 			goto Done;
! 		y = accum("microseconds", x, us, one, &leftover_us);
! 		Py_DECREF(one);
! 		Py_DECREF(x);
! 		x = y;
! 		if (x == NULL)
! 			goto Done;
 	}
 	if (ms) {
 		y = accum("milliseconds", x, ms, us_per_ms, &leftover_us);
! 		Py_DECREF(x);
! 		x = y;
! 		if (x == NULL)
! 			goto Done;
 	}
 	if (second) {
 		y = accum("seconds", x, second, us_per_second, &leftover_us);
! 		Py_DECREF(x);
! 		x = y;
! 		if (x == NULL)
! 			goto Done;
 	}
 	if (minute) {
 		y = accum("minutes", x, minute, us_per_minute, &leftover_us);
! 		Py_DECREF(x);
! 		x = y;
! 		if (x == NULL)
! 			goto Done;
 	}
 	if (hour) {
 		y = accum("hours", x, hour, us_per_hour, &leftover_us);
! 		Py_DECREF(x);
! 		x = y;
! 		if (x == NULL)
! 			goto Done;
 	}
 	if (day) {
 		y = accum("days", x, day, us_per_day, &leftover_us);
! 		Py_DECREF(x);
! 		x = y;
! 		if (x == NULL)
! 			goto Done;
 	}
 	if (week) {
 		y = accum("weeks", x, week, us_per_week, &leftover_us);
! 		Py_DECREF(x);
! 		x = y;
! 		if (x == NULL)
! 			goto Done;
 	}
 	if (leftover_us) {
--- 458,494 ----
 		goto Done;
 
+ #define CLEANUP 	\
+ 	Py_DECREF(x);	\
+ 	x = y;		\
+ 	if (x == NULL)	\
+ 		goto Done
+ 
 	if (us) {
! 		y = accum("microseconds", x, us, us_per_us, &leftover_us);
! 		CLEANUP;
 	}
 	if (ms) {
 		y = accum("milliseconds", x, ms, us_per_ms, &leftover_us);
! 		CLEANUP;
 	}
 	if (second) {
 		y = accum("seconds", x, second, us_per_second, &leftover_us);
! 		CLEANUP;
 	}
 	if (minute) {
 		y = accum("minutes", x, minute, us_per_minute, &leftover_us);
! 		CLEANUP;
 	}
 	if (hour) {
 		y = accum("hours", x, hour, us_per_hour, &leftover_us);
! 		CLEANUP;
 	}
 	if (day) {
 		y = accum("days", x, day, us_per_day, &leftover_us);
! 		CLEANUP;
 	}
 	if (week) {
 		y = accum("weeks", x, week, us_per_week, &leftover_us);
! 		CLEANUP;
 	}
 	if (leftover_us) {
***************
*** 525,532 ****
 		y = PyNumber_Add(x, temp);
 		Py_DECREF(temp);
! 		Py_DECREF(x);
! 		x = y;
! 		if (x == NULL)
! 			goto Done;
 	}
 
--- 506,510 ----
 		y = PyNumber_Add(x, temp);
 		Py_DECREF(temp);
! 		CLEANUP;
 	}
 
***************
*** 535,538 ****
--- 513,518 ----
 Done:
 	return self;
+ 
+ #undef CLEANUP
 }
 

AltStyle によって変換されたページ (->オリジナル) /