Haoyu Bai, 08.07.2010 16:40:
> On Thu, Jul 8, 2010 at 1:05 AM, Stefan Behnel wrote:
>> ---------------------
>> cdef class Foo2:
>>      cpdef hello(self):
>>          print 'Foo.hello()'
>>
>> cdef class Bar2(Foo2):
>>      cpdef hello(self):
>>          print 'Bar.hello()'
>>
>> Foo.hello(b)
>> ---------------------
>>
>> The problem is that this prints "Bar.hello()", not "Foo.hello()" as one
>> would expect (and which is how CPython behaves).
>>  [...]
>> So, the problem is that the cpdef wrapper effectively calls "self.hello",
>> which is "Bar.hello" in this case. This is the wrong thing to do for an
>> unbound method. However, I'm not sure how to fix this, either.
>
> How about implement a tp_descr_get to dispatch the vtable instead of
> dispatching it inside the method? Then Bar.hello will return the
> correct unbounded method and self.hello will call the descriptor and
> return the  bounded method.

Interesting. So we'd basically implement our own method lookup descriptor? 
You already have to return a separate instance for each lookup to inject 
the reference to 'self', so you could move the vtable lookup overhead into 
the method lookup rather than into the call. Might be worth a try. It also 
sounds like a lot of overhead, though...

Stefan
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to