[Pyrex] Generating a header?

Andreas Fredriksson deplinenoise at gmail.com
Wed Dec 27 20:18:28 UTC 2006


Hi folks,

I've just started playing with Pyrex and I'm wondering if it would be
feasible to generate a header from a cdef block.

I'm designing a little application where I'm writing a bunch of native
modules to be used to construct the application in Python. I don't
have anything to wrap since I'm starting a fresh project, so it would
make sense for me to

1) Write a pyx specification for some module,
2) Have the header file generated,
3) Implement the functions declared in said header file in C.

Maybe a slight syntax adaptation could work:

cdef extern into "foo.h":
     ctypedef struct my_opaque_t:
              pass
     my_opaque_t *opaque_create()
     void opaque_destroy(my_opaque_t *self)

"into" would behave as "from", except that it would also capture the
declarations and store them away so that they can be emitted to a
header file later on.

I realize that some declarations wouldn't work, but it's better than
repeating myself in two places. The rest of the pyx file could then
concern itself with presenting these functions to the Python world
(probably using classes) where the C files could include "foo.h" and
implement the functions.

Do you think something like this might work?

// Andreas



More information about the Pyrex mailing list