[Python-checkins] python/dist/src/Objects intobject.c,2.101,2.102

gvanrossum@users.sourceforge.net gvanrossum@users.sourceforge.net
Wed, 12 Feb 2003 12:43:38 -0800


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

Modified Files:
	intobject.c 
Log Message:
Issue a warning when int('0...', 0) returns an int with the sign
folded; this will change in Python 2.4.  On a 32-bit machine, this
happens for 0x80000000 through 0xffffffff, and for octal constants in
the same value range.  No warning is issued if an explicit base is
given, *or* if the string contains a sign (since in those cases no
sign folding ever happens).


Index: intobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/intobject.c,v
retrieving revision 2.101
retrieving revision 2.102
diff -C2 -d -r2.101 -r2.102
*** intobject.c	10 Feb 2003 02:12:42 -0000	2.101
--- intobject.c	12 Feb 2003 20:43:33 -0000	2.102
***************
*** 188,194 ****
  	long x;
  	char buffer[256]; /* For errors */
  
  	if ((base != 0 && base < 2) || base > 36) {
! 		PyErr_SetString(PyExc_ValueError, "int() base must be >= 2 and <= 36");
  		return NULL;
  	}
--- 188,196 ----
  	long x;
  	char buffer[256]; /* For errors */
+ 	int warn = 0;
  
  	if ((base != 0 && base < 2) || base > 36) {
! 		PyErr_SetString(PyExc_ValueError,
! 				"int() base must be >= 2 and <= 36");
  		return NULL;
  	}
***************
*** 197,202 ****
  		s++;
  	errno = 0;
! 	if (base == 0 && s[0] == '0')
  		x = (long) PyOS_strtoul(s, &end, base);
  	else
  		x = PyOS_strtol(s, &end, base);
--- 199,207 ----
  		s++;
  	errno = 0;
! 	if (base == 0 && s[0] == '0') {
  		x = (long) PyOS_strtoul(s, &end, base);
+ 		if (x < 0)
+ 			warn = 1;
+ 	}
  	else
  		x = PyOS_strtol(s, &end, base);
***************
*** 216,219 ****
--- 221,229 ----
  			return NULL;
  		return PyLong_FromString(s, pend, base);
+ 	}
+ 	if (warn) {
+ 		if (PyErr_Warn(PyExc_FutureWarning,
+ 			"int('0...', 0): sign will change in Python 2.4") < 0)
+ 			return NULL;
  	}
  	if (pend)