[pypy-commit] pypy ffistruct: move _ffi.Field and most of compute_shape to interp-level
antocuni
noreply at buildbot.pypy.org
Wed Sep 7 14:55:50 CEST 2011
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: ffistruct
Changeset: r47131:f348de8d9bd3
Date: 2011-09-07 09:43 +0200
http://bitbucket.org/pypy/pypy/changeset/f348de8d9bd3/
Log: move _ffi.Field and most of compute_shape to interp-level
diff --git a/pypy/module/_ffi/__init__.py b/pypy/module/_ffi/__init__.py
--- a/pypy/module/_ffi/__init__.py
+++ b/pypy/module/_ffi/__init__.py
@@ -8,9 +8,9 @@
'FuncPtr': 'interp_funcptr.W_FuncPtr',
'get_libc':'interp_funcptr.get_libc',
'_StructDescr': 'interp_struct.W__StructDescr',
+ 'Field': 'interp_struct.W_Field',
}
appleveldefs = {
'Structure': 'app_struct.Structure',
- 'Field': 'app_struct.Field',
}
diff --git a/pypy/module/_ffi/app_struct.py b/pypy/module/_ffi/app_struct.py
--- a/pypy/module/_ffi/app_struct.py
+++ b/pypy/module/_ffi/app_struct.py
@@ -1,20 +1,5 @@
import _ffi
-class Field(object):
-
- def __init__(self, name, ffitype):
- self.name = name
- self.ffitype = ffitype
- self.offset = -1
-
- ## def __get__(self, obj, cls=None):
- ## if obj is None:
- ## return self
- ## return getfield(obj._buffer, self.ffitype, self.offset)
-
- ## def __set__(self, obj, value):
- ## setfield(obj._buffer, self.ffitype, self.offset, value)
-
class MetaStructure(type):
def __new__(cls, name, bases, dic):
@@ -26,15 +11,9 @@
fields = dic.get('_fields_')
if fields is None:
return
- size = 0
- ffitypes = []
+ struct_descr = _ffi._StructDescr(name, fields)
for field in fields:
- field.offset = size # XXX: alignment!
- size += field.ffitype.sizeof()
- ffitypes.append(field.ffitype)
dic[field.name] = field
- alignment = 0 # XXX
- struct_descr = _ffi._StructDescr(name, size, alignment, ffitypes)
dic['_struct_'] = struct_descr
diff --git a/pypy/module/_ffi/test/test_struct.py b/pypy/module/_ffi/test/test_struct.py
--- a/pypy/module/_ffi/test/test_struct.py
+++ b/pypy/module/_ffi/test/test_struct.py
@@ -3,9 +3,13 @@
class AppTestStruct(BaseAppTestFFI):
def test__StructDescr(self):
- from _ffi import _StructDescr, types
+ from _ffi import _StructDescr, Field, types
longsize = types.slong.sizeof()
- descr = _StructDescr('foo', longsize*2, 0, [types.slong, types.slong])
+ fields = [
+ Field('x', types.slong),
+ Field('y', types.slong),
+ ]
+ descr = _StructDescr('foo', fields)
assert descr.ffitype.sizeof() == longsize*2
assert descr.ffitype.name == 'struct foo'
@@ -24,4 +28,3 @@
assert Point.y.offset == longsize
assert Point._struct_.ffitype.sizeof() == longsize*2
assert Point._struct_.ffitype.name == 'struct Point'
-
More information about the pypy-commit
mailing list