Mercurial > cpython-lru_cache-weakref
diff Python/compile.c @ 24736:ff05eef3a6d1 legacy-trunk
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.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Sun, 11 Aug 2002 04:24:12 +0000 |
| parents | 43caa212b959 |
| children | eec6832818a3 |
line wrap: on
line diff
--- a/Python/compile.c Sun Aug 11 04:15:09 2002 +0000 +++ b/Python/compile.c Sun Aug 11 04:24:12 2002 +0000 @@ -1154,8 +1154,16 @@ #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') {
