3 ms·
I don't see why you would use Cython when you are writing C/C++ anyway. All the trivial data types and wrappers are easily handled by SWIG. Just don't try to wr
by Matumio 11y ago
I don't see why you would use Cython when you are writing C/C++ anyway. All the trivial data types and wrappers are easily handled by SWIG. Just don't try to wrap any non-trivial types with SWIG, instead declare them as `PyObject *` and use the Python/C API for those. Demo of this technique: https://github.com/martinxyz/python/tree/master/realistic https://github.com/martinxyz/python/tree/master/realistic
- versteegen 11y agoThe main advantage of using Cython for glue code is that you don't need to touch the Python/C API, it generates the necessary code for you (in particular it handles the reference counting). (I like to think of Cython as 'C with easy access to the Python runtime'.) However, the API certainly doesn't look scary in these examples (I've never really used it). Admittedly I didn't consider SWIG, so thanks for that. It would be nice to be rid of the Cython glue layer, so I might try that. Of course that would mean writing much of the glue (sanity checking) in C++ or Python instead of Cython.