[Cython] RFC: an inline_ function that dumps c/c++ code to the code emitter

Stefan Behnel stefan_ml at behnel.de
Sat Aug 20 01:19:26 EDT 2016


Robert Bradshaw schrieb am 19.08.2016 um 11:36:
> On Thu, Aug 18, 2016 at 12:05 PM, Jason Newton wrote:
>> I was hoping we could give a way to drop straight into C/C++ inside of
>> Cython pyx files.
>>
>> Why?
>> [...]
>> -It works around having the Cython compiler know about all of C++'s nuances
>> - as an advanced C++ developer these are painful and it is a 2nd class
>> citizen to Cython's simpler C-support - that's no good.  Just right now I
>> was bitten by yet another template argument bug and it's clear C++ template
>> arguments have been kind of dicy since support appeared.
> 
> Yes, C++ is an extraordinarily complicated language, and exposing all
> of that would add significant amounts of complexity to Cython itself,
> and perhaps more importantly increase the barrier of entry to reading
> Cython code. One of the guiding principles is that we try to stay as
> close to Python as possible (if you know Python, you can probably read
> Cython, and with a minimal amount of C knowledge start writing it) and
> much of C++ simply isn't Pythonic.
> 
> Though, as you discovered, there are some basic things like non-type
> template arguments that we would like to have. If there are other
> specific C++ constructs that are commonly used but impossible to
> express in Cython it'd be useful to know.

Especially with respect to C++, we've always tried to make things safe and
helpful that Cython can support directly, and to make things possible that
are too complex to handle safely. But I agree with Robert that allowing
arbitrary C++ code snippets inside of Cython code is not a good idea.

If there are code constructs that we can add to improve the C++ integration
then we should do that, even if it means that Cython would (initially?) not
be able to validate that code. But we should otherwise keep the language
such that it allows us to get back to a state where Cython can validate and
understand what it sees.

Stefan



More information about the cython-devel mailing list