[Gdal-dev] Next Generation Language Binding News

Howard Butler hobu at iastate.edu
Fri Aug 5 18:10:06 EDT 2005


Kevin Ruland and myself (well, Kevin mostly) have been working on the next 
generation bindings for GDAL.  These new bindings take advantage of new 
features in SWIG 1.3.25.  Most importantly, this development provides the 
architecture for supporting more languages than the current Python and VB 
bindings.  This post will describe the work that has been going on, what is 
yet to be done, and how we need your help.

Work that has gone on
------------------------------------

Current Python bindings for GDAL are generated with SWIG 1.1, with a lot of 
hand rolling of code by Frank.  They work great, but the development is not 
sustainable when you start factoring in the desire to have more than Python 
be supported.  In addition, migrating these bindings from 1.1 to 1.3 SWIG 
is difficult because Frank had to do a lot of swig voodoo to get what he 
needed.

In February, Kevin and myself started working on new SWIG definition files, 
in a similar fashion to MapScript, that provide a fully backward-compatible 
Python interface and provide the architecture to support more language 
bindings in a more automated way.  The ng Python bindings were in a 
reasonable state just before the OSGIS conference and throughout the spring 
I worked on C# bindings.

In addition, Kevin, heavyweight that he his, tore into SWIG itself to make 
it support PHP better and bring SWIG PHP support to the same level as many 
of the other languages in SWIG specifically for the development of PHP GDAL 
wrappers.  These updates are expected to be available in an upcoming SWIG 
release...

Where we're at now
--------------------------------

So, to recap where we're at, ng Python bindings are backward compatible 
(however lightly tested) with existing Python bindings, C# has bindings 
that are about 90% of the way there, and PHP bindings are on the 
horizon.  Now I'm going to explain what has yet to be done.

1.  SWIG is a fantastic, if arcane, tool that allows you to auto-generate 
code to bind C/C++ to one of its supported langauges.  There are a few 
gotchas with SWIG though.  First, not all of the concepts in every language 
transfers easily to other languages.  For example, things like default 
arguments, common in Python don't translate to Java.  Module-level 
variables, common in C/C++, Python and others, don't work in C#.  Second, 
the types in one language (C/C++, for example) cannot be automagically 
coerced into the types of another language (list of strings in C#, for 
example).  SWIG has a system called typemaps that a programmer must use to 
provide definitions for how SWIG is to make these kinds of coercions.  So, 
while SWIG gets you through the boring 90% of generating the bindings, 
there's still a really messy 10% that has to be done.

2.  ng Python bindings have almost all of the their typemaps done, past 
most of the gdalautotest suite of tests, and seem to be working pretty 
well.  I have used these fairly extensively.  It is important that they are 
widely tested before we attempt to replace the current Python bindings with 
these, however.

3.  ng C# bindings are 90% of the way there.  The build environment exists, 
C# and C/C++ dlls are created as expected, and you can import everything 
into Visual Studio .NET and use them some.  It's that last 10% that is the 
killer though.  There are *no* typemaps beyond the stock SWIG ones.  This 
means you can't return a list of GeoTransform variables... instead you just 
get back a pointer to it.

4.  Some PHP typemaps exist, and I can let Kevin explain things further, 
but an updated SWIG with Kevin's improvements isn't available yet, so these 
are a ways off.

5.  Charlie Savage has been playing around with working up Ruby 
bindings.  I'll let him comment on how much progress has been made.

6.  No Java, Perl or TCL bindings have been attempted.  Java users could 
use the C# bindings as a template -- adding in typemaps  specific to Java 
where needed.  Perl and TCL users might use the Python bindings as a template.

How we need your help
-----------------------------------

We need developers who have expertise in their pet language's C/C++ 
API.  For C#, this is the PINVOKE mechanism.  For Python, it is the Python 
C API.  For Java, it is JNI.  And so on.  There is some typemap code for 
individual languages in MapScript that might be useful as a guide.  Without 
the typemaps, your language will be a second class citizen ... you'll have 
primitive bindings, but you won't be able to do everything you want.  This 
situation is still better than where you might have been before the ng 
development -- hand-rolling bindings entirely by yourself.

To reiterate, if you are a Python GDAL user, please test the ng bindings in 
the upcoming 1.3 beta.  They are located under swig/python.  C# users might 
grab a copy of SWIG 1.3.25 from Sourceforge and build up C# bindings with 
the makefile.vc that exists in swig/csharp.  Anyone else who has a language 
not mentioned should check out the stuff in the swig directory and see how 
they might make SWIG generate what they need.

Howard 




More information about the Gdal-dev mailing list