1

Is it feasible for Cython to have the ability to translate C headers Cython-directives? (See here, in Conditional Compilation). A similar suggestion was made here too.

In my case, I would like these C-directives in my .h:

/* myheader.h */
#define MONIT_STEP      1 // stuff for step monit
//#define MONIT_SCATTERING 1 // monitor particle scattering
#define clight          (3.0*1e10)  
//#define NORM(x,y,z)  (sqrt(x*x+y*y+z*z)) // maybe this is too much to ask?

to be translated to:

# cython_header.pyx
DEF MONIT_STEP   = 1
DEF clight       = (3.0*1e10)

So that later, I can do:

include "cython_header.pyx"

in any other .pyx code I want to compile. Of course, I'm implying to have the hability to ignore any character after any "//" string in the myheader.h.

I left the NORM(x,y,z) commented as I don't see it trivial to implement, due to its "function" nature (i.e. it's not just copy-paste).

I thought I could catch the C-preprocessor with this (see Cython docs, in "Referencing C header files"):

cdef extern from "spam.h":
    pass

but doesn't work.


Of course, I can always use this method, but I'm hoping we can be more consistent.

Community
  • 1
  • 1
jimmy
  • 21
  • 5
  • Is there a reason you can't just try this? – KevinDTimm Apr 13 '17 at 16:13
  • There is no automated header translator. The method in the answer you linked right at the bottom is the right way. If you only need to use them from Cython and not Python you can just use the `cdef extern` block without re-assigning them. `NORM` can be defined as if it was a function instead of a macro. – DavidW Apr 13 '17 at 16:55
  • Ok, I was just checking if the cython compiler made any progress in this direction, since that method is from 2011. Thanks for your comments! – jimmy Apr 15 '17 at 20:21

0 Answers0