>> it'd be nice to have some easier way to handle C++ subclasses in >> Cython. I don't know how it should be done though. > > Good point. If we can declare inheritance information, I believe we > can use the same type infrastructure we use for cdef classes to > handle this smootly.
I second this. I have used Cython for c++ before and it worked really well, but getting the subclassing right was really a pain. As I remember it, the main issues are these: * It would be nice to be able to only declare a method once in the cdef class and that have it show up in all subclasses and to have those methods be overridable in subclasses. * It should be easy to build a Cython based object hierarchy that mirrors one in C++. * I had to re-implement methods in subclasses underlying pointer to the C++ class used to call the actual method was pointing to the wrong type (the base or the subclass, I don't remember) when you were in the subclass. You just have to be very careful about what pointer you have and what methods can be called. * This was further complicated as there isn't a way of having great control over which class in a Cython class heirarchy calls the __cinit__ method. This was a while ago, but as I recall, I couldn't get the base class __cinit__ method and the subclass __cinit__ method to play well together. Ideally, when you create a subclass, you want to allocate and hold a pointer to the subclass. But, when you need to call a method of the base class, the pointer has to be cast to the base class. I eventually figured out a super subtle way of accomplishing this, but it was nasty. I think a fantastic test case for this work would be to wrap a non-trivial c++ class hierarchy into Cython. The example doesn't have to have a ton of c++ classes, just enough to show that all the basic patterns are working (maybe 3-4 c++ classes). Ideally, such an example should also include virtual methods, abstract base classes and such. Other than having a nice template syntax, these were the main things that I ran into when using Cython with c++. But, even then, it worked super well once I figured out all the details. Another great test case would be to start wrapping the STL. If you can do that, you can do most things. Also having access to the STL from Cython would be killer! Cheers, Brian > - Robert > > > > > --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to sage-devel-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---