[gdal-dev] Gdalinfo.exe is magic, why not bindings ?

Even Rouault even.rouault at mines-paris.org
Sun Nov 27 05:58:46 EST 2011

> It seems to me that a datasource can be opened using a datasource
> (class) method or driver (object) method. Only the first tests for the
> case ds not null and error, but usually the error state is always
> checked after a call to GDAL internals in the bindings. The
> UseExceptions/DontUseExceptions methods can perhaps be used to change
> that (I'm not sure as I always have the UseExceptions on).

Indeed, the rationale for r11529 was that if UseExceptions() is on, and a 
CPLError(CE_Failure, ...) is emitted during the open procedure, SWIG will 
eventually throw a Java/Python/Perl exception but will forget to destroy the 
datasource object. Hence the need for that early cleanup.

> Change 11529 did not touch the case when such a dataset is opened with
> OGR_Dr_Open. That might still be a bug.

Yes it was. Fixed in r23428.

> In general I don't think it is a good practice to return a valid pointer
> when there is an error, and it seems impossible to get a valid object
> when using the bindings in such a case.

The issue is that the drivers might emit CE_Failure and still return a non-
NULL valid object. Perhaps a saner policy would be that if they emit 
CE_Failure, they should return a NULL pointer. And if they are able to return 
a valid non-NULL object, then the error should be just a CE_Warning. However, 
that can be fixed only by reviewing each driver code ...


More information about the gdal-dev mailing list