[Cairo] another set of Python bindings

Maarten Breddels dmon at xs4all.nl
Fri Sep 12 05:22:30 PDT 2003


>  From my experiences, SWIG is suboptimal for wrapping "object 
> oriented 
> C" APIs.  It leaves you with a direct procedural binding of the C 
> functions, and then you need to build something on top to get 
> a binding 
> more appropriate to the language.  In addition, you would 

Yup, that's the way I'd like to see it

> probably need 
> _different_ SIWG .i files for each of those languages, since 
> the .i file 
> generally has language specific annotations.

Not anymore, newstyle typemaps are in the following format:
	%typemap(python, out) char*  {
		$result = PyString_FromStringAndSize($1, arg1);
	} 
So you can write typemaps for any language, and generate the Python and 
Ruby binding using 1 SWIG file

> 
> I guess I am a bit biased though, since I had some bad 
> experiences with 
> SWIG when I was first working on PyGTK (it quickly became 
> unmaintainable).  The problems may not be as bad for Cairo 
> though, since 
> its API is much smaller by several orders of magnitude.

Well, having a binding for C#/Java/Ruby/Perl in 1 SWIG file can
be a good reason for using SWIG. But I can't say SWIG is that easy
to work with.

> It would be good to work towards a single binding though.  My main 
> requirement for such a binding is that I can use it as a 
> dependency for 
> pygtk at some point in the future (when GTK depends on Cairo).  Being 
> usable with from PyGTK programs right now would be nice too.

Well, I'd rather keep the bindings simple, and not putting any binding
to
GTK, PIL or wxWindows in the cairobinding itself. It makes the Cairo
binding clean,
and without a lot of dependencies. If you do it in Python, you can
provide for 
example, a Python module which uses wxPython, but doesn't require it. It
will
simple give an import error in Python, and not a missing dll/lib when 
linking or importing.
For example, a Java binding doesn't really want binding to all of these,
just 
some CairoPanel on which to dump the raw image.

Btw, I believe your binding doesn't wrap cairo_surface_create_for_image,

I do it by using a Python string ("\0" * height * stride) as a buffer,
I don't know if this is valid, since I believe Python strings are
immutable.






More information about the cairo mailing list