[Pyrex] C versus Python access

Robert Bradshaw robertwb at math.washington.edu
Thu Nov 1 00:15:02 CET 2007


On Oct 31, 2007, at 3:37 PM, Greg Ewing wrote:

> Robert Bradshaw wrote:
>
>> if type(self) has a __dict__:
>>     foo = self.getattr('foo')
>>     if foo is not wrapper_foo:
>>         return foo(args)
>> [cdef method body]
>
> It does add an attribute lookup whenever a Python subclass
> is involved, so it's not entirely overhead-free.

Yes, this is why we made it a third function type (rather than  
rolling it into def or cdef). For much of what we have in SAGE it is  
worth it.

> More seriously, it looks like it will fail if the overriding
> method tries to call the inherited method. This will call
> the wrapper, which will pick up the overriding method and
> call it again, leading to infinite recursion.

Good point. Short of warning people to avoid this flaw, one could  
maybe look at the traceback to detect where one was called from, or  
perhaps add a dispatcher function (is called by the vtable entry, but  
skipped in the wrapper function). Of course this would add an extra  
function call so is less than ideal... I'll have to think about this;  
do you have any ideas?

- Robert




More information about the Pyrex mailing list