[Cython] Simple class hierarchy problems

Lisandro Dalcin dalcinl at gmail.com
Fri Jul 25 22:25:51 CEST 2008


I believe you are not missing anything, It's just a bug in Cython !!.

The following patch (also attached) against cython-devel repo seems to
fix the problem. Of course, perhaps the patch is not completely OK
because I'm missing something about the implementation of virtual
tables.


--- a/Cython/Compiler/ModuleNode.py	Wed Jul 23 23:02:37 2008 -0700
+++ b/Cython/Compiler/ModuleNode.py	Fri Jul 25 17:18:04 2008 -0300
@@ -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:
+                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;" % (



On Wed, Jul 23, 2008 at 6:26 PM, Brian Granger <ellisonbg.net at gmail.com> wrote:
> Hi,
>
> The following code is giving me problems:
>
> # foo.pyx
> cdef class Foo:
>
>    cdef fooit(self):
>        return 10
>
> cdef class Bar(Foo):
>    pass
>
> cdef class Bam(Bar):
>    pass
>
> When I do "cython foo.pyx" and compile as c I get a warning:
>
> foo.c: In function '__pyx_tp_new_3foo_Bam':
> foo.c:608: warning: assignment from incompatible pointer type
>
> But, when I do "cython --cplus" and compile with c++ I get a failure:
>
> foo.cpp: In function 'PyObject* __pyx_tp_new_3foo_Bam(PyTypeObject*,
> PyObject*, PyObject*)':
> foo.cpp:608: error: cannot convert '__pyx_vtabstruct_3foo_Bar*' to
> '__pyx_vtabstruct_3foo_Foo*' in a
>
> I swear this code used to work fine.  I am using Cython 0.9.8, but the
> problem is there if I try it in earlier versions.
>
> What am I missing?
>
> Thanks
>
> Brian
> _______________________________________________
> Cython-dev mailing list
> Cython-dev at codespeak.net
> http://codespeak.net/mailman/listinfo/cython-dev
>



-- 
Lisandro Dalcín
---------------
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vtab.diff
Type: text/x-patch
Size: 833 bytes
Desc: not available
Url : http://codespeak.net/pipermail/cython-dev/attachments/20080725/c49d7741/attachment-0001.bin 


More information about the Cython-dev mailing list