Stefan Behnel wrote:
> Neal Becker, 27.08.2010 15:09:
>> Stefan Behnel wrote:
>>> Neal Becker, 27.08.2010 13:32:
>>>> I've noticed that cython extension classes are more restrictive than
>>>> boost::python classes. In particular, I believe boost::python allows
>>>> attributes to be added by python code to boost::python classes, while
>>>> cython
>>>> classes are 'closed'. Is this correct?
>>>
>>> I don't know what kind of classes boost uses, but the above only applies
>>> to extension types in Cython. Normal Python classes behave as in normal
>>> Python. And it should be possible to add a __dict__ to extension types
>>> without much hassle, it's just that most people don't want that.
>>> Initialising a dict takes time during type instantiation and takes
>>> additional space during the lifetime of the object.
>>>
>>> BTW, now that you mention it - does anyone know what became of the idea
>>> to allow a
>>>
>>> cdef __dict__
>>>
>>> attribute notation (as for __weakref__) to add a dict to an extension
>>> type? AFAIR, that was already proposed more than once on this list.
>>>
>>> Stefan
>>
>> I just tested it. With boost::python you can add attribute to class as
>> well as instance of class.
>
> Could you send me the C++ code that it generates for the module?
>
> I checked what CPython does when accessing TheType.__dict__, and it
> actually returns a read-only dict proxy:
>
> static PyObject *
> type_dict(PyTypeObject *type, void *context)
> {
> if (type->tp_dict == NULL) {
> Py_INCREF(Py_None);
> return Py_None;
> }
> return PyDictProxy_New(type->tp_dict);
> }
>
> To work around that, we may have to override the descriptor that returns
> the __dict__ through the tp_getset slot of the type.
>
> Stefan
boost::python is not a code generator. Is is (some of the most twisted,
obfuscated ever!) native c++ code.
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev