Author: Ronan Lamy <[email protected]>
Branch: py3.5
Changeset: r92416:ffe904e9ac64
Date: 2017-09-18 19:08 +0100
http://bitbucket.org/pypy/pypy/changeset/ffe904e9ac64/
Log: Correctly initialize data in 4BYTE case of _PyUnicode_Ready(), and
fix test to behave the same whether translated or not
diff --git a/pypy/module/cpyext/test/test_unicodeobject.py
b/pypy/module/cpyext/test/test_unicodeobject.py
--- a/pypy/module/cpyext/test/test_unicodeobject.py
+++ b/pypy/module/cpyext/test/test_unicodeobject.py
@@ -199,16 +199,21 @@
if (!PyArg_ParseTuple(args, "On", &text, &start))
return NULL;
if (PyUnicode_READY(text) == -1) return NULL;
+ if (!PyUnicode_1BYTE_DATA(text)) {
+ // Don't segfault, just fail the test.
+ Py_RETURN_NONE;
+ }
length = PyUnicode_GET_LENGTH(text);
if (start > length) return PyLong_FromSsize_t(start);
return PyUnicode_FromKindAndData(PyUnicode_KIND(text),
PyUnicode_1BYTE_DATA(text) + start*PyUnicode_KIND(text),
length-start);
''')])
- s = 'aАbБcСdД'
+ s = u'aАbБcСdД'
assert module.slice_start(s, 2) == 'bБcСdД'
- s = 'xx\N{PILE OF POO}'
- assert module.slice_start(s, 2) == '\N{PILE OF POO}'
+ # s = u'xx\N{PILE OF POO}'
+ s = u'xx\U0001F4A9'
+ assert module.slice_start(s, 2) == u'\U0001F4A9'
def test_aswidecharstring(self):
module = self.import_extension('foo', [
diff --git a/pypy/module/cpyext/unicodeobject.py
b/pypy/module/cpyext/unicodeobject.py
--- a/pypy/module/cpyext/unicodeobject.py
+++ b/pypy/module/cpyext/unicodeobject.py
@@ -300,6 +300,11 @@
set_utf8_len(py_obj, 0)
else:
# XXX: assumes that sizeof(wchar_t) == 4
+ if not get_wbuffer(py_obj):
+ # Copy unicode buffer
+ u = w_obj._value
+ set_wbuffer(py_obj, rffi.unicode2wcharp(u))
+ set_wsize(py_obj, len(u))
ucs4_data = get_wbuffer(py_obj)
set_data(py_obj, cts.cast('void*', ucs4_data))
set_len(py_obj, get_wsize(py_obj))
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit