[gdal-dev] Bindings and typemaps

Ari Jolma ari.jolma at gmail.com
Sun Mar 8 14:20:50 PDT 2015


Even,

It took me quite a while again to understand what goes on with Swig when 
we %apply a typemap etc.

I think we could simplify the things quite a lot if we simply use 
typedefs and then create typemaps for the return values.

For example CPLErr is never returned to the calling language (I think, 
but it could in any case be defined by the language typemap), thus we 
could simply define typemaps for it in language specific files instead 
of repeating

%apply (IF_ERROR_RETURN_NONE) { (CPLErr) };
...
%clear (CPLErr);

in the include/*.i files.

Also sometimes GDAL has simple int instead of CPLErr, which is used as a 
success/failure return value, then we could (like we already do) write

typedef int RETURN_NONE;

(actually we have also

typedef int OGRErr;

for SWIGCSHARP, which is invented for the same reason I assume)

and then define typemaps for the new type and skip again

%apply (IF_FALSE_RETURN_NONE) { (RETURN_NONE) };
...
%clear (RETURN_NONE);

which is overkill (and I believe I introduced that).

BTW, RETURN_NONE is not a good name, maybe use TRUE_OR_FALSE or 
something more descriptive.

Best,

Ari



More information about the gdal-dev mailing list