On Oct 22, 2008, at 10:46 AM, Brian Granger wrote: > This is sort of a separate issue than these others.... > > I have spent a good amount of time hand wrapping C++ classes using > cython. The big thing that you quickly run into is the difficulty in > handling inheritance. More specifically, you would like your c++ > class hierarchy to be reflected and mirrored in the Cython class > hierarchy. > > Have you looked into these issues yet? It has been a few months, so > my mind is not fresh on this stuff, but it was quite subtle and I > don't think I ever got to a point of having a solution that we really > satisfactory.
This is a very good issue to bring up, and though I don't see us coming up with a good full-blown solution right away, whatever we do end up doing should be extensible to this kind of thing in the future. > What I do remember: > > * There were problems getting superclass methods in Python callable by > sub classes because the pointer types were different. On the technical side, the infrastructure is there to say "this (pointer) type is a subtype of that" but no way yet to expose it to Cython. > * Performing dynamic memory allocations, etc. in __cinit__ is > difficult because subclasses might need to do this differently. For > example a subclass would want to hold a pointer to the C++ subclass, > not a pointer to the subclass. The calling conventions of __cinit__ > in Cython make this really tough to handle this. > > I am curious if you or others have made progress in figuring this > stuff out? I personally don't know enough C++ to know the ins and outs of all of this, but certainly things could be made easier. If I remember right, for some of the C++ wrappings in Sage (e.g. NTL) we were able to store the class data itself as part of the struct (rather than requiring a second alloc) but this obviously wouldn't play well with subclasses (which happened to be less important than speed for that particular use case). - Robert _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
