Commit cd40d9e7 authored by Claude Paroz's avatar Claude Paroz
Browse files

Fixed #25657 -- Ignored exceptions when destroying geometry objects

Due to randomness of garbage collection with geometry objects, it's
easier to simply ignore AttributeError/TypeError generally raised when
parts of objects are already garbage-collected.
Thanks Sergey Fedoseev and Tim Graham for reviewing the patch.
parent ec708803
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -87,8 +87,10 @@ class DataSource(GDALBase):

    def __del__(self):
        "Destroys this DataStructure object."
        if self._ptr and capi:
        try:
            capi.destroy_ds(self._ptr)
        except (AttributeError, TypeError):
            pass  # Some part might already have been garbage collected

    def __iter__(self):
        "Allows for iteration over the layers in a data source."
+3 −1
Original line number Diff line number Diff line
@@ -29,8 +29,10 @@ class Feature(GDALBase):

    def __del__(self):
        "Releases a reference to this object."
        if self._ptr and capi:
        try:
            capi.destroy_feature(self._ptr)
        except (AttributeError, TypeError):
            pass  # Some part might already have been garbage collected

    def __getitem__(self, index):
        """
+3 −1
Original line number Diff line number Diff line
@@ -121,8 +121,10 @@ class OGRGeometry(GDALBase):

    def __del__(self):
        "Deletes this Geometry."
        if self._ptr and capi:
        try:
            capi.destroy_geom(self._ptr)
        except (AttributeError, TypeError):
            pass  # Some part might already have been garbage collected

    # Pickle routines
    def __getstate__(self):
+3 −1
Original line number Diff line number Diff line
@@ -131,8 +131,10 @@ class GDALRaster(GDALBase):
            raise GDALException('Invalid data source input type: "{}".'.format(type(ds_input)))

    def __del__(self):
        if self._ptr and capi:
        try:
            capi.close_ds(self._ptr)
        except (AttributeError, TypeError):
            pass  # Some part might already have been garbage collected

    def __str__(self):
        return self.name
+6 −2
Original line number Diff line number Diff line
@@ -96,8 +96,10 @@ class SpatialReference(GDALBase):

    def __del__(self):
        "Destroys this spatial reference."
        if self._ptr and capi:
        try:
            capi.release_srs(self._ptr)
        except (AttributeError, TypeError):
            pass  # Some part might already have been garbage collected

    def __getitem__(self, target):
        """
@@ -341,8 +343,10 @@ class CoordTransform(GDALBase):

    def __del__(self):
        "Deletes this Coordinate Transformation object."
        if self._ptr and capi:
        try:
            capi.destroy_ct(self._ptr)
        except (AttributeError, TypeError):
            pass

    def __str__(self):
        return 'Transform from "%s" to "%s"' % (self._srs1_name, self._srs2_name)
Loading