mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
Merged revisions 75931 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r75931 | benjamin.peterson | 2009-10-28 20:49:07 -0500 (Wed, 28 Oct 2009) | 5 lines do a backport of r75928 The added test does not fail without the patch, but we still fix the issue of surrogates being used in wide builds where they should not be. ........
This commit is contained in:
parent
e7228d3e01
commit
c717aec772
2 changed files with 49 additions and 39 deletions
|
@ -1,4 +1,4 @@
|
||||||
#! -*- coding: koi8-r -*-
|
# -*- coding: koi8-r -*-
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
from test import test_support
|
from test import test_support
|
||||||
|
@ -23,6 +23,13 @@ class PEP263Test(unittest.TestCase):
|
||||||
self.assertEqual(d['u'], u'\xf3')
|
self.assertEqual(d['u'], u'\xf3')
|
||||||
|
|
||||||
|
|
||||||
|
def test_issue3297(self):
|
||||||
|
c = compile("a, b = '\U0001010F', '\\U0001010F'", "dummy", "exec")
|
||||||
|
d = {}
|
||||||
|
exec(c, d)
|
||||||
|
self.assertEqual(d['a'], d['b'])
|
||||||
|
self.assertEqual(len(d['a']), len(d['b']))
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
test_support.run_unittest(PEP263Test)
|
test_support.run_unittest(PEP263Test)
|
||||||
|
|
||||||
|
|
21
Python/ast.c
21
Python/ast.c
|
@ -3248,10 +3248,11 @@ decode_unicode(struct compiling *c, const char *s, size_t len, int rawmode, cons
|
||||||
u = NULL;
|
u = NULL;
|
||||||
} else {
|
} else {
|
||||||
/* check for integer overflow */
|
/* check for integer overflow */
|
||||||
if (len > PY_SIZE_MAX / 4)
|
if (len > PY_SIZE_MAX / 6)
|
||||||
return NULL;
|
return NULL;
|
||||||
/* "\XX" may become "\u005c\uHHLL" (12 bytes) */
|
/* "<C3><A4>" (2 bytes) may become "\U000000E4" (10 bytes), or 1:5
|
||||||
u = PyString_FromStringAndSize((char *)NULL, len * 4);
|
"\ä" (3 bytes) may become "\u005c\U000000E4" (16 bytes), or ~1:6 */
|
||||||
|
u = PyString_FromStringAndSize((char *)NULL, len * 6);
|
||||||
if (u == NULL)
|
if (u == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
p = buf = PyString_AsString(u);
|
p = buf = PyString_AsString(u);
|
||||||
|
@ -3268,19 +3269,21 @@ decode_unicode(struct compiling *c, const char *s, size_t len, int rawmode, cons
|
||||||
PyObject *w;
|
PyObject *w;
|
||||||
char *r;
|
char *r;
|
||||||
Py_ssize_t rn, i;
|
Py_ssize_t rn, i;
|
||||||
w = decode_utf8(c, &s, end, "utf-16-be");
|
w = decode_utf8(c, &s, end, "utf-32-be");
|
||||||
if (w == NULL) {
|
if (w == NULL) {
|
||||||
Py_DECREF(u);
|
Py_DECREF(u);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
r = PyString_AsString(w);
|
r = PyString_AsString(w);
|
||||||
rn = PyString_Size(w);
|
rn = PyString_Size(w);
|
||||||
assert(rn % 2 == 0);
|
assert(rn % 4 == 0);
|
||||||
for (i = 0; i < rn; i += 2) {
|
for (i = 0; i < rn; i += 4) {
|
||||||
sprintf(p, "\\u%02x%02x",
|
sprintf(p, "\\U%02x%02x%02x%02x",
|
||||||
r[i + 0] & 0xFF,
|
r[i + 0] & 0xFF,
|
||||||
r[i + 1] & 0xFF);
|
r[i + 1] & 0xFF,
|
||||||
p += 6;
|
r[i + 2] & 0xFF,
|
||||||
|
r[i + 3] & 0xFF);
|
||||||
|
p += 10;
|
||||||
}
|
}
|
||||||
Py_DECREF(w);
|
Py_DECREF(w);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue