[Gdal-dev] Testing arguments in the swig-bindings

Ari Jolma ari.jolma at tkk.fi
Wed Aug 29 06:18:28 EDT 2007


Frank Warmerdam wrote:
>
> For the many string arguments that are required to be non-NULL,
> can we have a swig typemap for "non-null-string" arguments
> to catch this?

For example for MajorObject.SetDescription this would be (the %apply and 
%clear):

  %apply (char *non_null_input) {const char *pszNewDesc};
  void SetDescription( const char *pszNewDesc ) {
    GDALSetDescription( self, pszNewDesc );
  }
  %clear const char *pszNewDesc;

and the actual typemap in the Perl case would be

%typemap(in) (char *non_null_input)
{
  /* %typemap(in) (char *non_null_input) */
  if (!$1) {
    croak("argument must not be null");
    SWIG_fail; 
  }
}

This simple typemap could perhaps be language-independent, I don't know.

Since introduction of new typemaps need to be done in concert for all 
bindings, we need some kind of procedure. Any ideas for this? Two things 
need to be agreed: 1) do we need this typemap 2) where we will apply it.

Ari





More information about the Gdal-dev mailing list