On 28 August 2010 03:12, Stefan Behnel <[email protected]> wrote:
> Lisandro Dalcin, 27.08.2010 23:38:
>>> I think the right way to implement this is with custom decriptors for both
>>> the type and its instance.
>>
>> Do you mean adding a descriptor for __dict__ ? If you use cdef
>> public|readonly __dict__, you get it.
>
> Right, I think __dict__ should be "public" by default, just like
> __weakref__ is always usable from outside.
>

Do you think that "cdef private __dict__" would have any use? We
cannot write "private"...

>
>> But Cython code will make a
>> direct pointer access, like for any other cdef member... What's wrong
>> with this approach?
>
> Well, it wastes instance memory if __dict__ is not used. I would expect
> that most use cases for __dict__ do not come from Cython code but from
> Python code that uses the types. As I said, going through a descriptor
> would allow instantiating the dict at first request rather than *always*.
> That's important for library code.
>
> Potentially, we could also add a NULL check in the Cython access code
> wherever __dict__ is used, and go through the descriptor only if it's not
> set up yet. But that would be an optimisation. I think safe and memory
> friendly access should go first.
>

On one hand, I think that who adds a __dict__ to cdef classes do know
the trade-offs, as __dict__ is not provided unless explicitly
requested, I do not consider a big deal to unconditionally create the
__dict__ and have fast access, we can optimize things later. My
current patch do work already, users needing this could start using
the feature in 0.13.1

On the other hand, I do not care too much if this is implemented going
through a descriptor, but as I'm not going to use this feature anyway.
This implementations have to be written (and certainly not by me, I
have no clear idea how to use cdef __dict__ and make Cython go through
the descriptor).

It is  hard follow the criteria of core Cython developers and
contributors :-)... For some things, they like it fast despite being
unsafe, for others this it is the other way around, some idiot guys as
for compiler directives controlling every detail...



-- 
Lisandro Dalcin
---------------
CIMEC (INTEC/CONICET-UNL)
Predio CONICET-Santa Fe
Colectora RN 168 Km 472, Paraje El Pozo
Tel: +54-342-4511594 (ext 1011)
Tel/Fax: +54-342-4511169
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to