Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
f5cff56a
Commit
f5cff56a
authored
Oct 14, 2011
by
Victor Stinner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #13088: Add shared Py_hexdigits constant to format a number into base 16
parent
e506437b
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
118 additions
and
135 deletions
+118
-135
Include/codecs.h
Include/codecs.h
+2
-0
Modules/_codecsmodule.c
Modules/_codecsmodule.c
+2
-3
Modules/_hashopenssl.c
Modules/_hashopenssl.c
+3
-5
Modules/_json.c
Modules/_json.c
+8
-8
Modules/_pickle.c
Modules/_pickle.c
+12
-13
Modules/binascii.c
Modules/binascii.c
+3
-5
Modules/md5module.c
Modules/md5module.c
+3
-5
Modules/sha1module.c
Modules/sha1module.c
+3
-5
Modules/sha256module.c
Modules/sha256module.c
+3
-5
Modules/sha512module.c
Modules/sha512module.c
+3
-5
Objects/bytearrayobject.c
Objects/bytearrayobject.c
+2
-3
Objects/bytesobject.c
Objects/bytesobject.c
+2
-3
Objects/floatobject.c
Objects/floatobject.c
+1
-1
Objects/unicodeobject.c
Objects/unicodeobject.c
+58
-60
Python/codecs.c
Python/codecs.c
+12
-12
Python/traceback.c
Python/traceback.c
+1
-2
No files found.
Include/codecs.h
View file @
f5cff56a
...
...
@@ -174,6 +174,8 @@ PyAPI_FUNC(PyObject *) PyCodec_XMLCharRefReplaceErrors(PyObject *exc);
/* replace the unicode encode error with backslash escapes (\x, \u and \U) */
PyAPI_FUNC
(
PyObject
*
)
PyCodec_BackslashReplaceErrors
(
PyObject
*
exc
);
extern
const
char
*
Py_hexdigits
;
#ifdef __cplusplus
}
#endif
...
...
Modules/_codecsmodule.c
View file @
f5cff56a
...
...
@@ -162,7 +162,6 @@ static PyObject *
escape_encode
(
PyObject
*
self
,
PyObject
*
args
)
{
static
const
char
*
hexdigits
=
"0123456789abcdef"
;
PyObject
*
str
;
Py_ssize_t
size
;
Py_ssize_t
newsize
;
...
...
@@ -205,8 +204,8 @@ escape_encode(PyObject *self,
else
if
(
c
<
' '
||
c
>=
0x7f
)
{
*
p
++
=
'\\'
;
*
p
++
=
'x'
;
*
p
++
=
hexdigits
[(
c
&
0xf0
)
>>
4
];
*
p
++
=
hexdigits
[
c
&
0xf
];
*
p
++
=
Py_
hexdigits
[(
c
&
0xf0
)
>>
4
];
*
p
++
=
Py_
hexdigits
[
c
&
0xf
];
}
else
*
p
++
=
c
;
...
...
Modules/_hashopenssl.c
View file @
f5cff56a
...
...
@@ -201,13 +201,11 @@ EVP_hexdigest(EVPobject *self, PyObject *unused)
/* Make hex version of the digest */
for
(
i
=
j
=
0
;
i
<
digest_size
;
i
++
)
{
char
c
;
unsigned
char
c
;
c
=
(
digest
[
i
]
>>
4
)
&
0xf
;
c
=
(
c
>
9
)
?
c
+
'a'
-
10
:
c
+
'0'
;
hex_digest
[
j
++
]
=
c
;
hex_digest
[
j
++
]
=
Py_hexdigits
[
c
];
c
=
(
digest
[
i
]
&
0xf
);
c
=
(
c
>
9
)
?
c
+
'a'
-
10
:
c
+
'0'
;
hex_digest
[
j
++
]
=
c
;
hex_digest
[
j
++
]
=
Py_hexdigits
[
c
];
}
retval
=
PyUnicode_FromStringAndSize
(
hex_digest
,
digest_size
*
2
);
PyMem_Free
(
hex_digest
);
...
...
Modules/_json.c
View file @
f5cff56a
...
...
@@ -175,18 +175,18 @@ ascii_escape_unichar(Py_UCS4 c, unsigned char *output, Py_ssize_t chars)
Py_UCS4
v
=
c
-
0x10000
;
c
=
0xd800
|
((
v
>>
10
)
&
0x3ff
);
output
[
chars
++
]
=
'u'
;
output
[
chars
++
]
=
"0123456789abcdef"
[(
c
>>
12
)
&
0xf
];
output
[
chars
++
]
=
"0123456789abcdef"
[(
c
>>
8
)
&
0xf
];
output
[
chars
++
]
=
"0123456789abcdef"
[(
c
>>
4
)
&
0xf
];
output
[
chars
++
]
=
"0123456789abcdef"
[(
c
)
&
0xf
];
output
[
chars
++
]
=
Py_hexdigits
[(
c
>>
12
)
&
0xf
];
output
[
chars
++
]
=
Py_hexdigits
[(
c
>>
8
)
&
0xf
];
output
[
chars
++
]
=
Py_hexdigits
[(
c
>>
4
)
&
0xf
];
output
[
chars
++
]
=
Py_hexdigits
[(
c
)
&
0xf
];
c
=
0xdc00
|
(
v
&
0x3ff
);
output
[
chars
++
]
=
'\\'
;
}
output
[
chars
++
]
=
'u'
;
output
[
chars
++
]
=
"0123456789abcdef"
[(
c
>>
12
)
&
0xf
];
output
[
chars
++
]
=
"0123456789abcdef"
[(
c
>>
8
)
&
0xf
];
output
[
chars
++
]
=
"0123456789abcdef"
[(
c
>>
4
)
&
0xf
];
output
[
chars
++
]
=
"0123456789abcdef"
[(
c
)
&
0xf
];
output
[
chars
++
]
=
Py_hexdigits
[(
c
>>
12
)
&
0xf
];
output
[
chars
++
]
=
Py_hexdigits
[(
c
>>
8
)
&
0xf
];
output
[
chars
++
]
=
Py_hexdigits
[(
c
>>
4
)
&
0xf
];
output
[
chars
++
]
=
Py_hexdigits
[(
c
)
&
0xf
];
}
return
chars
;
}
...
...
Modules/_pickle.c
View file @
f5cff56a
...
...
@@ -1776,7 +1776,6 @@ save_bytes(PicklerObject *self, PyObject *obj)
static
PyObject
*
raw_unicode_escape
(
PyObject
*
obj
)
{
static
const
char
*
hexdigits
=
"0123456789abcdef"
;
PyObject
*
repr
,
*
result
;
char
*
p
;
Py_ssize_t
i
,
size
,
expandsize
;
...
...
@@ -1809,23 +1808,23 @@ raw_unicode_escape(PyObject *obj)
if
(
ch
>=
0x10000
)
{
*
p
++
=
'\\'
;
*
p
++
=
'U'
;
*
p
++
=
hexdigits
[(
ch
>>
28
)
&
0xf
];
*
p
++
=
hexdigits
[(
ch
>>
24
)
&
0xf
];
*
p
++
=
hexdigits
[(
ch
>>
20
)
&
0xf
];
*
p
++
=
hexdigits
[(
ch
>>
16
)
&
0xf
];
*
p
++
=
hexdigits
[(
ch
>>
12
)
&
0xf
];
*
p
++
=
hexdigits
[(
ch
>>
8
)
&
0xf
];
*
p
++
=
hexdigits
[(
ch
>>
4
)
&
0xf
];
*
p
++
=
hexdigits
[
ch
&
15
];
*
p
++
=
Py_
hexdigits
[(
ch
>>
28
)
&
0xf
];
*
p
++
=
Py_
hexdigits
[(
ch
>>
24
)
&
0xf
];
*
p
++
=
Py_
hexdigits
[(
ch
>>
20
)
&
0xf
];
*
p
++
=
Py_
hexdigits
[(
ch
>>
16
)
&
0xf
];
*
p
++
=
Py_
hexdigits
[(
ch
>>
12
)
&
0xf
];
*
p
++
=
Py_
hexdigits
[(
ch
>>
8
)
&
0xf
];
*
p
++
=
Py_
hexdigits
[(
ch
>>
4
)
&
0xf
];
*
p
++
=
Py_
hexdigits
[
ch
&
15
];
}
/* Map 16-bit characters to '\uxxxx' */
else
if
(
ch
>=
256
||
ch
==
'\\'
||
ch
==
'\n'
)
{
*
p
++
=
'\\'
;
*
p
++
=
'u'
;
*
p
++
=
hexdigits
[(
ch
>>
12
)
&
0xf
];
*
p
++
=
hexdigits
[(
ch
>>
8
)
&
0xf
];
*
p
++
=
hexdigits
[(
ch
>>
4
)
&
0xf
];
*
p
++
=
hexdigits
[
ch
&
15
];
*
p
++
=
Py_
hexdigits
[(
ch
>>
12
)
&
0xf
];
*
p
++
=
Py_
hexdigits
[(
ch
>>
8
)
&
0xf
];
*
p
++
=
Py_
hexdigits
[(
ch
>>
4
)
&
0xf
];
*
p
++
=
Py_
hexdigits
[
ch
&
15
];
}
/* Copy everything else as-is */
else
...
...
Modules/binascii.c
View file @
f5cff56a
...
...
@@ -1078,13 +1078,11 @@ binascii_hexlify(PyObject *self, PyObject *args)
/* make hex version of string, taken from shamodule.c */
for
(
i
=
j
=
0
;
i
<
arglen
;
i
++
)
{
char
c
;
unsigned
char
c
;
c
=
(
argbuf
[
i
]
>>
4
)
&
0xf
;
c
=
(
c
>
9
)
?
c
+
'a'
-
10
:
c
+
'0'
;
retbuf
[
j
++
]
=
c
;
retbuf
[
j
++
]
=
Py_hexdigits
[
c
];
c
=
argbuf
[
i
]
&
0xf
;
c
=
(
c
>
9
)
?
c
+
'a'
-
10
:
c
+
'0'
;
retbuf
[
j
++
]
=
c
;
retbuf
[
j
++
]
=
Py_hexdigits
[
c
];
}
PyBuffer_Release
(
&
parg
);
return
retval
;
...
...
Modules/md5module.c
View file @
f5cff56a
...
...
@@ -391,13 +391,11 @@ MD5_hexdigest(MD5object *self, PyObject *unused)
/* Make hex version of the digest */
for
(
i
=
j
=
0
;
i
<
MD5_DIGESTSIZE
;
i
++
)
{
char
c
;
unsigned
char
c
;
c
=
(
digest
[
i
]
>>
4
)
&
0xf
;
c
=
(
c
>
9
)
?
c
+
'a'
-
10
:
c
+
'0'
;
hex_digest
[
j
++
]
=
c
;
hex_digest
[
j
++
]
=
Py_hexdigits
[
c
];
c
=
(
digest
[
i
]
&
0xf
);
c
=
(
c
>
9
)
?
c
+
'a'
-
10
:
c
+
'0'
;
hex_digest
[
j
++
]
=
c
;
hex_digest
[
j
++
]
=
Py_hexdigits
[
c
];
}
return
retval
;
}
...
...
Modules/sha1module.c
View file @
f5cff56a
...
...
@@ -367,13 +367,11 @@ SHA1_hexdigest(SHA1object *self, PyObject *unused)
/* Make hex version of the digest */
for
(
i
=
j
=
0
;
i
<
SHA1_DIGESTSIZE
;
i
++
)
{
char
c
;
unsigned
char
c
;
c
=
(
digest
[
i
]
>>
4
)
&
0xf
;
c
=
(
c
>
9
)
?
c
+
'a'
-
10
:
c
+
'0'
;
hex_digest
[
j
++
]
=
c
;
hex_digest
[
j
++
]
=
Py_hexdigits
[
c
];
c
=
(
digest
[
i
]
&
0xf
);
c
=
(
c
>
9
)
?
c
+
'a'
-
10
:
c
+
'0'
;
hex_digest
[
j
++
]
=
c
;
hex_digest
[
j
++
]
=
Py_hexdigits
[
c
];
}
return
retval
;
}
...
...
Modules/sha256module.c
View file @
f5cff56a
...
...
@@ -460,13 +460,11 @@ SHA256_hexdigest(SHAobject *self, PyObject *unused)
/* Make hex version of the digest */
for
(
i
=
j
=
0
;
i
<
self
->
digestsize
;
i
++
)
{
char
c
;
unsigned
char
c
;
c
=
(
digest
[
i
]
>>
4
)
&
0xf
;
c
=
(
c
>
9
)
?
c
+
'a'
-
10
:
c
+
'0'
;
hex_digest
[
j
++
]
=
c
;
hex_digest
[
j
++
]
=
Py_hexdigits
[
c
];
c
=
(
digest
[
i
]
&
0xf
);
c
=
(
c
>
9
)
?
c
+
'a'
-
10
:
c
+
'0'
;
hex_digest
[
j
++
]
=
c
;
hex_digest
[
j
++
]
=
Py_hexdigits
[
c
];
}
return
retval
;
}
...
...
Modules/sha512module.c
View file @
f5cff56a
...
...
@@ -526,13 +526,11 @@ SHA512_hexdigest(SHAobject *self, PyObject *unused)
/* Make hex version of the digest */
for
(
i
=
j
=
0
;
i
<
self
->
digestsize
;
i
++
)
{
char
c
;
unsigned
char
c
;
c
=
(
digest
[
i
]
>>
4
)
&
0xf
;
c
=
(
c
>
9
)
?
c
+
'a'
-
10
:
c
+
'0'
;
hex_digest
[
j
++
]
=
c
;
hex_digest
[
j
++
]
=
Py_hexdigits
[
c
];
c
=
(
digest
[
i
]
&
0xf
);
c
=
(
c
>
9
)
?
c
+
'a'
-
10
:
c
+
'0'
;
hex_digest
[
j
++
]
=
c
;
hex_digest
[
j
++
]
=
Py_hexdigits
[
c
];
}
return
retval
;
}
...
...
Objects/bytearrayobject.c
View file @
f5cff56a
...
...
@@ -850,7 +850,6 @@ bytearray_init(PyByteArrayObject *self, PyObject *args, PyObject *kwds)
static
PyObject
*
bytearray_repr
(
PyByteArrayObject
*
self
)
{
static
const
char
*
hexdigits
=
"0123456789abcdef"
;
const
char
*
quote_prefix
=
"bytearray(b"
;
const
char
*
quote_postfix
=
")"
;
Py_ssize_t
length
=
Py_SIZE
(
self
);
...
...
@@ -912,8 +911,8 @@ bytearray_repr(PyByteArrayObject *self)
else
if
(
c
<
' '
||
c
>=
0x7f
)
{
*
p
++
=
'\\'
;
*
p
++
=
'x'
;
*
p
++
=
hexdigits
[(
c
&
0xf0
)
>>
4
];
*
p
++
=
hexdigits
[
c
&
0xf
];
*
p
++
=
Py_
hexdigits
[(
c
&
0xf0
)
>>
4
];
*
p
++
=
Py_
hexdigits
[
c
&
0xf
];
}
else
*
p
++
=
c
;
...
...
Objects/bytesobject.c
View file @
f5cff56a
...
...
@@ -564,7 +564,6 @@ PyBytes_AsStringAndSize(register PyObject *obj,
PyObject
*
PyBytes_Repr
(
PyObject
*
obj
,
int
smartquotes
)
{
static
const
char
*
hexdigits
=
"0123456789abcdef"
;
register
PyBytesObject
*
op
=
(
PyBytesObject
*
)
obj
;
Py_ssize_t
i
,
length
=
Py_SIZE
(
op
);
size_t
newsize
,
squotes
,
dquotes
;
...
...
@@ -620,8 +619,8 @@ PyBytes_Repr(PyObject *obj, int smartquotes)
else
if
(
c
<
' '
||
c
>=
0x7f
)
{
*
p
++
=
'\\'
;
*
p
++
=
'x'
;
*
p
++
=
hexdigits
[(
c
&
0xf0
)
>>
4
];
*
p
++
=
hexdigits
[
c
&
0xf
];
*
p
++
=
Py_
hexdigits
[(
c
&
0xf0
)
>>
4
];
*
p
++
=
Py_
hexdigits
[
c
&
0xf
];
}
else
*
p
++
=
c
;
...
...
Objects/floatobject.c
View file @
f5cff56a
...
...
@@ -1058,7 +1058,7 @@ static char
char_from_hex
(
int
x
)
{
assert
(
0
<=
x
&&
x
<
16
);
return
"0123456789abcdef"
[
x
];
return
Py_hexdigits
[
x
];
}
static
int
...
...
Objects/unicodeobject.c
View file @
f5cff56a
...
...
@@ -5943,8 +5943,6 @@ PyUnicode_DecodeUnicodeEscape(const char *s,
*/
static
const
char
*
hexdigits
=
"0123456789abcdef"
;
PyObject
*
PyUnicode_EncodeUnicodeEscape
(
const
Py_UNICODE
*
s
,
Py_ssize_t
size
)
...
...
@@ -6006,14 +6004,14 @@ PyUnicode_EncodeUnicodeEscape(const Py_UNICODE *s,
else
if
(
ch
>=
0x10000
)
{
*
p
++
=
'\\'
;
*
p
++
=
'U'
;
*
p
++
=
hexdigits
[(
ch
>>
28
)
&
0x0000000F
];
*
p
++
=
hexdigits
[(
ch
>>
24
)
&
0x0000000F
];
*
p
++
=
hexdigits
[(
ch
>>
20
)
&
0x0000000F
];
*
p
++
=
hexdigits
[(
ch
>>
16
)
&
0x0000000F
];
*
p
++
=
hexdigits
[(
ch
>>
12
)
&
0x0000000F
];
*
p
++
=
hexdigits
[(
ch
>>
8
)
&
0x0000000F
];
*
p
++
=
hexdigits
[(
ch
>>
4
)
&
0x0000000F
];
*
p
++
=
hexdigits
[
ch
&
0x0000000F
];
*
p
++
=
Py_
hexdigits
[(
ch
>>
28
)
&
0x0000000F
];
*
p
++
=
Py_
hexdigits
[(
ch
>>
24
)
&
0x0000000F
];
*
p
++
=
Py_
hexdigits
[(
ch
>>
20
)
&
0x0000000F
];
*
p
++
=
Py_
hexdigits
[(
ch
>>
16
)
&
0x0000000F
];
*
p
++
=
Py_
hexdigits
[(
ch
>>
12
)
&
0x0000000F
];
*
p
++
=
Py_
hexdigits
[(
ch
>>
8
)
&
0x0000000F
];
*
p
++
=
Py_
hexdigits
[(
ch
>>
4
)
&
0x0000000F
];
*
p
++
=
Py_
hexdigits
[
ch
&
0x0000000F
];
continue
;
}
#else
...
...
@@ -6028,14 +6026,14 @@ PyUnicode_EncodeUnicodeEscape(const Py_UNICODE *s,
ucs
=
(((
ch
&
0x03FF
)
<<
10
)
|
(
ch2
&
0x03FF
))
+
0x00010000
;
*
p
++
=
'\\'
;
*
p
++
=
'U'
;
*
p
++
=
hexdigits
[(
ucs
>>
28
)
&
0x0000000F
];
*
p
++
=
hexdigits
[(
ucs
>>
24
)
&
0x0000000F
];
*
p
++
=
hexdigits
[(
ucs
>>
20
)
&
0x0000000F
];
*
p
++
=
hexdigits
[(
ucs
>>
16
)
&
0x0000000F
];
*
p
++
=
hexdigits
[(
ucs
>>
12
)
&
0x0000000F
];
*
p
++
=
hexdigits
[(
ucs
>>
8
)
&
0x0000000F
];
*
p
++
=
hexdigits
[(
ucs
>>
4
)
&
0x0000000F
];
*
p
++
=
hexdigits
[
ucs
&
0x0000000F
];
*
p
++
=
Py_
hexdigits
[(
ucs
>>
28
)
&
0x0000000F
];
*
p
++
=
Py_
hexdigits
[(
ucs
>>
24
)
&
0x0000000F
];
*
p
++
=
Py_
hexdigits
[(
ucs
>>
20
)
&
0x0000000F
];
*
p
++
=
Py_
hexdigits
[(
ucs
>>
16
)
&
0x0000000F
];
*
p
++
=
Py_
hexdigits
[(
ucs
>>
12
)
&
0x0000000F
];
*
p
++
=
Py_
hexdigits
[(
ucs
>>
8
)
&
0x0000000F
];
*
p
++
=
Py_
hexdigits
[(
ucs
>>
4
)
&
0x0000000F
];
*
p
++
=
Py_
hexdigits
[
ucs
&
0x0000000F
];
continue
;
}
/* Fall through: isolated surrogates are copied as-is */
...
...
@@ -6048,10 +6046,10 @@ PyUnicode_EncodeUnicodeEscape(const Py_UNICODE *s,
if
(
ch
>=
256
)
{
*
p
++
=
'\\'
;
*
p
++
=
'u'
;
*
p
++
=
hexdigits
[(
ch
>>
12
)
&
0x000F
];
*
p
++
=
hexdigits
[(
ch
>>
8
)
&
0x000F
];
*
p
++
=
hexdigits
[(
ch
>>
4
)
&
0x000F
];
*
p
++
=
hexdigits
[
ch
&
0x000F
];
*
p
++
=
Py_
hexdigits
[(
ch
>>
12
)
&
0x000F
];
*
p
++
=
Py_
hexdigits
[(
ch
>>
8
)
&
0x000F
];
*
p
++
=
Py_
hexdigits
[(
ch
>>
4
)
&
0x000F
];
*
p
++
=
Py_
hexdigits
[
ch
&
0x000F
];
}
/* Map special whitespace to '\t', \n', '\r' */
...
...
@@ -6072,8 +6070,8 @@ PyUnicode_EncodeUnicodeEscape(const Py_UNICODE *s,
else
if
(
ch
<
' '
||
ch
>=
0x7F
)
{
*
p
++
=
'\\'
;
*
p
++
=
'x'
;
*
p
++
=
hexdigits
[(
ch
>>
4
)
&
0x000F
];
*
p
++
=
hexdigits
[
ch
&
0x000F
];
*
p
++
=
Py_
hexdigits
[(
ch
>>
4
)
&
0x000F
];
*
p
++
=
Py_
hexdigits
[
ch
&
0x000F
];
}
/* Copy everything else as-is */
...
...
@@ -6258,14 +6256,14 @@ PyUnicode_EncodeRawUnicodeEscape(const Py_UNICODE *s,
if
(
ch
>=
0x10000
)
{
*
p
++
=
'\\'
;
*
p
++
=
'U'
;
*
p
++
=
hexdigits
[(
ch
>>
28
)
&
0xf
];
*
p
++
=
hexdigits
[(
ch
>>
24
)
&
0xf
];
*
p
++
=
hexdigits
[(
ch
>>
20
)
&
0xf
];
*
p
++
=
hexdigits
[(
ch
>>
16
)
&
0xf
];
*
p
++
=
hexdigits
[(
ch
>>
12
)
&
0xf
];
*
p
++
=
hexdigits
[(
ch
>>
8
)
&
0xf
];
*
p
++
=
hexdigits
[(
ch
>>
4
)
&
0xf
];
*
p
++
=
hexdigits
[
ch
&
15
];
*
p
++
=
Py_
hexdigits
[(
ch
>>
28
)
&
0xf
];
*
p
++
=
Py_
hexdigits
[(
ch
>>
24
)
&
0xf
];
*
p
++
=
Py_
hexdigits
[(
ch
>>
20
)
&
0xf
];
*
p
++
=
Py_
hexdigits
[(
ch
>>
16
)
&
0xf
];
*
p
++
=
Py_
hexdigits
[(
ch
>>
12
)
&
0xf
];
*
p
++
=
Py_
hexdigits
[(
ch
>>
8
)
&
0xf
];
*
p
++
=
Py_
hexdigits
[(
ch
>>
4
)
&
0xf
];
*
p
++
=
Py_
hexdigits
[
ch
&
15
];
}
else
#else
...
...
@@ -6280,14 +6278,14 @@ PyUnicode_EncodeRawUnicodeEscape(const Py_UNICODE *s,
ucs
=
(((
ch
&
0x03FF
)
<<
10
)
|
(
ch2
&
0x03FF
))
+
0x00010000
;
*
p
++
=
'\\'
;
*
p
++
=
'U'
;
*
p
++
=
hexdigits
[(
ucs
>>
28
)
&
0xf
];
*
p
++
=
hexdigits
[(
ucs
>>
24
)
&
0xf
];
*
p
++
=
hexdigits
[(
ucs
>>
20
)
&
0xf
];
*
p
++
=
hexdigits
[(
ucs
>>
16
)
&
0xf
];
*
p
++
=
hexdigits
[(
ucs
>>
12
)
&
0xf
];
*
p
++
=
hexdigits
[(
ucs
>>
8
)
&
0xf
];
*
p
++
=
hexdigits
[(
ucs
>>
4
)
&
0xf
];
*
p
++
=
hexdigits
[
ucs
&
0xf
];
*
p
++
=
Py_
hexdigits
[(
ucs
>>
28
)
&
0xf
];
*
p
++
=
Py_
hexdigits
[(
ucs
>>
24
)
&
0xf
];
*
p
++
=
Py_
hexdigits
[(
ucs
>>
20
)
&
0xf
];
*
p
++
=
Py_
hexdigits
[(
ucs
>>
16
)
&
0xf
];
*
p
++
=
Py_
hexdigits
[(
ucs
>>
12
)
&
0xf
];
*
p
++
=
Py_
hexdigits
[(
ucs
>>
8
)
&
0xf
];
*
p
++
=
Py_
hexdigits
[(
ucs
>>
4
)
&
0xf
];
*
p
++
=
Py_
hexdigits
[
ucs
&
0xf
];
continue
;
}
/* Fall through: isolated surrogates are copied as-is */
...
...
@@ -6299,10 +6297,10 @@ PyUnicode_EncodeRawUnicodeEscape(const Py_UNICODE *s,
if
(
ch
>=
256
)
{
*
p
++
=
'\\'
;
*
p
++
=
'u'
;
*
p
++
=
hexdigits
[(
ch
>>
12
)
&
0xf
];
*
p
++
=
hexdigits
[(
ch
>>
8
)
&
0xf
];
*
p
++
=
hexdigits
[(
ch
>>
4
)
&
0xf
];
*
p
++
=
hexdigits
[
ch
&
15
];
*
p
++
=
Py_
hexdigits
[(
ch
>>
12
)
&
0xf
];
*
p
++
=
Py_
hexdigits
[(
ch
>>
8
)
&
0xf
];
*
p
++
=
Py_
hexdigits
[(
ch
>>
4
)
&
0xf
];
*
p
++
=
Py_
hexdigits
[
ch
&
15
];
}
/* Copy everything else as-is */
else
...
...
@@ -11648,8 +11646,8 @@ unicode_repr(PyObject *unicode)
else
if
(
ch
<
' '
||
ch
==
0x7F
)
{
PyUnicode_WRITE
(
okind
,
odata
,
o
++
,
'\\'
);
PyUnicode_WRITE
(
okind
,
odata
,
o
++
,
'x'
);
PyUnicode_WRITE
(
okind
,
odata
,
o
++
,
hexdigits
[(
ch
>>
4
)
&
0x000F
]);
PyUnicode_WRITE
(
okind
,
odata
,
o
++
,
hexdigits
[
ch
&
0x000F
]);
PyUnicode_WRITE
(
okind
,
odata
,
o
++
,
Py_
hexdigits
[(
ch
>>
4
)
&
0x000F
]);
PyUnicode_WRITE
(
okind
,
odata
,
o
++
,
Py_
hexdigits
[
ch
&
0x000F
]);
}
/* Copy ASCII characters as-is */
...
...
@@ -11667,30 +11665,30 @@ unicode_repr(PyObject *unicode)
if
(
ch
<=
0xff
)
{
PyUnicode_WRITE
(
okind
,
odata
,
o
++
,
'\\'
);
PyUnicode_WRITE
(
okind
,
odata
,
o
++
,
'x'
);
PyUnicode_WRITE
(
okind
,
odata
,
o
++
,
hexdigits
[(
ch
>>
4
)
&
0x000F
]);
PyUnicode_WRITE
(
okind
,
odata
,
o
++
,
hexdigits
[
ch
&
0x000F
]);
PyUnicode_WRITE
(
okind
,
odata
,
o
++
,
Py_
hexdigits
[(
ch
>>
4
)
&
0x000F
]);
PyUnicode_WRITE
(
okind
,
odata
,
o
++
,
Py_
hexdigits
[
ch
&
0x000F
]);
}
/* Map 21-bit characters to '\U00xxxxxx' */
else
if
(
ch
>=
0x10000
)
{
PyUnicode_WRITE
(
okind
,
odata
,
o
++
,
'\\'
);
PyUnicode_WRITE
(
okind
,
odata
,
o
++
,
'U'
);
PyUnicode_WRITE
(
okind
,
odata
,
o
++
,
hexdigits
[(
ch
>>
28
)
&
0xF
]);
PyUnicode_WRITE
(
okind
,
odata
,
o
++
,
hexdigits
[(
ch
>>
24
)
&
0xF
]);
PyUnicode_WRITE
(
okind
,
odata
,
o
++
,
hexdigits
[(
ch
>>
20
)
&
0xF
]);
PyUnicode_WRITE
(
okind
,
odata
,
o
++
,
hexdigits
[(
ch
>>
16
)
&
0xF
]);
PyUnicode_WRITE
(
okind
,
odata
,
o
++
,
hexdigits
[(
ch
>>
12
)
&
0xF
]);
PyUnicode_WRITE
(
okind
,
odata
,
o
++
,
hexdigits
[(
ch
>>
8
)
&
0xF
]);
PyUnicode_WRITE
(
okind
,
odata
,
o
++
,
hexdigits
[(
ch
>>
4
)
&
0xF
]);
PyUnicode_WRITE
(
okind
,
odata
,
o
++
,
hexdigits
[
ch
&
0xF
]);
PyUnicode_WRITE
(
okind
,
odata
,
o
++
,
Py_
hexdigits
[(
ch
>>
28
)
&
0xF
]);
PyUnicode_WRITE
(
okind
,
odata
,
o
++
,
Py_
hexdigits
[(
ch
>>
24
)
&
0xF
]);
PyUnicode_WRITE
(
okind
,
odata
,
o
++
,
Py_
hexdigits
[(
ch
>>
20
)
&
0xF
]);
PyUnicode_WRITE
(
okind
,
odata
,
o
++
,
Py_
hexdigits
[(
ch
>>
16
)
&
0xF
]);
PyUnicode_WRITE
(
okind
,
odata
,
o
++
,
Py_
hexdigits
[(
ch
>>
12
)
&
0xF
]);
PyUnicode_WRITE
(
okind
,
odata
,
o
++
,
Py_
hexdigits
[(
ch
>>
8
)
&
0xF
]);
PyUnicode_WRITE
(
okind
,
odata
,
o
++
,
Py_
hexdigits
[(
ch
>>
4
)
&
0xF
]);
PyUnicode_WRITE
(
okind
,
odata
,
o
++
,
Py_
hexdigits
[
ch
&
0xF
]);
}
/* Map 16-bit characters to '\uxxxx' */
else
{
PyUnicode_WRITE
(
okind
,
odata
,
o
++
,
'\\'
);
PyUnicode_WRITE
(
okind
,
odata
,
o
++
,
'u'
);
PyUnicode_WRITE
(
okind
,
odata
,
o
++
,
hexdigits
[(
ch
>>
12
)
&
0xF
]);
PyUnicode_WRITE
(
okind
,
odata
,
o
++
,
hexdigits
[(
ch
>>
8
)
&
0xF
]);
PyUnicode_WRITE
(
okind
,
odata
,
o
++
,
hexdigits
[(
ch
>>
4
)
&
0xF
]);
PyUnicode_WRITE
(
okind
,
odata
,
o
++
,
hexdigits
[
ch
&
0xF
]);
PyUnicode_WRITE
(
okind
,
odata
,
o
++
,
Py_
hexdigits
[(
ch
>>
12
)
&
0xF
]);
PyUnicode_WRITE
(
okind
,
odata
,
o
++
,
Py_
hexdigits
[(
ch
>>
8
)
&
0xF
]);
PyUnicode_WRITE
(
okind
,
odata
,
o
++
,
Py_
hexdigits
[(
ch
>>
4
)
&
0xF
]);
PyUnicode_WRITE
(
okind
,
odata
,
o
++
,
Py_
hexdigits
[
ch
&
0xF
]);
}
}
/* Copy characters as-is */
...
...
Python/codecs.c
View file @
f5cff56a
...
...
@@ -11,6 +11,8 @@ Copyright (c) Corporation for National Research Initiatives.
#include "Python.h"
#include <ctype.h>
const
char
*
Py_hexdigits
=
"0123456789abcdef"
;
/* --- Codec Registry ----------------------------------------------------- */
/* Import the standard encodings package which will register the first
...
...
@@ -673,8 +675,6 @@ PyObject *PyCodec_XMLCharRefReplaceErrors(PyObject *exc)
}
}
static
const
char
*
hexdigits
=
"0123456789abcdef"
;
PyObject
*
PyCodec_BackslashReplaceErrors
(
PyObject
*
exc
)
{
#ifndef Py_UNICODE_WIDE
...
...
@@ -731,22 +731,22 @@ PyObject *PyCodec_BackslashReplaceErrors(PyObject *exc)
}
if
(
c
>=
0x00010000
)
{
*
outp
++
=
'U'
;
*
outp
++
=
hexdigits
[(
c
>>
28
)
&
0xf
];
*
outp
++
=
hexdigits
[(
c
>>
24
)
&
0xf
];
*
outp
++
=
hexdigits
[(
c
>>
20
)
&
0xf
];
*
outp
++
=
hexdigits
[(
c
>>
16
)
&
0xf
];
*
outp
++
=
hexdigits
[(
c
>>
12
)
&
0xf
];
*
outp
++
=
hexdigits
[(
c
>>
8
)
&
0xf
];
*
outp
++
=
Py_
hexdigits
[(
c
>>
28
)
&
0xf
];
*
outp
++
=
Py_
hexdigits
[(
c
>>
24
)
&
0xf
];
*
outp
++
=
Py_
hexdigits
[(
c
>>
20
)
&
0xf
];
*
outp
++
=
Py_
hexdigits
[(
c
>>
16
)
&
0xf
];
*
outp
++
=
Py_
hexdigits
[(
c
>>
12
)
&
0xf
];
*
outp
++
=
Py_
hexdigits
[(
c
>>
8
)
&
0xf
];
}
else
if
(
c
>=
0x100
)
{
*
outp
++
=
'u'
;
*
outp
++
=
hexdigits
[(
c
>>
12
)
&
0xf
];
*
outp
++
=
hexdigits
[(
c
>>
8
)
&
0xf
];
*
outp
++
=
Py_
hexdigits
[(
c
>>
12
)
&
0xf
];
*
outp
++
=
Py_
hexdigits
[(
c
>>
8
)
&
0xf
];
}
else
*
outp
++
=
'x'
;
*
outp
++
=
hexdigits
[(
c
>>
4
)
&
0xf
];
*
outp
++
=
hexdigits
[
c
&
0xf
];
*
outp
++
=
Py_
hexdigits
[(
c
>>
4
)
&
0xf
];
*
outp
++
=
Py_
hexdigits
[
c
&
0xf
];
}
restuple
=
Py_BuildValue
(
"(On)"
,
res
,
end
);
...
...
Python/traceback.c
View file @
f5cff56a
...
...
@@ -463,12 +463,11 @@ dump_decimal(int fd, int value)
static
void
dump_hexadecimal
(
int
width
,
unsigned
long
value
,
int
fd
)
{
const
char
*
hexdigits
=
"0123456789abcdef"
;
int
len
;
char
buffer
[
sizeof
(
unsigned
long
)
*
2
+
1
];
len
=
0
;
do
{
buffer
[
len
]
=
hexdigits
[
value
&
15
];
buffer
[
len
]
=
Py_
hexdigits
[
value
&
15
];
value
>>=
4
;
len
++
;
}
while
(
len
<
width
||
value
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment