[Python-checkins] python/nondist/sandbox/datetime datetime.c,1.25,1.26
tim_one@users.sourceforge.net
tim_one@users.sourceforge.net
Mon, 25 Nov 2002 21:32:09 -0800
Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory sc8-pr-cvs1:/tmp/cvs-serv31253
Modified Files:
datetime.c
Log Message:
Reworked the signed-add-overflowed logic into a macro, as it's already
used twice and will be needed again.
Index: datetime.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/datetime.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** datetime.c 26 Nov 2002 05:17:27 -0000 1.25
--- datetime.c 26 Nov 2002 05:32:06 -0000 1.26
***************
*** 64,67 ****
--- 64,74 ----
*/
+ /* k = i+j overflows iff k differs in sign from both inputs,
+ * iff k^i has sign bit set and k^j has sign bit set,
+ * iff (k^i)&(k^j) has sign bit set.
+ */
+ #define SIGNED_ADD_OVERFLOWED(RESULT, I, J) \
+ ((((RESULT) ^ (I)) & ((RESULT) ^ (J))) < 0)
+
/* Compute Python divmod(x, y), returning the quotient and storing the
* remainder into *r. The quotient is the floor of x/y, and that's
***************
*** 362,369 ****
PyDateTime_Delta *self = NULL;
- /* k = i+j overflows iff k differs in sign from both inputs,
- * iff k^i has sign bit set and k^j has sign bit set,
- * iff (k^i)&(k^j) has sign bit set.
- */
if (microseconds < 0 || microseconds >= 1000000) {
long whole_seconds;
--- 369,372 ----
***************
*** 373,378 ****
assert(microseconds >= 0);
new_seconds = seconds + whole_seconds;
! if (((new_seconds ^ seconds) &
! (new_seconds ^ whole_seconds)) < 0) {
PyErr_SetString(PyExc_OverflowError, "timedelta "
"seconds component too large");
--- 376,381 ----
assert(microseconds >= 0);
new_seconds = seconds + whole_seconds;
! if (SIGNED_ADD_OVERFLOWED(new_seconds, seconds,
! whole_seconds)) {
PyErr_SetString(PyExc_OverflowError, "timedelta "
"seconds component too large");
***************
*** 388,392 ****
assert(seconds >= 0);
new_days = days + whole_days;
! if (((new_days ^ days) & (new_days ^ whole_days)) < 0) {
PyErr_SetString(PyExc_OverflowError, "timedelta "
"days component too large");
--- 391,395 ----
assert(seconds >= 0);
new_days = days + whole_days;
! if (SIGNED_ADD_OVERFLOWED(new_days, days, whole_days)) {
PyErr_SetString(PyExc_OverflowError, "timedelta "
"days component too large");