[pypy-commit] pypy ffistruct: don't store the name on the struct descr, but make it accessible from the ffi type
antocuni
noreply at buildbot.pypy.org
Tue Sep 6 18:04:44 CEST 2011
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: ffistruct
Changeset: r47112:ced67009fa52
Date: 2011-09-06 16:39 +0200
http://bitbucket.org/pypy/pypy/changeset/ced67009fa52/
Log: don't store the name on the struct descr, but make it accessible
from the ffi type
diff --git a/pypy/module/_ffi/interp_ffitype.py b/pypy/module/_ffi/interp_ffitype.py
--- a/pypy/module/_ffi/interp_ffitype.py
+++ b/pypy/module/_ffi/interp_ffitype.py
@@ -1,7 +1,7 @@
from pypy.rlib import libffi
from pypy.rlib.rarithmetic import intmask
from pypy.interpreter.baseobjspace import Wrappable
-from pypy.interpreter.typedef import TypeDef
+from pypy.interpreter.typedef import TypeDef, interp_attrproperty
from pypy.interpreter.gateway import interp2app
class W_FFIType(Wrappable):
@@ -81,6 +81,7 @@
W_FFIType.typedef = TypeDef(
'FFIType',
+ name = interp_attrproperty('name', W_FFIType),
__repr__ = interp2app(W_FFIType.repr),
deref_pointer = interp2app(W_FFIType.descr_deref_pointer),
sizeof = interp2app(W_FFIType.descr_sizeof),
diff --git a/pypy/module/_ffi/test/test_ffitype.py b/pypy/module/_ffi/test/test_ffitype.py
--- a/pypy/module/_ffi/test/test_ffitype.py
+++ b/pypy/module/_ffi/test/test_ffitype.py
@@ -6,7 +6,9 @@
from _ffi import types
assert str(types.sint) == "<ffi type sint>"
assert str(types.uint) == "<ffi type uint>"
-
+ assert types.sint.name == 'sint'
+ assert types.uint.name == 'uint'
+
def test_sizeof(self):
from _ffi import types
assert types.sbyte.sizeof() == 1
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
@@ -6,9 +6,8 @@
from _ffi import _StructDescr, types
longsize = types.slong.sizeof()
descr = _StructDescr('foo', longsize*2, 0, [types.slong, types.slong])
- assert descr.name == 'foo'
assert descr.ffitype.sizeof() == longsize*2
- assert repr(descr.ffitype) == '<ffi type struct foo>'
+ assert descr.ffitype.name == 'struct foo'
def test_compute_shape(self):
from _ffi import Structure, Field, types
@@ -23,5 +22,6 @@
assert isinstance(Point.y, Field)
assert Point.x.offset == 0
assert Point.y.offset == longsize
- assert Point._struct_.name == 'Point'
assert Point._struct_.ffitype.sizeof() == longsize*2
+ assert Point._struct_.ffitype.name == 'struct Point'
+
More information about the pypy-commit
mailing list