Author: Antonio Cuni <anto.c...@gmail.com>
Branch: ffistruct
Changeset: r47111:69a6b100e900
Date: 2011-09-06 16:36 +0200
http://bitbucket.org/pypy/pypy/changeset/69a6b100e900/

Log:    store also the struct name in the descr

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
@@ -18,11 +18,11 @@
 class MetaStructure(type):
 
     def __new__(cls, name, bases, dic):
-        cls._compute_shape(dic)
+        cls._compute_shape(name, dic)
         return type.__new__(cls, name, bases, dic)
 
     @classmethod
-    def _compute_shape(cls, dic):
+    def _compute_shape(cls, name, dic):
         fields = dic.get('_fields_')
         if fields is None:
             return
@@ -34,7 +34,7 @@
             ffitypes.append(field.ffitype)
             dic[field.name] = field
         alignment = 0 # XXX
-        struct_descr = _ffi._StructDescr(size, alignment, ffitypes)
+        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
@@ -5,9 +5,10 @@
     def test__StructDescr(self):
         from _ffi import _StructDescr, types
         longsize = types.slong.sizeof()
-        descr = _StructDescr(longsize*2, 0, [types.slong, types.slong])
+        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 <unknown struct>>'
+        assert repr(descr.ffitype) == '<ffi type struct foo>'
 
     def test_compute_shape(self):
         from _ffi import Structure, Field, types
@@ -22,4 +23,5 @@
         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
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to