Lisandro Dalcin, 10.06.2010 16:50:
> Please try the attached test case. If you switch the comment in the
> first two lines, you will get the failure. So far, I could not figure
> out what's going on.
Your code is basically this:
---------------------
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).
gdb gives me this for C function call in the "Foo2.hallo" method wrapper:
601 __pyx_t_1 = ((struct __pyx_vtabstruct_11methinherit_Foo2
*)((struct __pyx_obj_11methinherit_Foo2
*)__pyx_v_self)->__pyx_vtab)->hello(((struct __pyx_obj_11methinherit_Foo2
*)__pyx_v_self), 1); if (unlikely(!__pyx_t_1)) {__pyx_filename =
__pyx_f[0]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
(gdb) print __pyx_v_self
$1 = <methinherit.Bar2 at remote 0x7ffff7ee40f0>
(gdb) pyo __pyx_v_self
object : <methinherit.Bar2 object at 0x7ffff7ee40f0>
type : methinherit.Bar2
refcount: 3
address : 0x7ffff7ee40f0
$2 = void
(gdb) print ((struct __pyx_obj_11methinherit_Foo2 *)__pyx_v_self)->__pyx_vtab
$3 = (struct __pyx_vtabstruct_11methinherit_Foo2 *) 0x7ffff69ba2f0
(gdb) print ((struct __pyx_obj_11methinherit_Foo2
*)__pyx_v_self)->__pyx_vtab->hello
$4 = (PyObject *(*)(struct __pyx_obj_11methinherit_Foo2 *, int))
0x7ffff67b6492 <__pyx_f_11methinherit_4Bar2_hello>
Note the "__pyx_f_11methinherit_4Bar2_hello" function in the last line.
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.
Any ideas?
Stefan
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev