[gdal-dev] [gdal 3.12beta1] OGRFeature::GetDefnRef now returns a const pointer

Even Rouault even.rouault at spatialys.com
Thu Oct 23 05:20:23 PDT 2025


Le 23/10/2025 à 14:12, Momtchil Momtchev a écrit :
>
> On 23/10/2025 14:09, Even Rouault wrote:
>>
>>>
>>> Ok, if whether its me const_casting or GDAL, this does not change 
>>> the basic problem:
>>>
>>>     Is incrementing the reference counter of a const object an 
>>> allowed operation?
>>>
>> I'd say, if we were purely pedantic, no, but we might decide to 
>> derogate from that, with warnings in the documentation. I'm still 
>> undecided about the best course of action. I guess I'll talk about 
>> that in the maintainer meeting in a few miutes.
>
> What do the Python bindings do when retrieving the SRS of a Dataset? 
> Can the user keep this object beyond the lifetime of the Dataset?

- For Dataset.GetSpatialRef(), it creates a clone, so yes the returned 
SRS is independent from the Dataset

- For Layer.GetLayerDefn(), it calls OGR_FD_Reference(), so fine too here.

- For Feature.GetDefnRef(), it doesn't do anything regarding ref 
counting, which is a bug:

 >>> from osgeo import ogr
 >>> defn = ogr.FeatureDefn('foo')
 >>> f = ogr.Feature(defn)
 >>> del defn
 >>> defn = f.GetDefnRef()
 >>> print(defn.GetName())
foo
 >>> del f
 >>> print(defn.GetName())
Segmentation fault (core dumped)

-- 
http://www.spatialys.com
My software is free, but my time generally not.



More information about the gdal-dev mailing list