[Prophesy] C from Python Example

Daniel Phillips phillips at bonn-fries.net
Wed Jun 12 01:31:55 EST 2002


On Tuesday 11 June 2002 07:48, Rasmus Andersen wrote:
> On Mon, Jun 10, 2002 at 11:33:18PM +0200, Rasmus Andersen wrote:
> > I have before used SWIG (www.swig.org) sucessfully as C/Python integrator.
> > The v1.3 (newest, I think) I had on my system choked on some of your
> > C constructs, using the attached patch helped.

Yes, it seems swig's parser has fallen a little bit behind and I suppose a
bug report to the project would be in order.

/me puts it on his list of things to do sometime

In the meantime your fix is fine.

> > Also, I had to use an interface file to get SWIG to grok other stuff.
> > Also attached.

Swig is very clearly a quick way to get started on constructing an
interface like this and I would have used it if I'd known about it.
(I did see swig mentioned a few times as I searched for documentation,
but mainly in the context of interfacing Python to C++, so that put
me off the scent.

There's a lot of knowledge encoded in the swig interface generators
that could be time consuming to acquire by other means.  For this
project I'd tend towards treating swig as more of a kind of tutorial 
that an essential build tool, since the Python/C interface is quite 
straightforward once you work out the basics, like where to find the
documentation and what's required to compile and link.  I do intend
to run swig from time to time to compare what it thinks is essential
for an interface, versus what I come up with from reading the docs.

OK... I just generated a swig python wrapper from your .i file...
Woohoo!  Over a thousand lines of wrapper, more than 3 times the size
of the project so far, and the generated code is 8 times the size. 
Well, I guess that's the problem with program-writing programs in
general.  By studying the wrapper I'm sure there are useful things to
learn, but I think it's easy enough to generate the Python wrappers
by hand, as needed.  Of course, that means being attentive and
worrying about things like object ref counts and locking, but these
are good to know about anyway.

Swig-friendly transform.c attached.

-- 
Daniel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: transform.c
Type: text/x-c
Size: 7761 bytes
Desc: not available
URL: <http://lists.ozlabs.org/pipermail/prophesy/attachments/20020611/fbb50a6e/attachment.bin>


More information about the Prophesy mailing list