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

34 views
Skip to first unread message

Jason Newton

unread,
Aug 18, 2016, 2:13:03 AM8/18/16
to cython-users
Following up from a github opened issue here:

https://github.com/cython/cython/issues/1440

I was hoping we could give a way to drop straight into C/C++ inside of Cython pyx files.

Why?

-It [helps] avoid needing to declare every class/function in cython, a somewhat daunting/impossible task that I think everyone hates.  Have you seen Eigen?
-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.
-It would allow single source files - I think this is important for runtime compiled quasi-JIT/AOC fragments, like OpenCL/PyOpenCL/PyCUDA provide

The idea is that Cython glue makes the playing field for extracting data easy, but that once it's extracted to a cdef variable for instance, cython doesn't need to know what happens.  Maybe in a way sort of like the GCC asm extension.  Hopefully simpler variable passing though.

The alternative to not having this construct is a concrete wall.  I'll have to segment up files for C++ for the rest of time until I get function forms that Cython can handle. At that point I just say screw it and use boost python.  Of course cython does the definitions, data extraction, and compilation so much easier than boost.python.  It would be a shame to not consider this plight C++ developers have been cornered into.

I did some examination of how this could be implemented - my idea was to base on the print/exec statements handling and simply emit their arguments from the Nodes to the code generator.  Proposing inline_c or inline_ as the statement.  Such a statement could be used to do macros, pull in includes, and modify/declare c-variables.

-Jason

Robert Bradshaw

unread,
Aug 19, 2016, 5:38:54 AM8/19/16
to cython...@googlegroups.com
Discussion moved to
https://mail.python.org/pipermail/cython-devel/2016-August/004900.html
> --
>
> ---
> 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.
Reply all
Reply to author
Forward
0 new messages