Author: Armin Rigo <ar...@tunes.org> Branch: ffi-backend Changeset: r55784:8e6a642a506d Date: 2012-06-23 16:41 +0200 http://bitbucket.org/pypy/pypy/changeset/8e6a642a506d/
Log: Next test 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 @@ -211,12 +211,12 @@ space = self.space if (space.isinstance_w(w_ob, space.w_list) or space.isinstance_w(w_ob, space.w_tuple)): - lst = space.listview(w_ob) - if self.length >= 0 and len(lst) > self.length: + lst_w = space.listview(w_ob) + if self.length >= 0 and len(lst_w) > self.length: xxx ctitem = self.ctitem - for i in range(len(lst)): - ctitem.convert_from_object(cdata, lst[i]) + for i in range(len(lst_w)): + ctitem.convert_from_object(cdata, lst_w[i]) cdata = rffi.ptradd(cdata, ctitem.size) else: xxx @@ -432,9 +432,30 @@ class W_CTypeStruct(W_CTypeStructOrUnion): kind = "struct" + def convert_from_object(self, cdata, w_ob): + space = self.space + ob = space.interpclass_w(w_ob) + if isinstance(ob, cdataobj.W_CData): + xxx + + if (space.isinstance_w(w_ob, space.w_list) or + space.isinstance_w(w_ob, space.w_tuple)): + lst_w = space.listview(w_ob) + if len(lst_w) > len(self.fields_list): + xxx # "too many initializers for '%s' (got %zd)" + for i in range(len(lst_w)): + self.fields_list[i].write(cdata, lst_w[i]) + else: + xxx + + class W_CTypeUnion(W_CTypeStructOrUnion): kind = "union" + def convert_from_object(self, cdata, w_ob): + xxx + + class W_CField(Wrappable): _immutable_ = True def __init__(self, ctype, offset, bitshift, bitsize): 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 @@ -831,7 +831,15 @@ BInt = new_primitive_type("int") BStruct = new_struct_type("foo") complete_struct_or_union(BStruct, [('a1', BInt, 1)]) - py.test.raises(NotImplementedError, newp, new_pointer_type(BStruct), [-1]) + p = newp(new_pointer_type(BStruct), [-1]) + assert p.a1 == -1 + p = newp(new_pointer_type(BStruct), {'a1': -1}) + assert p.a1 == -1 + # + BUnion = new_union_type("bar") + complete_struct_or_union(BUnion, [('a1', BInt, 1)]) + p = newp(new_pointer_type(BUnion), -1) + assert p.a1 == -1 def test_weakref(): import weakref _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit