[Pyrex] Pyrex versus ctypes, again

Peter Brinkmann brinkman at math.TU-Berlin.DE
Fri Jul 22 12:49:47 CEST 2005



Hi,
About a year ago there was a discussion of relative merits of pyrex and
ctypes, but it didn't quite cover one issue I'm thinking about right now.

To wit, I'm considering the following problem: I'd like to have Python
bindings for a C library that stores its data in huge structures, and
an application manipulates these structures either through direct access
to their elements, or via a few convenience methods (some of which are
not C functions but macros). (Specifically, I'm talking about the ALSA
sequencer API.)

I've got a working solution already: Using ctypes, I simply build Python
shadow classes for the structs and unions that I want to work with in
Python, and I use a bit of intermediate C code that takes the macros I
need and dresses them up as functions, so that I can call them with
ctypes.

This doesn't seem like an elegant solution, though, and I'm wondering
whether I might be better off redoing this in pyrex. Now, my main concern
is that I don't see how to use pyrex to expose C structs and unions to
Python. They may appear in pyrex code, but they won't be available on
the Python side, right? 

I would like to use pyrex in this project, but if I can't get access to
C structs and unions, I'll probably have to stick to ctypes. Any thoughts
would be appreciated!
    Peter





More information about the Pyrex mailing list