Cdef function overloading or extern cppclass with cython code?

59 views
Skip to first unread message

Sour Ce

unread,
Jun 1, 2021, 3:42:47 PM6/1/21
to cython-users
Hey again guys. Hope you're doing good.

I'm trying to transition the largest class in my project from a cdef class to something that supports function overloading, like an extern cppclass.

However at least some of the methods relies on some cython code that is going to be a lot of work to reimplement in pure C++ for me.
For example cython prange code, splitting up filenames (much easier to do in Python, negligible performance differences, and the standard C/C++ library that I used for splitting up strings actually seemed to be unreliable, it usually worked most of the time, but some of the splits would be bugged), and others, not mention there's probably about 100+ functions that would all have to be rewritten in pure C++.

So I thought it would be nice to transition partially / slowly over time, and having learned that cppclasses can execute arbitrary cython code, I was hoping maybe the same would apply to extern cppclasses, but it didn't seem like it (once defined as extern it seems to rely on and only call things from the given header/C++ file).

As another option I would've thought of trying to create function loading for the class declaring it as a non-extern cppclass, but I've already tried creating a non-extern cppclass before and it doesn't seem to support function overloading.

Is there any way to create a hybrid solution here, having the option to use function overloading without having to rewrite the entire class in pure C++?
If not, any reason why this hasn't been made?
I already love being able to call cython code from a non-extern cppclass, but adding function overloading support for them or optionally allow cython code to be run from an extern C++ class would be awesome.

I guess if both are never going to be an option, my only option other than to not try to add function overloading at all is to split the class into two separate classes, declare the first one as extern and the second one as non-extern, and have the second class rely on using the first class object as a replacement for this?

Sour Ce

unread,
Jun 2, 2021, 5:21:36 PM6/2/21
to cython-users
Circumstantially found the answer about an hour later in a different question asked here on a completely different topic where the answer linked to some cython example file from the git about cdef classes which reminded me that C++ inheritance is supported, tested it out and realized I had found the answer :)
Reply all
Reply to author
Forward
0 new messages