summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2002-08-11 04:24:12 (GMT)
committerGuido van Rossum <guido@python.org>2002-08-11 04:24:12 (GMT)
commit078151da901bebce6eb232d958fbbb1e5ced4399 (patch)
treed25483ba545d58138518591645e60caa20a7262b /Python
parentd92ae840e940db2fc8e9ec6293fe22dbb73f4514 (diff)
downloadcpython-078151da901bebce6eb232d958fbbb1e5ced4399.zip
cpython-078151da901bebce6eb232d958fbbb1e5ced4399.tar.gz
cpython-078151da901bebce6eb232d958fbbb1e5ced4399.tar.bz2
Implement stage B0 of PEP 237: add warnings for operations that
currently return inconsistent results for ints and longs; in particular: hex/oct/%u/%o/%x/%X of negative short ints, and x<<n that either loses bits or changes sign. (No warnings for repr() of a long, though that will also change to lose the trailing 'L' eventually.) This introduces some warnings in the test suite; I'll take care of those later.
Diffstat (limited to 'Python')
-rw-r--r--Python/compile.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/Python/compile.c b/Python/compile.c
index 79756ea..e547e03 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -1154,8 +1154,16 @@ parsenumber(struct compiling *co, char *s)
#endif
if (*end == 'l' || *end == 'L')
return PyLong_FromString(s, (char **)0, 0);
- if (s[0] == '0')
+ if (s[0] == '0') {
x = (long) PyOS_strtoul(s, &end, 0);
+ if (x < 0 && errno == 0) {
+ if (PyErr_Warn(PyExc_DeprecationWarning,
+ "hex/oct constants > sys.maxint "
+ "will return positive values "
+ "in Python 2.4 and up") < 0)
+ return NULL;
+ }
+ }
else
x = PyOS_strtol(s, &end, 0);
if (*end == '\0') {