[pypy-commit] pypy ffi-backend: More cases.
arigo
noreply at buildbot.pypy.org
Mon Jun 25 17:07:42 CEST 2012
Author: Armin Rigo <arigo at tunes.org>
Branch: ffi-backend
Changeset: r55817:24a81db180a8
Date: 2012-06-25 17:07 +0200
http://bitbucket.org/pypy/pypy/changeset/24a81db180a8/
Log: More cases.
diff --git a/pypy/module/_ffi_backend/ctypeobj.py b/pypy/module/_ffi_backend/ctypeobj.py
--- a/pypy/module/_ffi_backend/ctypeobj.py
+++ b/pypy/module/_ffi_backend/ctypeobj.py
@@ -244,7 +244,9 @@
space.isinstance_w(w_ob, space.w_tuple)):
lst_w = space.listview(w_ob)
if self.length >= 0 and len(lst_w) > self.length:
- xxx
+ raise operationerrfmt(space.w_IndexError,
+ "too many initializers for '%s' (got %d)",
+ self.name, len(lst_w))
ctitem = self.ctitem
for i in range(len(lst_w)):
ctitem.convert_from_object(cdata, lst_w[i])
@@ -258,7 +260,10 @@
raise self._convert_error("str or list or tuple", w_ob)
n = len(s)
if self.length >= 0 and n > self.length:
- xxx
+ raise operationerrfmt(space.w_IndexError,
+ "initializer string is too long for '%s'"
+ " (got %d characters)",
+ self.name, n)
for i in range(n):
cdata[i] = s[i]
if n != self.length:
@@ -504,8 +509,22 @@
self.name, len(lst_w))
for i in range(len(lst_w)):
self.fields_list[i].write(cdata, lst_w[i])
+
+ elif space.isinstance_w(w_ob, space.w_dict):
+ lst_w = space.fixedview(w_ob)
+ for i in range(len(lst_w)):
+ w_key = lst_w[i]
+ key = space.str_w(w_key)
+ try:
+ cf = self.fields_dict[key]
+ except KeyError:
+ space.raise_key_error(w_key)
+ assert 0
+ cf.write(cdata, space.getitem(w_ob, w_key))
+
else:
- xxx
+ raise self._convert_error("list or tuple or dict or struct-cdata",
+ w_ob)
class W_CTypeUnion(W_CTypeStructOrUnion):
diff --git a/pypy/module/_ffi_backend/test/_backend_test_c.py b/pypy/module/_ffi_backend/test/_backend_test_c.py
--- a/pypy/module/_ffi_backend/test/_backend_test_c.py
+++ b/pypy/module/_ffi_backend/test/_backend_test_c.py
@@ -281,7 +281,7 @@
new_array_type, new_pointer_type(p), sys.maxint // 3)
def test_array_instance():
- LENGTH = 14242
+ LENGTH = 1423
p = new_primitive_type("int")
p1 = new_array_type(new_pointer_type(p), LENGTH)
a = newp(p1, None)
@@ -545,6 +545,13 @@
assert s.a1 == 123
assert s.a2 == 456
assert s.a3 == 0
+ #
+ s = newp(BStructPtr, {'a2': 41122, 'a3': -123})
+ assert s.a1 == 0
+ assert s.a2 == 41122
+ assert s.a3 == -123
+ #
+ py.test.raises(KeyError, newp, BStructPtr, {'foobar': 0})
def test_array_in_struct():
BInt = new_primitive_type("int")
More information about the pypy-commit
mailing list