Struct attributes can have private or readonly, but not public, Python
visibility.
Readonly structs are currently converted to dicts on the fly for each
call getting the struct attribute value. The dict-generation code is
currently broken for C++ (error: declaration does not declare
anything), so tests/run/cdef_members_T517.pyx currently fails a C++
test. However, we hope to soon replace it with full blown Python
classes representing structs/unions/enums which will work for both C
and C++.
6:24: C attribute of type 'VoidP' cannot be accessed from Python
6:24: Cannot convert 'VoidP' to Python object
6:24: Cannot convert Python object to 'VoidP'
-14:22: C attribute of type 'Foo' cannot be accessed from Python
14:22: Cannot convert Python object to 'Foo'
"""
>>> b.c2 = A() #doctest: +ELLIPSIS
Traceback (most recent call last):
AttributeError: ...
+
+>>> bar = Bar()
+
+>>> bar.foo0 #doctest: +ELLIPSIS
+Traceback (most recent call last):
+AttributeError: ...
+
+>>> type(bar.foo1)
+<type 'dict'>
+>>> bar.foo1
+{'i': 0}
+>>> bar.foo1['i'] = 2
+>>> bar.foo1
+{'i': 0}
"""
import sys
def __cinit__(self):
self.b0 = self.b1 = self.b2 = []
self.c0 = self.c1 = self.c2 = A()
+
+
+ctypedef struct Foo:
+ int i
+
+
+cdef class Bar:
+ cdef Foo foo0
+ cdef readonly Foo foo1
+ pass