cython-codegen: cython code generator from gccxml files

I have enjoyed using cython to wrap from C libraries recently. Unfortunately, some libraries I was interested in (Alsa, CoreAudio) are quite big. In particular, they have a lot of structures, typedefs and enumerations which are easy to get wrong by doing it manually. Since the problem is quite similar to wrapping with ctypes (my former method of choice), I thought it would be interesting to do something like ctypeslib code generator for cython – hencecython-codegen “project”, available on github:

http://github.com/cournape/cython-codegen

Basic usage goes like this to generate a .pyx file for the foo.h header:

gccxml -I. foo.h -o foo.xml
xml2cython.py -l 'foo' foo.h foo.xml

I can’t stress enough that this is little more than a throw-away script, and is likely to fail on many header files, or generate invalid cython code. I could use it successfully on non trivial headers though, like alsa or CoreAudio on Mac OS X. Your mileage may vary.

About these ads

Posted in python

Tags:

Permalink 2 Comments

2 responses to “cython-codegen: cython code generator from gccxml files

  1. lavanya

    I am looking for using cython to wrap c library. It seems you tried this, could you give some more details on how to use this tool, to write cython specific files.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

December 2008
M T W T F S S
« Oct   Feb »
1234567
891011121314
15161718192021
22232425262728
293031  

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 9 other followers

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: