summaryrefslogtreecommitdiffstats
path: root/Objects/intobject.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2003-02-12 20:48:22 (GMT)
committerGuido van Rossum <guido@python.org>2003-02-12 20:48:22 (GMT)
commit47710656e53717b8369b72efcc486287f61bd69e (patch)
tree865a2fa565460d12a191b62daab1531f4403923e /Objects/intobject.c
parent3288f592cba8476faaa9412548be575df3f4d573 (diff)
downloadcpython-47710656e53717b8369b72efcc486287f61bd69e.zip
cpython-47710656e53717b8369b72efcc486287f61bd69e.tar.gz
cpython-47710656e53717b8369b72efcc486287f61bd69e.tar.bz2
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).
Diffstat (limited to 'Objects/intobject.c')
-rw-r--r--Objects/intobject.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/Objects/intobject.c b/Objects/intobject.c
index 544e663..fee7e4e 100644
--- a/Objects/intobject.c
+++ b/Objects/intobject.c
@@ -187,17 +187,22 @@ PyInt_FromString(char *s, char **pend, int base)
char *end;
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");
+ PyErr_SetString(PyExc_ValueError,
+ "int() base must be >= 2 and <= 36");
return NULL;
}
while (*s && isspace(Py_CHARMASK(*s)))
s++;
errno = 0;
- if (base == 0 && s[0] == '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);
if (end == s || !isalnum(Py_CHARMASK(end[-1])))
@@ -216,6 +221,11 @@ PyInt_FromString(char *s, char **pend, int base)
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)
*pend = end;
return PyInt_FromLong(x);