Author: Armin Rigo <ar...@tunes.org> Branch: cffi-char16-char32 Changeset: r91515:35d3643b476a Date: 2017-06-04 23:38 +0200 http://bitbucket.org/pypy/pypy/changeset/35d3643b476a/
Log: Copy failing test from the CPython cffi test suite; fix it (for 16-bit unicode chars) diff --git a/pypy/module/_cffi_backend/test/test_ffi_obj.py b/pypy/module/_cffi_backend/test/test_ffi_obj.py --- a/pypy/module/_cffi_backend/test/test_ffi_obj.py +++ b/pypy/module/_cffi_backend/test/test_ffi_obj.py @@ -555,3 +555,11 @@ import _cffi_backend as _cffi1_backend ffi = _cffi1_backend.FFI() raises(ffi.error, ffi.cast, "int[-5]", 0) + + def test_char32_t(self): + import _cffi_backend as _cffi1_backend + ffi = _cffi1_backend.FFI() + z = ffi.new("char32_t[]", u'\U00012345') + assert len(z) == 2 + assert ffi.cast("int *", z)[0] == 0x12345 + assert list(z) == [u'\U00012345', u'\x00'] # maybe a 2-unichars str diff --git a/pypy/module/_cffi_backend/wchar_helper.py b/pypy/module/_cffi_backend/wchar_helper.py --- a/pypy/module/_cffi_backend/wchar_helper.py +++ b/pypy/module/_cffi_backend/wchar_helper.py @@ -153,8 +153,9 @@ # we assume here that target_length == unicode_size_as_char32(u). ptr = rffi.cast(rffi.UINTP, target_ptr) src_index = 0 + last_surrogate_pos = len(u) - 2 for i in range(target_length): - if i < target_length - 1 and is_surrogate(u, src_index): + if src_index <= last_surrogate_pos and is_surrogate(u, src_index): ordinal = as_surrogate(u, src_index) src_index += 2 else: _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit