[Python-checkins] python/nondist/sandbox/datetime datetime.c,1.70,1.71 datetime.h,1.17,1.18 obj_date.c,1.53,1.54 obj_datetime.c,1.55,1.56 obj_datetimetz.c,1.15,1.16 obj_delta.c,1.27,1.28 obj_time.c,1.17,1.18 obj_timetz.c,1.27,1.28

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
2002年12月14日 09:42:12 -0800


Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory sc8-pr-cvs1:/tmp/cvs-serv21596
Modified Files:
	datetime.c datetime.h obj_date.c obj_datetime.c 
	obj_datetimetz.c obj_delta.c obj_time.c obj_timetz.c 
Log Message:
Finally bit the moldy int-vs-long bullet. We use int everywhere now,
except where we absolutely can't. Should have done this the first day.
Index: datetime.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/datetime.c,v
retrieving revision 1.70
retrieving revision 1.71
diff -C2 -d -r1.70 -r1.71
*** datetime.c	14 Dec 2002 16:23:34 -0000	1.70
--- datetime.c	14 Dec 2002 17:42:09 -0000	1.71
***************
*** 11,14 ****
--- 11,23 ----
 #include "datetime.h"
 
+ /* We require that C int be at least 32 bits, and use int virtually
+ * everywhere. In just a few cases we use a temp long, where a Python
+ * API returns a C long. In such cases, we have to ensure that the
+ * final result fits in a C int (this can be an issue on 64-bit boxes).
+ */
+ #if SIZEOF_INT < 4
+ #	error "datetime.c requires that C int have at least 32 bits"
+ #endif
+ 
 #define MINYEAR 1
 #define MAXYEAR 9999
***************
*** 96,103 ****
 * overflow case).
 */
! static long
! divmod(long x, long y, long *r)
 {
! 	long quo;
 
 	assert(y > 0);
--- 105,112 ----
 * overflow case).
 */
! static int
! divmod(int x, int y, int *r)
 {
! 	int quo;
 
 	assert(y > 0);
***************
*** 172,176 ****
 * start with year 1, so days_before_year(1) == 0.
 */
! static long
 days_before_year(int year)
 {
--- 181,185 ----
 * start with year 1, so days_before_year(1) == 0.
 */
! static int
 days_before_year(int year)
 {
***************
*** 195,199 ****
 /* ordinal -> year, month, day, considering 01-Jan-0001 as day 1. */
 static void
! ord_to_ymd(long ordinal, long *year, long *month, long *day)
 {
 	int n, n1, n4, n100, n400, leapyear, preceding;
--- 204,208 ----
 /* ordinal -> year, month, day, considering 01-Jan-0001 as day 1. */
 static void
! ord_to_ymd(int ordinal, int *year, int *month, int *day)
 {
 	int n, n1, n4, n100, n400, leapyear, preceding;
***************
*** 278,282 ****
 
 /* year, month, day -> ordinal, considering 01-Jan-0001 as day 1. */
! static long
 ymd_to_ord(int year, int month, int day)
 {
--- 287,291 ----
 
 /* year, month, day -> ordinal, considering 01-Jan-0001 as day 1. */
! static int
 ymd_to_ord(int year, int month, int day)
 {
***************
*** 316,331 ****
 */
 static int
! check_delta_day_range(long days, PyObject *exception)
 {
- 	char buf[200];
- 
 	if (-MAX_DELTA_DAYS <= days && days <= MAX_DELTA_DAYS)
 		return 0;
! 	/* PyErr_Format() ignores the "l" in "%ld", which isn't correct
! 	 * on boxes where sizeof(long) > sizeof(int). So roll our own.
! 	 */
! 	PyOS_snprintf(buf, sizeof(buf), "days=%ld; must have magnitude <= %d",
! 		 days, MAX_DELTA_DAYS);
! 	PyErr_SetString(exception, buf);
 	return -1;
 }
--- 325,335 ----
 */
 static int
! check_delta_day_range(int days, PyObject *exception)
 {
 	if (-MAX_DELTA_DAYS <= days && days <= MAX_DELTA_DAYS)
 		return 0;
! 	PyErr_Format(exception,
! 		 "days=%d; must have magnitude <= %d",
! 		 days);
 	return -1;
 }
***************
*** 335,339 ****
 */
 static int
! check_date_args(long year, long month, long day)
 {
 
--- 339,343 ----
 */
 static int
! check_date_args(int year, int month, int day)
 {
 
***************
*** 360,364 ****
 */
 static int
! check_time_args(long h, long m, long s, long us)
 {
 	if (h < 0 || h > 23) {
--- 364,368 ----
 */
 static int
! check_time_args(int h, int m, int s, int us)
 {
 	if (h < 0 || h > 23) {
***************
*** 392,406 ****
 * factor "lo" units. factor must be > 0. If *lo is less than 0, or
 * at least factor, enough of *lo is converted into "hi" units so that
! * 0 <= *lo < factor. The input values must be such that long overflow
 * is impossible.
 */
 static void
! normalize_pair(long *hi, long *lo, long factor)
 {
 	assert(factor > 0);
 	assert(lo != hi);
 	if (*lo < 0 || *lo >= factor) {
! 		const long num_hi = divmod(*lo, factor, lo);
! 		const long new_hi = *hi + num_hi;
 		assert(! SIGNED_ADD_OVERFLOWED(new_hi, *hi, num_hi));
 		*hi = new_hi;
--- 396,410 ----
 * factor "lo" units. factor must be > 0. If *lo is less than 0, or
 * at least factor, enough of *lo is converted into "hi" units so that
! * 0 <= *lo < factor. The input values must be such that int overflow
 * is impossible.
 */
 static void
! normalize_pair(int *hi, int *lo, int factor)
 {
 	assert(factor > 0);
 	assert(lo != hi);
 	if (*lo < 0 || *lo >= factor) {
! 		const int num_hi = divmod(*lo, factor, lo);
! 		const int new_hi = *hi + num_hi;
 		assert(! SIGNED_ADD_OVERFLOWED(new_hi, *hi, num_hi));
 		*hi = new_hi;
***************
*** 416,420 ****
 */
 static void
! normalize_d_s_us(long *d, long *s, long *us)
 {
 	if (*us < 0 || *us >= 1000000) {
--- 420,424 ----
 */
 static void
! normalize_d_s_us(int *d, int *s, int *us)
 {
 	if (*us < 0 || *us >= 1000000) {
***************
*** 443,447 ****
 */
 static void
! normalize_y_m_d(long *y, long *m, long *d)
 {
 	int dim;	/* # of days in month */
--- 447,451 ----
 */
 static void
! normalize_y_m_d(int *y, int *m, int *d)
 {
 	int dim;	/* # of days in month */
***************
*** 462,466 ****
 	}
 	assert(1 <= *m && *m <= 12);
- 	assert(INT_MIN < *y && *y < INT_MAX); /* so cast to int is safe */
 
 	/* Now only day can be out of bounds (year may also be out of bounds
--- 466,469 ----
***************
*** 469,473 ****
 	 * method here is principled and explainable.
 	 */
! 	dim = days_in_month((int)*y, (int)*m);
 	if (*d < 1 || *d > dim) {
 		/* Move day-1 days from the first of the month. First try to
--- 472,476 ----
 	 * method here is principled and explainable.
 	 */
! 	dim = days_in_month(*y, *m);
 	if (*d < 1 || *d > dim) {
 		/* Move day-1 days from the first of the month. First try to
***************
*** 478,482 ****
 			--*m;
 			if (*m > 0)
! 				*d = days_in_month((int)*y, (int)*m);
 			else {
 				--*y;
--- 481,485 ----
 			--*m;
 			if (*m > 0)
! 				*d = days_in_month(*y, *m);
 			else {
 				--*y;
***************
*** 495,499 ****
 		}
 		else {
! 			long ordinal = ymd_to_ord((int)*y, (int)*m, 1) +
 						 *d - 1;
 			ord_to_ymd(ordinal, y, m, d);
--- 498,502 ----
 		}
 		else {
! 			int ordinal = ymd_to_ord(*y, *m, 1) +
 						 *d - 1;
 			ord_to_ymd(ordinal, y, m, d);
***************
*** 509,513 ****
 */
 static int
! normalize_date(long *year, long *month, long *day)
 {
 	int result;
--- 512,516 ----
 */
 static int
! normalize_date(int *year, int *month, int *day)
 {
 	int result;
***************
*** 528,534 ****
 */
 static int
! normalize_datetime(long *year, long *month, long *day,
! long *hour, long *minute, long *second,
! long *microsecond)
 {
 	normalize_pair(second, microsecond, 1000000);
--- 531,537 ----
 */
 static int
! normalize_datetime(int *year, int *month, int *day,
! int *hour, int *minute, int *second,
! int *microsecond)
 {
 	normalize_pair(second, microsecond, 1000000);
***************
*** 566,574 ****
 * *none is set to 0 and the offset is returned.
 */
! static long
 call_utcoffset(PyObject *tzinfo, PyObject *tzinfoarg, int *none)
 {
 	PyObject *u;
! 	long result = -1;
 
 	assert(tzinfo != NULL);
--- 569,577 ----
 * *none is set to 0 and the offset is returned.
 */
! static int
 call_utcoffset(PyObject *tzinfo, PyObject *tzinfoarg, int *none)
 {
 	PyObject *u;
! 	long result = -1;	/* Py{Inr,Long}_AsLong return long */
 
 	assert(tzinfo != NULL);
***************
*** 597,600 ****
--- 600,605 ----
 	}
 
+ Done:
+ 	Py_DECREF(u);
 	if (result < -1439 || result > 1439) {
 		PyErr_Format(PyExc_ValueError,
***************
*** 604,611 ****
 		result = -1;
 	}
! 
! Done:
! 	Py_DECREF(u);
! 	return result;
 }
 
--- 609,613 ----
 		result = -1;
 	}
! 	return (int)result;
 }
 
***************
*** 641,645 ****
 */
 static naivety
! classify_object(PyObject *op, long *offset)
 {
 	int none;
--- 643,647 ----
 */
 static naivety
! classify_object(PyObject *op, int *offset)
 {
 	int none;
***************
*** 785,791 ****
 		PyObject *tzinfo, PyObject *tzinfoarg)
 {
! 	long offset;
! 	long hours;
! 	long minutes;
 	char sign;
 	int none;
--- 787,793 ----
 		PyObject *tzinfo, PyObject *tzinfoarg)
 {
! 	int offset;
! 	int hours;
! 	int minutes;
 	char sign;
 	int none;
***************
*** 857,861 ****
 */
 static PyObject *
! diff_to_bool(long diff, int op)
 {
 	PyObject *result;
--- 859,863 ----
 */
 static PyObject *
! diff_to_bool(int diff, int op)
 {
 	PyObject *result;
***************
*** 949,953 ****
 static PyObject *
 new_datetimetz(int year, int month, int day, int hour, int minute,
! int second, int usecond, PyObject *tzinfo)
 {
 	PyDateTime_DateTimeTZ *self;
--- 951,955 ----
 static PyObject *
 new_datetimetz(int year, int month, int day, int hour, int minute,
! 	 int second, int usecond, PyObject *tzinfo)
 {
 	PyDateTime_DateTimeTZ *self;
***************
*** 999,1003 ****
 */
 static PyObject *
! new_delta(long days, long seconds, long microseconds, int normalize)
 {
 	PyDateTime_Delta *self;
--- 1001,1005 ----
 */
 static PyObject *
! new_delta(int days, int seconds, int microseconds, int normalize)
 {
 	PyDateTime_Delta *self;
Index: datetime.h
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/datetime.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** datetime.h	13 Dec 2002 19:00:53 -0000	1.17
--- datetime.h	14 Dec 2002 17:42:09 -0000	1.18
***************
*** 69,75 ****
 	PyObject_HEAD
 	long hashcode;		/* -1 when unknown */
! 	long days;		/* -MAX_DELTA_DAYS <= days <= MAX_DELTA_DAYS */
! 	long seconds;		/* 0 <= seconds < 24*3600 is invariant */
! 	long microseconds;	/* 0 <= microseconds < 1000000 is invariant */
 } PyDateTime_Delta;
 
--- 69,75 ----
 	PyObject_HEAD
 	long hashcode;		/* -1 when unknown */
! 	int days;		/* -MAX_DELTA_DAYS <= days <= MAX_DELTA_DAYS */
! 	int seconds;		/* 0 <= seconds < 24*3600 is invariant */
! 	int microseconds;	/* 0 <= microseconds < 1000000 is invariant */
 } PyDateTime_Delta;
 
Index: obj_date.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/obj_date.c,v
retrieving revision 1.53
retrieving revision 1.54
diff -C2 -d -r1.53 -r1.54
*** obj_date.c	14 Dec 2002 16:23:34 -0000	1.53
--- obj_date.c	14 Dec 2002 17:42:09 -0000	1.54
***************
*** 8,12 ****
 date_year(PyDateTime_Date *self, void *unused)
 {
! 	return (PyInt_FromLong(GET_YEAR(self)));
 }
 
--- 8,12 ----
 date_year(PyDateTime_Date *self, void *unused)
 {
! 	return PyInt_FromLong(GET_YEAR(self));
 }
 
***************
*** 14,18 ****
 date_month(PyDateTime_Date *self, void *unused)
 {
! 	return (PyInt_FromLong(GET_MONTH(self)));
 }
 
--- 14,18 ----
 date_month(PyDateTime_Date *self, void *unused)
 {
! 	return PyInt_FromLong(GET_MONTH(self));
 }
 
***************
*** 20,24 ****
 date_day(PyDateTime_Date *self, void *unused)
 {
! 	return (PyInt_FromLong(GET_DAY(self)));
 }
 
--- 20,24 ----
 date_day(PyDateTime_Date *self, void *unused)
 {
! 	return PyInt_FromLong(GET_DAY(self));
 }
 
***************
*** 36,42 ****
 {
 	PyObject *self = NULL;
! 	long year;
! 	long month;
! 	long day;
 
 	static char *keywords[] = {
--- 36,42 ----
 {
 	PyObject *self = NULL;
! 	int year;
! 	int month;
! 	int day;
 
 	static char *keywords[] = {
***************
*** 44,52 ****
 	};
 
! 	if (PyArg_ParseTupleAndKeywords(args, kw, "lll", keywords,
 					&year, &month, &day)) {
 		if (check_date_args(year, month, day) < 0)
 			return NULL;
! 		self = new_date((int)year, (int)month, (int)day);
 	}
 	return self;
--- 44,52 ----
 	};
 
! 	if (PyArg_ParseTupleAndKeywords(args, kw, "iii", keywords,
 					&year, &month, &day)) {
 		if (check_date_args(year, month, day) < 0)
 			return NULL;
! 		self = new_date(year, month, day);
 	}
 	return self;
***************
*** 119,128 ****
 {
 	PyObject *result = NULL;
! 	long ordinal;
 
! 	if (PyArg_ParseTuple(args, "l:fromordinal", &ordinal)) {
! 		long year;
! 		long month;
! 		long day;
 
 		if (ordinal < 1)
--- 119,128 ----
 {
 	PyObject *result = NULL;
! 	int ordinal;
 
! 	if (PyArg_ParseTuple(args, "i:fromordinal", &ordinal)) {
! 		int year;
! 		int month;
! 		int day;
 
 		if (ordinal < 1)
***************
*** 131,135 ****
 		else {
 			ord_to_ymd(ordinal, &year, &month, &day);
! 			result = PyObject_CallFunction(cls, "lll",
 						 year, month, day);
 		}
--- 131,135 ----
 		else {
 			ord_to_ymd(ordinal, &year, &month, &day);
! 			result = PyObject_CallFunction(cls, "iii",
 						 year, month, day);
 		}
***************
*** 149,160 ****
 {
 	PyObject *result = NULL;
! 	long year = GET_YEAR(date);
! 	long month = GET_MONTH(date);
! 	long deltadays = GET_TD_DAYS(delta);
 	/* C-level overflow is impossible because |deltadays| < 1e9. */
! 	long day = GET_DAY(date) + (negate ? -deltadays : deltadays);
 
 	if (normalize_date(&year, &month, &day) >= 0)
! 		result = new_date((int)year, (int)month, (int)day);
 	return result;
 }
--- 149,160 ----
 {
 	PyObject *result = NULL;
! 	int year = GET_YEAR(date);
! 	int month = GET_MONTH(date);
! 	int deltadays = GET_TD_DAYS(delta);
 	/* C-level overflow is impossible because |deltadays| < 1e9. */
! 	int day = GET_DAY(date) + (negate ? -deltadays : deltadays);
 
 	if (normalize_date(&year, &month, &day) >= 0)
! 		result = new_date(year, month, day);
 	return result;
 }
***************
*** 199,208 ****
 		if (PyDate_CheckExact(right)) {
 			/* date - date */
! 			long left_ord = ymd_to_ord(GET_YEAR(left),
! 						 GET_MONTH(left),
! 						 GET_DAY(left));
! 			long right_ord = ymd_to_ord(GET_YEAR(right),
! 						 GET_MONTH(right),
! 						 GET_DAY(right));
 			return new_delta(left_ord - right_ord, 0, 0, 0);
 		}
--- 199,208 ----
 		if (PyDate_CheckExact(right)) {
 			/* date - date */
! 			int left_ord = ymd_to_ord(GET_YEAR(left),
! 						 GET_MONTH(left),
! 						 GET_DAY(left));
! 			int right_ord = ymd_to_ord(GET_YEAR(right),
! 						 GET_MONTH(right),
! 						 GET_DAY(right));
 			return new_delta(left_ord - right_ord, 0, 0, 0);
 		}
***************
*** 290,296 ****
 	int year = GET_YEAR(self);
 	int week1_monday = iso_week1_monday(year);
! 	long today = ymd_to_ord(year, GET_MONTH(self), GET_DAY(self));
! 	long week;
! 	long day;
 
 	week = divmod(today - week1_monday, 7, &day);
--- 290,296 ----
 	int year = GET_YEAR(self);
 	int week1_monday = iso_week1_monday(year);
! 	int today = ymd_to_ord(year, GET_MONTH(self), GET_DAY(self));
! 	int week;
! 	int day;
 
 	week = divmod(today - week1_monday, 7, &day);
***************
*** 304,308 ****
 		week = 0;
 	}
! 	return Py_BuildValue("iii", year, (int)week + 1, (int)day + 1);
 }
 
--- 304,308 ----
 		week = 0;
 	}
! 	return Py_BuildValue("iii", year, week + 1, day + 1);
 }
 
***************
*** 316,320 ****
 date_richcompare(PyDateTime_Date *self, PyObject *other, int op)
 {
! 	long diff;
 
 	if (! PyDate_Check(other)) {
--- 316,320 ----
 date_richcompare(PyDateTime_Date *self, PyObject *other, int op)
 {
! 	int diff;
 
 	if (! PyDate_Check(other)) {
Index: obj_datetime.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/obj_datetime.c,v
retrieving revision 1.55
retrieving revision 1.56
diff -C2 -d -r1.55 -r1.56
*** obj_datetime.c	14 Dec 2002 16:23:34 -0000	1.55
--- obj_datetime.c	14 Dec 2002 17:42:09 -0000	1.56
***************
*** 43,53 ****
 {
 	PyObject *self = NULL;
! 	long year;
! 	long month;
! 	long day;
! 	long hour = 0;
! 	long minute = 0;
! 	long second = 0;
! 	long usecond = 0;
 
 	static char *keywords[] = {
--- 43,53 ----
 {
 	PyObject *self = NULL;
! 	int year;
! 	int month;
! 	int day;
! 	int hour = 0;
! 	int minute = 0;
! 	int second = 0;
! 	int usecond = 0;
 
 	static char *keywords[] = {
***************
*** 56,60 ****
 	};
 
! 	if (PyArg_ParseTupleAndKeywords(args, kw, "lll|llll", keywords,
 					&year, &month, &day, &hour, &minute,
 					&second, &usecond)) {
--- 56,60 ----
 	};
 
! 	if (PyArg_ParseTupleAndKeywords(args, kw, "iii|iiii", keywords,
 					&year, &month, &day, &hour, &minute,
 					&second, &usecond)) {
***************
*** 63,69 ****
 		if (check_time_args(hour, minute, second, usecond) < 0)
 			return NULL;
! 		self = new_datetime((int)year, (int)month, (int)day, 
! 				 (int)hour, (int)minute, (int)second,
! 				 (int)usecond);
 	}
 	return self;
--- 63,68 ----
 		if (check_time_args(hour, minute, second, usecond) < 0)
 			return NULL;
! 		self = new_datetime(year, month, day, 
! 				 hour, minute, second, usecond);
 	}
 	return self;
***************
*** 79,83 ****
 */
 static PyObject *
! datetime_from_timet_and_us(PyObject *cls, TM_FUNC f, time_t timet, long us)
 {
 	struct tm *tm;
--- 78,82 ----
 */
 static PyObject *
! datetime_from_timet_and_us(PyObject *cls, TM_FUNC f, time_t timet, int us)
 {
 	struct tm *tm;
***************
*** 86,90 ****
 	tm = f(&timet);
 	if (tm)
! 		result = PyObject_CallFunction(cls, "iiiiiil",
 					 tm->tm_year + 1900,
 					 tm->tm_mon + 1,
--- 85,89 ----
 	tm = f(&timet);
 	if (tm)
! 		result = PyObject_CallFunction(cls, "iiiiiii",
 					 tm->tm_year + 1900,
 					 tm->tm_mon + 1,
***************
*** 112,116 ****
 {
 	time_t timet = (time_t)timestamp;
! 	long us = (long)((timestamp - (double)timet) * 1e6);
 
 	return datetime_from_timet_and_us(cls, f, timet, us);
--- 111,115 ----
 {
 	time_t timet = (time_t)timestamp;
! 	int us = (int)((timestamp - (double)timet) * 1e6);
 
 	return datetime_from_timet_and_us(cls, f, timet, us);
***************
*** 243,254 ****
 	 * invariant bounds on the member values.
 	 */
! 	long year = GET_YEAR(date);
! 	long month = GET_MONTH(date);
! 	long day = GET_DAY(date) + GET_TD_DAYS(delta);
! 	long hour = DATE_GET_HOUR(date);
! 	long minute = DATE_GET_MINUTE(date);
! 	long second = DATE_GET_SECOND(date) + GET_TD_SECONDS(delta);
! 	long microsecond = DATE_GET_MICROSECOND(date) +
! 			 GET_TD_MICROSECONDS(delta);
 
 	if (normalize_datetime(&year, &month, &day,
--- 242,253 ----
 	 * invariant bounds on the member values.
 	 */
! 	int year = GET_YEAR(date);
! 	int month = GET_MONTH(date);
! 	int day = GET_DAY(date) + GET_TD_DAYS(delta);
! 	int hour = DATE_GET_HOUR(date);
! 	int minute = DATE_GET_MINUTE(date);
! 	int second = DATE_GET_SECOND(date) + GET_TD_SECONDS(delta);
! 	int microsecond = DATE_GET_MICROSECOND(date) +
! 			 GET_TD_MICROSECONDS(delta);
 
 	if (normalize_datetime(&year, &month, &day,
***************
*** 256,262 ****
 		return NULL;
 	else
! 		return new_datetime((int)year, (int)month, (int)day,
! 				 (int)hour, (int)minute, (int)second,
! 				 (int)microsecond);
 }
 
--- 255,260 ----
 		return NULL;
 	else
! 		return new_datetime(year, month, day,
! 				 hour, minute, second, microsecond);
 }
 
***************
*** 267,278 ****
 	 * invariant bounds on the member values.
 	 */
! 	long year = GET_YEAR(date);
! 	long month = GET_MONTH(date);
! 	long day = GET_DAY(date) - GET_TD_DAYS(delta);
! 	long hour = DATE_GET_HOUR(date);
! 	long minute = DATE_GET_MINUTE(date);
! 	long second = DATE_GET_SECOND(date) - GET_TD_SECONDS(delta);
! 	long microsecond = DATE_GET_MICROSECOND(date) -
! 			 GET_TD_MICROSECONDS(delta);
 
 	if (normalize_datetime(&year, &month, &day,
--- 265,276 ----
 	 * invariant bounds on the member values.
 	 */
! 	int year = GET_YEAR(date);
! 	int month = GET_MONTH(date);
! 	int day = GET_DAY(date) - GET_TD_DAYS(delta);
! 	int hour = DATE_GET_HOUR(date);
! 	int minute = DATE_GET_MINUTE(date);
! 	int second = DATE_GET_SECOND(date) - GET_TD_SECONDS(delta);
! 	int microsecond = DATE_GET_MICROSECOND(date) -
! 			 GET_TD_MICROSECONDS(delta);
 
 	if (normalize_datetime(&year, &month, &day,
***************
*** 280,286 ****
 		return NULL;
 	else
! 		return new_datetime((int)year, (int)month, (int)day,
! 				 (int)hour, (int)minute, (int)second,
! 				 (int)microsecond);
 }
 
--- 278,283 ----
 		return NULL;
 	else
! 		return new_datetime(year, month, day,
! 				 hour, minute, second, microsecond);
 }
 
***************
*** 288,305 ****
 sub_datetime_datetime(PyDateTime_DateTime *left, PyDateTime_DateTime *right)
 {
! 	long days1 = ymd_to_ord(GET_YEAR(left),
! 				GET_MONTH(left),
! 				GET_DAY(left));
! 	long days2 = ymd_to_ord(GET_YEAR(right),
! 				GET_MONTH(right),
! 				GET_DAY(right));
 	/* These can't overflow, since the values are normalized. At most
 	 * this gives the number of seconds in one day.
 	 */
! 	long delta_s = (DATE_GET_HOUR(left) - DATE_GET_HOUR(right)) * 3600 +
! 	 (DATE_GET_MINUTE(left) - DATE_GET_MINUTE(right)) * 60 +
! 		 DATE_GET_SECOND(left) - DATE_GET_SECOND(right);
! 	long delta_us = DATE_GET_MICROSECOND(left) -
! 			DATE_GET_MICROSECOND(right);
 
 	return new_delta(days1 - days2, delta_s, delta_us, 1);
--- 285,300 ----
 sub_datetime_datetime(PyDateTime_DateTime *left, PyDateTime_DateTime *right)
 {
! 	int days1 = ymd_to_ord(GET_YEAR(left), GET_MONTH(left), GET_DAY(left));
! 	int days2 = ymd_to_ord(GET_YEAR(right),
! 			 GET_MONTH(right),
! 			 GET_DAY(right));
 	/* These can't overflow, since the values are normalized. At most
 	 * this gives the number of seconds in one day.
 	 */
! 	int delta_s = (DATE_GET_HOUR(left) - DATE_GET_HOUR(right)) * 3600 +
! 	 (DATE_GET_MINUTE(left) - DATE_GET_MINUTE(right)) * 60 +
! 		 DATE_GET_SECOND(left) - DATE_GET_SECOND(right);
! 	int delta_us = DATE_GET_MICROSECOND(left) -
! 		 DATE_GET_MICROSECOND(right);
 
 	return new_delta(days1 - days2, delta_s, delta_us, 1);
***************
*** 431,437 ****
 datetime_richcompare(PyDateTime_DateTime *self, PyObject *other, int op)
 {
! 	long diff;
 	naivety n1, n2;
! 	long offset1, offset2;
 
 	if (! PyDateTime_Check(other)) {
--- 426,432 ----
 datetime_richcompare(PyDateTime_DateTime *self, PyObject *other, int op)
 {
! 	int diff;
 	naivety n1, n2;
! 	int offset1, offset2;
 
 	if (! PyDateTime_Check(other)) {
***************
*** 469,473 ****
 		 */
 		PyDateTime_Delta *delta;
! 		long days, seconds, us;
 
 		assert(offset1 != offset2);	/* else last "if" handled it */
--- 464,468 ----
 		 */
 		PyDateTime_Delta *delta;
! 		int days, seconds, us;
 
 		assert(offset1 != offset2);	/* else last "if" handled it */
***************
*** 501,505 ****
 	if (self->hashcode == -1) {
 		naivety n;
! 		long offset;
 
 		n = classify_object((PyObject *)self, &offset);
--- 496,500 ----
 	if (self->hashcode == -1) {
 		naivety n;
! 		int offset;
 
 		n = classify_object((PyObject *)self, &offset);
***************
*** 515,520 ****
 		}
 		else {
! 			long days;
! 			long seconds;
 			PyDateTime_Delta *delta;
 
--- 510,515 ----
 		}
 		else {
! 			int days;
! 			int seconds;
 			PyDateTime_Delta *delta;
 
Index: obj_datetimetz.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/obj_datetimetz.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** obj_datetimetz.c	14 Dec 2002 16:23:34 -0000	1.15
--- obj_datetimetz.c	14 Dec 2002 17:42:09 -0000	1.16
***************
*** 27,37 ****
 {
 	PyObject *self = NULL;
! 	long year;
! 	long month;
! 	long day;
! 	long hour = 0;
! 	long minute = 0;
! 	long second = 0;
! 	long usecond = 0;
 	PyObject *tzinfo = Py_None;
 
--- 27,37 ----
 {
 	PyObject *self = NULL;
! 	int year;
! 	int month;
! 	int day;
! 	int hour = 0;
! 	int minute = 0;
! 	int second = 0;
! 	int usecond = 0;
 	PyObject *tzinfo = Py_None;
 
***************
*** 41,45 ****
 	};
 
! 	if (PyArg_ParseTupleAndKeywords(args, kw, "lll|llllO", keywords,
 					&year, &month, &day, &hour, &minute,
 					&second, &usecond, &tzinfo)) {
--- 41,45 ----
 	};
 
! 	if (PyArg_ParseTupleAndKeywords(args, kw, "iii|iiiiO", keywords,
 					&year, &month, &day, &hour, &minute,
 					&second, &usecond, &tzinfo)) {
***************
*** 50,56 ****
 		if (check_tzinfo_subclass(tzinfo, "tzinfo argument") < 0)
 			return NULL;
! 		self = new_datetimetz((int)year, (int)month, (int)day,
! 				 (int)hour, (int)minute, (int)second,
! 				 (int)usecond,
 				 tzinfo);
 	}
--- 50,55 ----
 		if (check_tzinfo_subclass(tzinfo, "tzinfo argument") < 0)
 			return NULL;
! 		self = new_datetimetz(year, month, day,
! 				 hour, minute, second, usecond,
 				 tzinfo);
 	}
***************
*** 66,70 ****
 */
 static PyObject *
! datetimetz_from_timet_and_us(PyObject *cls, TM_FUNC f, time_t timet, long us)
 {
 	struct tm *tm;
--- 65,69 ----
 */
 static PyObject *
! datetimetz_from_timet_and_us(PyObject *cls, TM_FUNC f, time_t timet, int us)
 {
 	struct tm *tm;
***************
*** 73,77 ****
 	tm = f(&timet);
 	if (tm)
! 		result = PyObject_CallFunction(cls, "iiiiiil",
 					 tm->tm_year + 1900,
 					 tm->tm_mon + 1,
--- 72,76 ----
 	tm = f(&timet);
 	if (tm)
! 		result = PyObject_CallFunction(cls, "iiiiiii",
 					 tm->tm_year + 1900,
 					 tm->tm_mon + 1,
***************
*** 99,103 ****
 {
 	time_t timet = (time_t)timestamp;
! 	long us = (long)((timestamp - (double)timet) * 1e6);
 
 	return datetimetz_from_timet_and_us(cls, f, timet, us);
--- 98,102 ----
 {
 	time_t timet = (time_t)timestamp;
! 	int us = (int)((timestamp - (double)timet) * 1e6);
 
 	return datetimetz_from_timet_and_us(cls, f, timet, us);
***************
*** 288,292 ****
 			/* datetime - datetime */
 			naivety n1, n2;
! 			long offset1, offset2;
 			PyDateTime_Delta *delta;
 
--- 287,291 ----
 			/* datetime - datetime */
 			naivety n1, n2;
! 			int offset1, offset2;
 			PyDateTime_Delta *delta;
 
Index: obj_delta.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/obj_delta.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -d -r1.27 -r1.28
*** obj_delta.c	13 Dec 2002 19:22:32 -0000	1.27
--- obj_delta.c	14 Dec 2002 17:42:09 -0000	1.28
***************
*** 62,68 ****
 microseconds_to_delta(PyObject *pyus)
 {
! 	long us;
! 	long s;
! 	long d;
 
 	PyObject *tuple = NULL;
--- 62,68 ----
 microseconds_to_delta(PyObject *pyus)
 {
! 	int us;
! 	int s;
! 	int d;
 
 	PyObject *tuple = NULL;
***************
*** 175,182 ****
 		 * invariant bounds.
 		 */
! 		long days = GET_TD_DAYS(left) + GET_TD_DAYS(right);
! 		long seconds = GET_TD_SECONDS(left) + GET_TD_SECONDS(right);
! 		long microseconds = GET_TD_MICROSECONDS(left) +
! 				 GET_TD_MICROSECONDS(right);
 		result = new_delta(days, seconds, microseconds, 1);
 	}
--- 175,182 ----
 		 * invariant bounds.
 		 */
! 		int days = GET_TD_DAYS(left) + GET_TD_DAYS(right);
! 		int seconds = GET_TD_SECONDS(left) + GET_TD_SECONDS(right);
! 		int microseconds = GET_TD_MICROSECONDS(left) +
! 				 GET_TD_MICROSECONDS(right);
 		result = new_delta(days, seconds, microseconds, 1);
 	}
***************
*** 252,256 ****
 delta_richcompare(PyDateTime_Delta *self, PyObject *other, int op)
 {
! 	long diff;
 
 	if (! PyDelta_CheckExact(other)) {
--- 252,256 ----
 delta_richcompare(PyDateTime_Delta *self, PyObject *other, int op)
 {
! 	int diff;
 
 	if (! PyDelta_CheckExact(other)) {
***************
*** 520,524 ****
 {
 	if (GET_TD_MICROSECONDS(self) != 0)
! 		return PyString_FromFormat("%s(%ld, %ld, %ld)",
 					 self->ob_type->tp_name,
 					 GET_TD_DAYS(self),
--- 520,524 ----
 {
 	if (GET_TD_MICROSECONDS(self) != 0)
! 		return PyString_FromFormat("%s(%d, %d, %d)",
 					 self->ob_type->tp_name,
 					 GET_TD_DAYS(self),
***************
*** 526,535 ****
 					 GET_TD_MICROSECONDS(self));
 	if (GET_TD_SECONDS(self) != 0)
! 		return PyString_FromFormat("%s(%ld, %ld)",
 					 self->ob_type->tp_name,
 					 GET_TD_DAYS(self),
 					 GET_TD_SECONDS(self));
 
! 	return PyString_FromFormat("%s(%ld)",
 				 self->ob_type->tp_name,
 				 GET_TD_DAYS(self));
--- 526,535 ----
 					 GET_TD_MICROSECONDS(self));
 	if (GET_TD_SECONDS(self) != 0)
! 		return PyString_FromFormat("%s(%d, %d)",
 					 self->ob_type->tp_name,
 					 GET_TD_DAYS(self),
 					 GET_TD_SECONDS(self));
 
! 	return PyString_FromFormat("%s(%d)",
 				 self->ob_type->tp_name,
 				 GET_TD_DAYS(self));
***************
*** 539,547 ****
 delta_str(PyDateTime_Delta *self)
 {
! 	long days = GET_TD_DAYS(self);
! 	long seconds = GET_TD_SECONDS(self);
! 	long us = GET_TD_MICROSECONDS(self);
! 	long hours;
! 	long minutes;
 	char buf[500];
 	int i = 0;
--- 539,547 ----
 delta_str(PyDateTime_Delta *self)
 {
! 	int days = GET_TD_DAYS(self);
! 	int seconds = GET_TD_SECONDS(self);
! 	int us = GET_TD_MICROSECONDS(self);
! 	int hours;
! 	int minutes;
 	char buf[500];
 	int i = 0;
***************
*** 551,565 ****
 
 	if (days) {
! 		i += sprintf(buf + i, "%d day%s, ", (int)days,
 			 (days == 1 || days == -1) ? "" : "s");
 		assert(i < sizeof(buf));
 	}
 
! 	i += sprintf(buf + i, "%d:%02d:%02d", (int)hours, (int)minutes,
! 					 (int)seconds);
 	assert(i < sizeof(buf));
 
 	if (us) {
! 		i += sprintf(buf + i, ".%06d", (int)us);
 		assert(i < sizeof(buf));
 	}
--- 551,564 ----
 
 	if (days) {
! 		i += sprintf(buf + i, "%d day%s, ", days,
 			 (days == 1 || days == -1) ? "" : "s");
 		assert(i < sizeof(buf));
 	}
 
! 	i += sprintf(buf + i, "%d:%02d:%02d", hours, minutes, seconds);
 	assert(i < sizeof(buf));
 
 	if (us) {
! 		i += sprintf(buf + i, ".%06d", us);
 		assert(i < sizeof(buf));
 	}
***************
*** 575,581 ****
 delta_getstate(PyDateTime_Delta *self)
 {
! 	return Py_BuildValue("iii", (int)GET_TD_DAYS(self),
! 				 (int)GET_TD_SECONDS(self),
! 				 (int)GET_TD_MICROSECONDS(self));
 }
 
--- 574,580 ----
 delta_getstate(PyDateTime_Delta *self)
 {
! 	return Py_BuildValue("iii", GET_TD_DAYS(self),
! 				 GET_TD_SECONDS(self),
! 				 GET_TD_MICROSECONDS(self));
 }
 
***************
*** 583,591 ****
 delta_setstate(PyDateTime_Delta *self, PyObject *state)
 {
! 	long day;
! 	long second;
! 	long us;
 
! 	if (!PyArg_ParseTuple(state, "lll:__setstate__", &day, &second, &us))
 		return NULL;
 
--- 582,590 ----
 delta_setstate(PyDateTime_Delta *self, PyObject *state)
 {
! 	int day;
! 	int second;
! 	int us;
 
! 	if (!PyArg_ParseTuple(state, "iii:__setstate__", &day, &second, &us))
 		return NULL;
 
Index: obj_time.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/obj_time.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** obj_time.c	14 Dec 2002 16:53:14 -0000	1.17
--- obj_time.c	14 Dec 2002 17:42:09 -0000	1.18
***************
*** 43,50 ****
 {
 	PyObject *self = NULL;
! 	long hour = 0;
! 	long minute = 0;
! 	long second = 0;
! 	long usecond = 0;
 
 	static char *keywords[] = {
--- 43,50 ----
 {
 	PyObject *self = NULL;
! 	int hour = 0;
! 	int minute = 0;
! 	int second = 0;
! 	int usecond = 0;
 
 	static char *keywords[] = {
***************
*** 52,61 ****
 	};
 
! 	if (PyArg_ParseTupleAndKeywords(args, kw, "|llll", keywords,
 					&hour, &minute, &second, &usecond)) {
 		if (check_time_args(hour, minute, second, usecond) < 0)
 			return NULL;
! 		self = new_time((int)hour, (int)minute, (int)second,
! 				(int)usecond);
 	}
 	return self;
--- 52,60 ----
 	};
 
! 	if (PyArg_ParseTupleAndKeywords(args, kw, "|iiii", keywords,
 					&hour, &minute, &second, &usecond)) {
 		if (check_time_args(hour, minute, second, usecond) < 0)
 			return NULL;
! 		self = new_time(hour, minute, second, usecond);
 	}
 	return self;
***************
*** 137,143 ****
 time_richcompare(PyDateTime_Time *self, PyObject *other, int op)
 {
! 	long diff;
 	naivety n1, n2;
! 	long offset1, offset2;
 
 	if (! PyTime_Check(other)) {
--- 136,142 ----
 time_richcompare(PyDateTime_Time *self, PyObject *other, int op)
 {
! 	int diff;
 	naivety n1, n2;
! 	int offset1, offset2;
 
 	if (! PyTime_Check(other)) {
***************
*** 201,205 ****
 	if (self->hashcode == -1) {
 		naivety n;
! 		long offset;
 		PyObject *temp;
 
--- 200,204 ----
 	if (self->hashcode == -1) {
 		naivety n;
! 		int offset;
 		PyObject *temp;
 
***************
*** 213,218 ****
 			temp = time_getstate(self);
 		else {
! 			long hour;
! 			long minute;
 
 			assert(n == OFFSET_AWARE);
--- 212,217 ----
 			temp = time_getstate(self);
 		else {
! 			int hour;
! 			int minute;
 
 			assert(n == OFFSET_AWARE);
***************
*** 223,231 ****
 				 &minute);
 			if (0 <= hour && hour < 24)
! 				temp = new_time((int)hour, (int)minute,
 						TIME_GET_SECOND(self),
 						TIME_GET_MICROSECOND(self));
 			else
! 				temp = Py_BuildValue("llii",
 					 hour, minute,
 					 TIME_GET_SECOND(self),
--- 222,230 ----
 				 &minute);
 			if (0 <= hour && hour < 24)
! 				temp = new_time(hour, minute,
 						TIME_GET_SECOND(self),
 						TIME_GET_MICROSECOND(self));
 			else
! 				temp = Py_BuildValue("iiii",
 					 hour, minute,
 					 TIME_GET_SECOND(self),
Index: obj_timetz.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/obj_timetz.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -d -r1.27 -r1.28
*** obj_timetz.c	14 Dec 2002 16:23:34 -0000	1.27
--- obj_timetz.c	14 Dec 2002 17:42:09 -0000	1.28
***************
*** 27,34 ****
 {
 	PyObject *self = NULL;
! 	long hour = 0;
! 	long minute = 0;
! 	long second = 0;
! 	long usecond = 0;
 	PyObject *tzinfo = Py_None;
 
--- 27,34 ----
 {
 	PyObject *self = NULL;
! 	int hour = 0;
! 	int minute = 0;
! 	int second = 0;
! 	int usecond = 0;
 	PyObject *tzinfo = Py_None;
 
***************
*** 44,50 ****
 		if (check_tzinfo_subclass(tzinfo, "tzinfo argument") < 0)
 			return NULL;
! 		self = new_timetz((int)hour, (int)minute, (int)second, 
! 				 (int)usecond,
! 				 tzinfo);
 	}
 	return self;
--- 44,48 ----
 		if (check_tzinfo_subclass(tzinfo, "tzinfo argument") < 0)
 			return NULL;
! 		self = new_timetz(hour, minute, second, usecond, tzinfo);
 	}
 	return self;
***************
*** 160,164 ****
 timetz_nonzero(PyDateTime_TimeTZ *self)
 {
! 	long offset;
 	int none;
 
--- 158,162 ----
 timetz_nonzero(PyDateTime_TimeTZ *self)
 {
! 	int offset;
 	int none;
 

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