Author: Armin Rigo <[email protected]>
Branch:
Changeset: r96553:d1159d6fe0e6
Date: 2019-04-29 10:22 +0200
http://bitbucket.org/pypy/pypy/changeset/d1159d6fe0e6/
Log: Test and fix
diff --git a/pypy/module/_rawffi/interp_rawffi.py
b/pypy/module/_rawffi/interp_rawffi.py
--- a/pypy/module/_rawffi/interp_rawffi.py
+++ b/pypy/module/_rawffi/interp_rawffi.py
@@ -450,8 +450,13 @@
elif c == 'c':
return space.newbytes(func(add_arg, argdesc, ll_type))
elif c == 'u':
- return space.newutf8(rutf8.unichr_as_utf8(
- ord(func(add_arg, argdesc, ll_type))), 1)
+ code = ord(func(add_arg, argdesc, ll_type))
+ try:
+ return space.newutf8(rutf8.unichr_as_utf8(
+ code, allow_surrogates=True), 1)
+ except rutf8.OutOfRange:
+ raise oefmt(space.w_ValueError,
+ "unicode character %d out of range", code)
elif c == 'f' or c == 'd' or c == 'g':
return space.newfloat(float(func(add_arg, argdesc, ll_type)))
else:
diff --git a/pypy/module/_rawffi/test/test__rawffi.py
b/pypy/module/_rawffi/test/test__rawffi.py
--- a/pypy/module/_rawffi/test/test__rawffi.py
+++ b/pypy/module/_rawffi/test/test__rawffi.py
@@ -347,6 +347,21 @@
arg2.free()
a.free()
+ def test_unicode_array(self):
+ import _rawffi
+ A = _rawffi.Array('u')
+ a = A(6, u'\u1234')
+ assert a[0] == u'\u1234'
+ a[0] = u'\U00012345'
+ assert a[0] == u'\U00012345'
+ a[0] = u'\ud800'
+ assert a[0] == u'\ud800'
+ B = _rawffi.Array('i')
+ b = B.fromaddress(a.itemaddress(0), 1)
+ b[0] = 0xffffffff
+ raises(ValueError, "a[0]")
+ a.free()
+
def test_returning_unicode(self):
import _rawffi
A = _rawffi.Array('u')
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit