[gdal-dev] some problem in python bindings

Howard Butler hobu.inc at gmail.com
Thu May 20 10:04:02 EDT 2010


On May 20, 2010, at 7:48 AM, Vincent Schut wrote:

> Hi,
> 
> since some time (I don't know exactly since when, but I regularly update gdal from svn and I don't remember this happening earlier), there is a problem with the python swig bindings when doing this:
> 
> data = gdal_array.BandReadAsArray(gdal.Open(filename).GetRasterBand(1))
> 
> instead of this:
> 
> ds = gdal.Open(filename)
> data = gdal_array.BandReadAsArray(ds.GetRasterBand(1))
> 
> The first version gives me a segfault, the second works OK. Probably some refcounting issue?

In the first one, the rasterband is fetched, but the dataset that owns it immediately goes out of scope and doesn't know that it needs to stay alive due to the rasterband fetch.  This is a consequence of the Python bindings historically expecting users to manage their own memory.  If operation chaining such as the first one works, it's a happy circumstance, but don't expect it to work always or even in most cases.  As to whether or not we fix it, I think yes, we'll take a patch if it's proven to work. 

Howard


More information about the gdal-dev mailing list