[pypy-svn] r51686 - in pypy/dist/pypy/module/_rawffi: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Wed Feb 20 14:38:28 CET 2008
Author: cfbolz
Date: Wed Feb 20 14:38:27 2008
New Revision: 51686
Modified:
pypy/dist/pypy/module/_rawffi/structure.py
pypy/dist/pypy/module/_rawffi/test/test__rawffi.py
Log:
make the __call__ of Structure not take any arguments, since it is not needed
Modified: pypy/dist/pypy/module/_rawffi/structure.py
==============================================================================
--- pypy/dist/pypy/module/_rawffi/structure.py (original)
+++ pypy/dist/pypy/module/_rawffi/structure.py Wed Feb 20 14:38:27 2008
@@ -69,14 +69,9 @@
raise OperationError(space.w_AttributeError, space.wrap(
"C Structure has no attribute %s" % attr))
- def descr_call(self, space, __args__):
- args_w, kwargs_w = __args__.unpack()
- if args_w:
- raise OperationError(
- space.w_TypeError,
- space.wrap("Structure accepts only keyword arguments as field initializers"))
- return space.wrap(W_StructureInstance(space, self, 0, kwargs_w))
- descr_call.unwrap_spec = ['self', ObjSpace, Arguments]
+ def descr_call(self, space):
+ return space.wrap(W_StructureInstance(space, self, 0))
+ descr_call.unwrap_spec = ['self', ObjSpace]
def descr_repr(self, space):
fieldnames = ' '.join(["'%s'" % name for name, _ in self.fields])
@@ -86,7 +81,7 @@
descr_repr.unwrap_spec = ['self', ObjSpace]
def fromaddress(self, space, address):
- return space.wrap(W_StructureInstance(space, self, address, None))
+ return space.wrap(W_StructureInstance(space, self, address))
fromaddress.unwrap_spec = ['self', ObjSpace, r_uint]
def descr_fieldoffset(self, space, attr):
@@ -129,12 +124,9 @@
cast_pos._annspecialcase_ = 'specialize:arg(2)'
class W_StructureInstance(W_DataInstance):
- def __init__(self, space, shape, address, fieldinits_w):
+ def __init__(self, space, shape, address):
W_DataInstance.__init__(self, space, shape.size, address)
self.shape = shape
- if fieldinits_w:
- for field, w_value in fieldinits_w.iteritems():
- self.setattr(space, field, w_value)
def descr_repr(self, space):
addr = rffi.cast(lltype.Unsigned, self.ll_buffer)
Modified: pypy/dist/pypy/module/_rawffi/test/test__rawffi.py
==============================================================================
--- pypy/dist/pypy/module/_rawffi/test/test__rawffi.py (original)
+++ pypy/dist/pypy/module/_rawffi/test/test__rawffi.py Wed Feb 20 14:38:27 2008
@@ -280,8 +280,14 @@
lib = _rawffi.CDLL(self.lib_name)
inner = lib.ptr("inner_struct_elem", ['P'], 'c')
X = _rawffi.Structure([('x1', 'i'), ('x2', 'h'), ('x3', 'c'), ('next', 'P')])
- next = X(next=0, x3='x')
- x = X(next=next, x1=1, x2=2, x3='x')
+ next = X()
+ next.next = 0
+ next.x3 = 'x'
+ x = X()
+ x.next = next
+ x.x1 = 1
+ x.x2 = 2
+ x.x3 = 'x'
assert X.fromaddress(x.next).x3 == 'x'
x.free()
next.free()
@@ -319,7 +325,8 @@
lib = _rawffi.CDLL(self.lib_name)
A = _rawffi.Array('P')
X = _rawffi.Structure([('x1', 'i'), ('x2', 'h'), ('x3', 'c'), ('next', 'P')])
- x = X(x2=3)
+ x = X()
+ x.x2 = 3
a = A(3)
a[1] = x
get_array_elem_s = lib.ptr('get_array_elem_s', ['P', 'i'], 'P')
@@ -421,7 +428,9 @@
def test_setattr_struct(self):
import _rawffi
X = _rawffi.Structure([('value1', 'i'), ('value2', 'i')])
- x = X(value1=1, value2=2)
+ x = X()
+ x.value1 = 1
+ x.value2 = 2
assert x.value1 == 1
assert x.value2 == 2
x.value1 = 3
@@ -454,7 +463,8 @@
assert a.shape is A
a.free()
S = _rawffi.Structure([('v1', 'i')])
- s = S(v1=3)
+ s = S()
+ s.v1 = 3
assert s.shape is S
s.free()
More information about the Pypy-commit
mailing list