Discussion:
setting C++ mode in cythonize()
Stefan Behnel
2014-10-03 07:27:48 UTC
Permalink
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

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
--
---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Matthew Honnibal
2014-10-04 13:37:23 UTC
Permalink
Post by Stefan Behnel
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?
Post by Stefan Behnel
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
--
---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Björn Dahlgren
2014-10-07 10:58:07 UTC
Permalink
Post by Matthew Honnibal
For instance, I wanted to use language="c++" for pyximport, and had some
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?
I've never see nthat either. I think it would be great if pyximport looks
for lines like:

# distutils: language = c++

in the pyx file.
--
---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...