mirror of
https://github.com/python/cpython.git
synced 2025-12-10 19:10:59 +00:00
SF bug #1224347: int/long unification and hex()
Hex longs now print with lowercase letters like their int counterparts.
This commit is contained in:
parent
d4128f397d
commit
3296e696db
4 changed files with 11 additions and 14 deletions
|
|
@ -208,7 +208,7 @@ class LongTest(unittest.TestCase):
|
||||||
digits = digits or [0]
|
digits = digits or [0]
|
||||||
return '-'[:sign] + \
|
return '-'[:sign] + \
|
||||||
{8: '0', 10: '', 16: '0x'}[base] + \
|
{8: '0', 10: '', 16: '0x'}[base] + \
|
||||||
"".join(map(lambda i: "0123456789ABCDEF"[i], digits)) + "L"
|
"".join(map(lambda i: "0123456789abcdef"[i], digits)) + "L"
|
||||||
|
|
||||||
def check_format_1(self, x):
|
def check_format_1(self, x):
|
||||||
for base, mapper in (8, oct), (10, repr), (16, hex):
|
for base, mapper in (8, oct), (10, repr), (16, hex):
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,9 @@ What's New in Python 2.5 alpha 1?
|
||||||
Core and builtins
|
Core and builtins
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- SF bug #1224347: hex longs now print with lowercase letters just
|
||||||
|
like their int counterparts.
|
||||||
|
|
||||||
- SF bug #1163563: the original fix for bug #1010677 ("thread Module
|
- SF bug #1163563: the original fix for bug #1010677 ("thread Module
|
||||||
Breaks PyGILState_Ensure()") broke badly in the case of multiple
|
Breaks PyGILState_Ensure()") broke badly in the case of multiple
|
||||||
interpreter states; back out that fix and do a better job (see
|
interpreter states; back out that fix and do a better job (see
|
||||||
|
|
|
||||||
|
|
@ -1090,7 +1090,7 @@ long_format(PyObject *aa, int base, int addL)
|
||||||
assert(accumbits >= basebits);
|
assert(accumbits >= basebits);
|
||||||
do {
|
do {
|
||||||
char cdigit = (char)(accum & (base - 1));
|
char cdigit = (char)(accum & (base - 1));
|
||||||
cdigit += (cdigit < 10) ? '0' : 'A'-10;
|
cdigit += (cdigit < 10) ? '0' : 'a'-10;
|
||||||
assert(p > PyString_AS_STRING(str));
|
assert(p > PyString_AS_STRING(str));
|
||||||
*--p = cdigit;
|
*--p = cdigit;
|
||||||
accumbits -= basebits;
|
accumbits -= basebits;
|
||||||
|
|
@ -1144,7 +1144,7 @@ long_format(PyObject *aa, int base, int addL)
|
||||||
digit nextrem = (digit)(rem / base);
|
digit nextrem = (digit)(rem / base);
|
||||||
char c = (char)(rem - nextrem * base);
|
char c = (char)(rem - nextrem * base);
|
||||||
assert(p > PyString_AS_STRING(str));
|
assert(p > PyString_AS_STRING(str));
|
||||||
c += (c < 10) ? '0' : 'A'-10;
|
c += (c < 10) ? '0' : 'a'-10;
|
||||||
*--p = c;
|
*--p = c;
|
||||||
rem = nextrem;
|
rem = nextrem;
|
||||||
--ntostore;
|
--ntostore;
|
||||||
|
|
|
||||||
|
|
@ -3753,18 +3753,12 @@ _PyString_FormatLong(PyObject *val, int flags, int prec, int type,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fix up case for hex conversions. */
|
/* Fix up case for hex conversions. */
|
||||||
switch (type) {
|
if (type == 'X') {
|
||||||
case 'x':
|
/* Need to convert all lower case letters to upper case.
|
||||||
/* Need to convert all upper case letters to lower case. */
|
and need to convert 0x to 0X (and -0x to -0X). */
|
||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
||||||
if (buf[i] >= 'A' && buf[i] <= 'F')
|
if (buf[i] >= 'a' && buf[i] <= 'x')
|
||||||
buf[i] += 'a'-'A';
|
buf[i] -= 'a'-'A';
|
||||||
break;
|
|
||||||
case 'X':
|
|
||||||
/* Need to convert 0x to 0X (and -0x to -0X). */
|
|
||||||
if (buf[sign + 1] == 'x')
|
|
||||||
buf[sign + 1] = 'X';
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
*pbuf = buf;
|
*pbuf = buf;
|
||||||
*plen = len;
|
*plen = len;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue