[Cython] __getattribute__

Peter Todd pete at petertodd.org
Fri May 9 05:26:12 CEST 2008


On Fri, May 09, 2008 at 02:13:21PM +1200, Greg Ewing wrote:
> I've been thinking some more about __getattribute__, and I think
> that rather than trying to emulate the Python semantics, the
> right thing to do is simply to expose the C type slot directly.
> 
> This would be in keeping with the way the other type slots
> are handled. The philosophy is that when defining an extension
> type, you should have as much control and as little overhead
> in the way as possible.
> 
> The only places where I've done things differently are where
> there isn't a directly corresponding C slot, such as __getattr__.
> Since __getattribute__ corresponds most closely to tp_getattr,
> it should just fill it directly.

If no __getattr__ is defined, __getattribute__ is essentially a
tp_getattr slot filler:

static PyObject *__pyx_tp_getattro_3foo_foo(PyObject *o, PyObject *n) {
    PyObject *v = __pyx_pf_3foo_3foo___getattribute__(o, n);
    return v;
}

One level of indirection, but that's just an artifact of the current
implementation that the compiler might very well optimize out anyway.

-- 
http://petertodd.org 'peter'[:-1]@petertodd.org 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://codespeak.net/pipermail/cython-dev/attachments/20080508/e816f6fe/attachment.pgp 


More information about the Cython-dev mailing list