Hi,
Dag Sverre Seljebotn wrote:
> Lisandro Dalcin wrote:
>> Brian Granger posted some days ago about problems with multiple inheritance:
>>
>> http://codespeak.net/pipermail/cython-dev/2008-July/001814.html
>>
>> It seems that Cython is generating bad code. A C compiler (gcc) just
>> warn about it, but a C++ compiler (g++)
>> generates an error.
>>
>> A tentative patch for this issue is posted here:
>>
>> http://codespeak.net/pipermail/cython-dev/2008-July/001835.html
The original patch made a test case fail, the attached patch works better (not
sure why this is required, though).
> Even with the patch, the end-result seems a bit strange:
>
> static PyObject *__pyx_tp_new_4vtab_Bam(PyTypeObject *t, PyObject *a,
> PyObject *k) {
> struct __pyx_obj_4vtab_Bam *p;
> PyObject *o = __pyx_tp_new_4vtab_Foo(t, a, k);
> if (!o) return 0;
> p = ((struct __pyx_obj_4vtab_Bam *)o);
> p->__pyx_base.__pyx_base.__pyx_vtab = (struct
> __pyx_vtabstruct_4vtab_Foo*)__pyx_vtabptr_4vtab_Bam;
> return o;
> }
>
> I.e. on vtable generation it seems to skip its immediate ancestor.
It still seems to be the right thing to do. Maybe Greg can enlighten us here.
Stefan
diff -r a07ae36c7693 Cython/Compiler/ModuleNode.py
--- a/Cython/Compiler/ModuleNode.py Mon Jul 28 21:02:29 2008 +0200
+++ b/Cython/Compiler/ModuleNode.py Wed Jul 30 22:29:04 2008 +0200
@@ -836,8 +836,11 @@ class ModuleNode(Nodes.Node, Nodes.Block
#if need_self_cast:
# self.generate_self_cast(scope, code)
if type.vtabslot_cname:
- if base_type:
- struct_type_cast = "(struct %s*)" % base_type.vtabstruct_cname
+ vtab_base_type = type
+ while vtab_base_type.base_type and vtab_base_type.base_type.vtabstruct_cname:
+ vtab_base_type = vtab_base_type.base_type
+ if vtab_base_type is not type:
+ struct_type_cast = "(struct %s*)" % vtab_base_type.vtabstruct_cname
else:
struct_type_cast = ""
code.putln("p->%s = %s%s;" % (
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev