Skip to content

Commit

Permalink
Mark SpatialRef::from_c_obj as unsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
lnicola committed Apr 12, 2022
1 parent 492e0c8 commit a4327a9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
12 changes: 8 additions & 4 deletions CHANGES.md
Expand Up @@ -2,6 +2,14 @@

## Unreleased

- **Breaking**: Add `gdal::vector::OwnedLayer`, `gdal::vector::LayerAccess` and `gdal::vector::layer::OwnedFeatureIterator`. This requires importing `gdal::vector::LayerAccess` for using most vector layer methods.

- https://github.com/georust/gdal/pull/238

- **Breaking**: `SpatialRef::from_c_obj` is now unsafe.

- https://github.com/georust/gdal/pull/267

- Add `programs::raster::build_vrt`
- Add `GeoTransformEx` extension trait with `apply` and `invert`

Expand All @@ -11,10 +19,6 @@

- <https://github.com/georust/gdal/pull/250>

- **Breaking**: Add `gdal::vector::OwnedLayer`, `gdal::vector::LayerAccess` and `gdal::vector::layer::OwnedFeatureIterator`. This requires importing `gdal::vector::LayerAccess` for using most vector layer methods.

- https://github.com/georust/gdal/pull/238

## 0.12

- Bump Rust edition to 2021
Expand Down
8 changes: 6 additions & 2 deletions src/spatial_ref/srs.rs
Expand Up @@ -214,8 +214,12 @@ impl SpatialRef {
}
}

pub fn from_c_obj(c_obj: OGRSpatialReferenceH) -> Result<SpatialRef> {
let mut_c_obj = unsafe { gdal_sys::OSRClone(c_obj) };
/// Returns a wrapped `SpatialRef` from a raw C API handle.
///
/// # Safety
/// The handle passed to this function must be valid.
pub unsafe fn from_c_obj(c_obj: OGRSpatialReferenceH) -> Result<SpatialRef> {
let mut_c_obj = gdal_sys::OSRClone(c_obj);
if mut_c_obj.is_null() {
Err(_last_null_pointer_err("OSRClone"))
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/vector/defn.rs
Expand Up @@ -20,7 +20,7 @@ impl Defn {
/// Creates a new Defn by wrapping a C pointer
///
/// # Safety
/// This method operates on a raw C pointer
/// This method operates on a raw C pointer
pub unsafe fn from_c_defn(c_defn: OGRFeatureDefnH) -> Defn {
Defn { c_defn }
}
Expand Down Expand Up @@ -160,6 +160,6 @@ impl<'a> GeomField<'a> {
if c_obj.is_null() {
return Err(_last_null_pointer_err("OGR_GFld_GetSpatialRef"));
}
SpatialRef::from_c_obj(c_obj)
unsafe { SpatialRef::from_c_obj(c_obj) }
}
}
4 changes: 2 additions & 2 deletions src/vector/geometry.rs
Expand Up @@ -47,7 +47,7 @@ impl Geometry {
/// Set the wrapped C pointer
///
/// # Safety
/// This method operates on a raw C pointer
/// This method operates on a raw C pointer
pub unsafe fn set_c_geometry(&self, c_geometry: OGRGeometryH) {
assert!(!self.has_gdal_ptr());
assert!(!self.owned);
Expand Down Expand Up @@ -388,7 +388,7 @@ impl Geometry {
if c_spatial_ref.is_null() {
None
} else {
match SpatialRef::from_c_obj(c_spatial_ref) {
match unsafe { SpatialRef::from_c_obj(c_spatial_ref) } {
Ok(sr) => Some(sr),
Err(_) => None,
}
Expand Down
2 changes: 1 addition & 1 deletion src/vector/layer.rs
Expand Up @@ -417,7 +417,7 @@ pub trait LayerAccess: Sized {
if c_obj.is_null() {
return Err(_last_null_pointer_err("OGR_L_GetSpatialRef"));
}
SpatialRef::from_c_obj(c_obj)
unsafe { SpatialRef::from_c_obj(c_obj) }
}

fn reset_feature_reading(&mut self) {
Expand Down

0 comments on commit a4327a9

Please sign in to comment.