[pypy-commit] cffi char16_char32_t: fixes
arigo
pypy.commits at gmail.com
Wed May 31 10:57:36 EDT 2017
Author: Armin Rigo <arigo at tunes.org>
Branch: char16_char32_t
Changeset: r2956:2c0195e0f232
Date: 2017-05-31 16:57 +0200
http://bitbucket.org/cffi/cffi/changeset/2c0195e0f232/
Log: fixes
diff --git a/c/parse_c_type.c b/c/parse_c_type.c
--- a/c/parse_c_type.c
+++ b/c/parse_c_type.c
@@ -493,6 +493,7 @@
case '1':
if (size == 8 && !memcmp(p, "uint16", 6)) return _CFFI_PRIM_UINT16;
+ if (size == 8 && !memcmp(p, "char16", 6)) return _CFFI_PRIM_CHAR16;
break;
case '2':
@@ -501,6 +502,7 @@
case '3':
if (size == 8 && !memcmp(p, "uint32", 6)) return _CFFI_PRIM_UINT32;
+ if (size == 8 && !memcmp(p, "char32", 6)) return _CFFI_PRIM_CHAR32;
break;
case '4':
diff --git a/c/wchar_helper.h b/c/wchar_helper.h
--- a/c/wchar_helper.h
+++ b/c/wchar_helper.h
@@ -134,7 +134,7 @@
#if Py_UNICODE_SIZE == 4
if (((unsigned int)u[0]) > 0xFFFF)
{
- sprintf(err_got, "unicode character too large for 16 bits");
+ sprintf(err_got, "larger-than-0xFFFF character");
return -1;
}
#endif
diff --git a/testing/cffi0/test_ffi_backend.py b/testing/cffi0/test_ffi_backend.py
--- a/testing/cffi0/test_ffi_backend.py
+++ b/testing/cffi0/test_ffi_backend.py
@@ -542,7 +542,12 @@
y = ffi.new("char32_t[]", u+'\u1234\u5678')
assert len(y) == 3
assert list(y) == [u+'\u1234', u+'\u5678', u+'\x00']
- z = ffi.new("char32_t[]", u+'\U00012345')
+ py_uni = u+'\U00012345'
+ z = ffi.new("char32_t[]", py_uni)
assert len(z) == 2
- assert list(z) == [u+'\U00012345', u+'\x00'] # maybe a 2-unichars string
- assert ffi.string(z) == u+'\U00012345'
+ assert list(z) == [py_uni, u+'\x00'] # maybe a 2-unichars string
+ assert ffi.string(z) == py_uni
+ if len(py_uni) == 1: # 4-bytes unicodes in Python
+ s = ffi.new("char32_t[]", u+'\ud808\udf00')
+ assert len(s) == 3
+ assert list(s) == [u+'\ud808', u+'\udf00', u+'\x00']
diff --git a/testing/cffi1/test_recompiler.py b/testing/cffi1/test_recompiler.py
--- a/testing/cffi1/test_recompiler.py
+++ b/testing/cffi1/test_recompiler.py
@@ -2271,6 +2271,7 @@
assert lib.foo_2bytes(u+'\u1234') == u+'\u125e'
assert lib.foo_4bytes(u+'\u1234') == u+'\u125e'
assert lib.foo_4bytes(u+'\U00012345') == u+'\U0001236f'
+ py.test.raises(TypeError, lib.foo_2bytes, u+'\U00012345')
def test_char16_char32_plain_c():
test_char16_char32_type(no_cpp=True)
More information about the pypy-commit
mailing list