[Cython] setting C++ mode in cythonize()

Matthew Honnibal honnibal at gmail.com
Sat Oct 4 15:37:23 CEST 2014



On Friday, 3 October 2014 17:27:54 UTC+10, Stefan Behnel wrote:
>
> Hi, 
>
> the documentation suggests to pass language='c++' into cythonize() to 
> globally enable C++ mode, but AFAICT, this never actually worked. Cython 
> previously ignored this option, Cython 0.21 rejects it, and we didn't 
> update the docs, so the current situation is outright confusing. 
>
>
> http://docs.cython.org/src/userguide/wrapping_CPlusPlus.html#specify-c-language-in-setup-py 
>
>
Thanks for this. Cython's a big project that's been changing fast, and as a 
user I've often found the docs a bit lacking.

For instance, I wanted to use language="c++" for pyximport, and had some 
trouble doing so. I found this answer on StackOverflow:

https://stackoverflow.com/questions/7620003/how-do-you-tell-pyximport-to-use-the-cython-cplus-option

It recommends the use of a "foo.pyxbld" file, in the same directory as 
"foo.pyx", which pyximport will read for options. I tried it, and it does 
indeed work. This blew me away --- I'm fairly sure it's never mentioned in 
the docs, and it left me with many questions...

My main question is: is this actually the recommended solution? Or is it 
there for historical reasons, e.g. via Pyrex?
 

> To me, this option seems the one obvious way to do it, as it mimics the 
> distutils Extension API most closely. So, I now implemented support for 
> this, but only for modules found by file name, not for user provided 
> Extension objects. I think that's a reasonable restriction. If users 
> construct their own Extension instances anyway, they can just as well set 
> the 'language' option on them directly (and probably already do so). 
>
>
> https://github.com/cython/cython/commit/88df97f250073d8a06f965d6a7e09d8fe6f4ca63 
>
> Stefan 
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cython-devel/attachments/20141004/f2d2f12e/attachment.html>


More information about the cython-devel mailing list