[pypy-commit] cffi default: Accept strings to initialize signed/unsigned char arrays.
arigo
noreply at buildbot.pypy.org
Sat Sep 22 13:10:28 CEST 2012
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r958:f60f68a19251
Date: 2012-09-22 13:09 +0200
http://bitbucket.org/cffi/cffi/changeset/f60f68a19251/
Log: Accept strings to initialize signed/unsigned char arrays.
diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -878,7 +878,9 @@
}
return 0;
}
- else if (ctitem->ct_flags & CT_PRIMITIVE_CHAR) {
+ else if ((ctitem->ct_flags & CT_PRIMITIVE_CHAR) ||
+ ((ctitem->ct_flags & (CT_PRIMITIVE_SIGNED|CT_PRIMITIVE_UNSIGNED))
+ && (ctitem->ct_size == sizeof(char)))) {
if (ctitem->ct_size == sizeof(char)) {
char *srcdata;
Py_ssize_t n;
diff --git a/c/test_c.py b/c/test_c.py
--- a/c/test_c.py
+++ b/c/test_c.py
@@ -2165,3 +2165,22 @@
#
d = rawaddressof(BCharP, s, 1)
assert d == cast(BCharP, p) + 1
+
+def test_newp_signed_unsigned_char():
+ BCharArray = new_array_type(
+ new_pointer_type(new_primitive_type("char")), None)
+ p = newp(BCharArray, b"foo")
+ assert len(p) == 4
+ assert list(p) == [b"f", b"o", b"o", b"\x00"]
+ #
+ BUCharArray = new_array_type(
+ new_pointer_type(new_primitive_type("unsigned char")), None)
+ p = newp(BUCharArray, b"fo\xff")
+ assert len(p) == 4
+ assert list(p) == [ord("f"), ord("o"), 0xff, 0]
+ #
+ BSCharArray = new_array_type(
+ new_pointer_type(new_primitive_type("signed char")), None)
+ p = newp(BSCharArray, b"fo\xff")
+ assert len(p) == 4
+ assert list(p) == [ord("f"), ord("o"), -1, 0]
More information about the pypy-commit
mailing list