From e2bb5bd9f906915f3c6f26be531ebc9b5fdeca73 Mon Sep 17 00:00:00 2001 From: Thomas ten Cate Date: Wed, 10 Mar 2021 11:33:18 +0100 Subject: [PATCH 01/10] Fix typo in method name --- src/vector/feature.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vector/feature.rs b/src/vector/feature.rs index d29209e3..36254838 100644 --- a/src/vector/feature.rs +++ b/src/vector/feature.rs @@ -385,7 +385,7 @@ impl<'a> Feature<'a> { if rv != OGRErr::OGRERR_NONE { return Err(GdalError::OgrError { err: rv, - method_name: "OGR_G_SetGeometry", + method_name: "OGR_F_SetGeometry", }); } self.geometry[0] = geom; From 5724f7f8ca0e0f5e496474782fd719a97160503e Mon Sep 17 00:00:00 2001 From: Thomas ten Cate Date: Wed, 10 Mar 2021 14:38:22 +0100 Subject: [PATCH 02/10] Fix memory leak in Geometry::from_wkt --- CHANGES.md | 3 +++ src/vector/geometry.rs | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index a3f2444d..2a0d188c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -76,6 +76,9 @@ `SpatialRef::axis_mapping_strategy` instead. * Add support for reading and setting rasterband colour interpretations * +* Fixed memory leak in `Geometry::from_wkt` + * + ## 0.7.1 * fix docs.rs build for gdal-sys * diff --git a/src/vector/geometry.rs b/src/vector/geometry.rs index 8b3766cc..a1e34f00 100644 --- a/src/vector/geometry.rs +++ b/src/vector/geometry.rs @@ -1,7 +1,7 @@ use crate::spatial_ref::{CoordTransform, SpatialRef}; use crate::utils::{_last_null_pointer_err, _string}; use gdal_sys::{self, OGRErr, OGRGeometryH, OGRwkbGeometryType}; -use libc::{c_double, c_int, c_void}; +use libc::{c_char, c_double, c_int, c_void}; use std::cell::RefCell; use std::ffi::CString; use std::fmt::{self, Debug}; @@ -75,7 +75,9 @@ impl Geometry { /// [WKT](https://en.wikipedia.org/wiki/Well-known_text) string. pub fn from_wkt(wkt: &str) -> Result { let c_wkt = CString::new(wkt)?; - let mut c_wkt_ptr = c_wkt.into_raw(); + // OGR_G_CreateFromWkt does not write to the pointed-to memory, but this is not reflected + // in its signature (`char**` instead of `char const**`), so we need a scary looking cast. + let mut c_wkt_ptr = c_wkt.as_ptr() as *mut c_char; let mut c_geom = null_mut(); let rv = unsafe { gdal_sys::OGR_G_CreateFromWkt(&mut c_wkt_ptr, null_mut(), &mut c_geom) }; if rv != OGRErr::OGRERR_NONE { From 5362990ace9471290b0cc0ee2d071d85887b2815 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 26 Mar 2021 06:52:56 +0000 Subject: [PATCH 03/10] Update ndarray requirement from 0.14 to 0.15 Updates the requirements on [ndarray](https://github.com/rust-ndarray/ndarray) to permit the latest version. - [Release notes](https://github.com/rust-ndarray/ndarray/releases) - [Changelog](https://github.com/rust-ndarray/ndarray/blob/master/RELEASES.md) - [Commits](https://github.com/rust-ndarray/ndarray/compare/0.14.0...0.15.0) Signed-off-by: dependabot[bot] --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 9744a83d..015170e9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ thiserror = "1.0" libc = "0.2" geo-types = { version = "0.7.0" } gdal-sys = { path = "gdal-sys", version = "^0.3"} -ndarray = {version = "0.14", optional = true } +ndarray = {version = "0.15", optional = true } chrono = { version = "0.4", optional = true } bitflags = "1.2" From d56732dadc728942f79549441dbdb43a92434abd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Sat, 27 Mar 2021 20:20:40 +0200 Subject: [PATCH 04/10] Add #175 to changelog --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 2a0d188c..a0a27bc3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,8 @@ # Changes ## Unreleased +* **Breaking**: Upgrade to `ndarray 0.15` + * * Implement wrapper for `OGR_L_TestCapability` * * **Breaking**: Use `DatasetOptions` to pass as `Dataset::open_ex` parameters and From 9a3de756c9fffa1c95759af144e0976358b0a848 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 5 Apr 2021 08:39:35 +0000 Subject: [PATCH 05/10] Update bindgen requirement from 0.57 to 0.58 Updates the requirements on [bindgen](https://github.com/rust-lang/rust-bindgen) to permit the latest version. - [Release notes](https://github.com/rust-lang/rust-bindgen/releases) - [Changelog](https://github.com/rust-lang/rust-bindgen/blob/master/CHANGELOG.md) - [Commits](https://github.com/rust-lang/rust-bindgen/compare/v0.57.0...v0.58.0) Signed-off-by: dependabot[bot] --- gdal-sys/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gdal-sys/Cargo.toml b/gdal-sys/Cargo.toml index 3134e533..f16e6dfb 100644 --- a/gdal-sys/Cargo.toml +++ b/gdal-sys/Cargo.toml @@ -11,6 +11,6 @@ edition = "2018" libc = "0.2" [build-dependencies] -bindgen = { version = "0.57", optional = true } +bindgen = { version = "0.58", optional = true } pkg-config = "0.3" semver = "0.11" From 95ad64eb4520af2c69333d0efbdbe6fd10758e2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Dr=C3=B6nner?= Date: Sun, 25 Apr 2021 11:33:53 +0200 Subject: [PATCH 06/10] allow clippy::upper_case_acronyms where needed --- gdal-sys/src/lib.rs | 1 + src/vector/sql.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/gdal-sys/src/lib.rs b/gdal-sys/src/lib.rs index a38a13a8..7b5213f6 100644 --- a/gdal-sys/src/lib.rs +++ b/gdal-sys/src/lib.rs @@ -1,5 +1,6 @@ #![allow(non_upper_case_globals)] #![allow(non_camel_case_types)] #![allow(non_snake_case)] +#![allow(clippy::clippy::upper_case_acronyms)] include!(concat!(env!("OUT_DIR"), "/bindings.rs")); diff --git a/src/vector/sql.rs b/src/vector/sql.rs index 67fcc602..decd23d5 100644 --- a/src/vector/sql.rs +++ b/src/vector/sql.rs @@ -29,6 +29,7 @@ impl<'a> Drop for ResultSet<'a> { /// Represents valid SQL dialects to use in SQL queries. See /// +#[allow(clippy::upper_case_acronyms)] pub enum Dialect { /// Use the default dialect. This is OGR SQL unless the underlying driver has a native dialect, /// such as MySQL, Postgres, Oracle, etc. From 51939bb5865d52186e28f46b3cb240dc77088afd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Dr=C3=B6nner?= Date: Sun, 25 Apr 2021 11:52:18 +0200 Subject: [PATCH 07/10] fix copy paste error --- gdal-sys/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gdal-sys/src/lib.rs b/gdal-sys/src/lib.rs index 7b5213f6..8b199c5a 100644 --- a/gdal-sys/src/lib.rs +++ b/gdal-sys/src/lib.rs @@ -1,6 +1,6 @@ #![allow(non_upper_case_globals)] #![allow(non_camel_case_types)] #![allow(non_snake_case)] -#![allow(clippy::clippy::upper_case_acronyms)] +#![allow(clippy::upper_case_acronyms)] include!(concat!(env!("OUT_DIR"), "/bindings.rs")); From 47145dac994a2ed6fc2101d354c051f64244f082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Dr=C3=B6nner?= Date: Sun, 25 Apr 2021 11:58:28 +0200 Subject: [PATCH 08/10] assert_eq to assert --- src/spatial_ref/tests.rs | 12 ++++++------ src/vector/geometry.rs | 2 +- src/vector/vector_tests/mod.rs | 10 +++++----- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/spatial_ref/tests.rs b/src/spatial_ref/tests.rs index 06354017..e97276fc 100644 --- a/src/spatial_ref/tests.rs +++ b/src/spatial_ref/tests.rs @@ -58,10 +58,10 @@ fn comparison() { let spatial_ref4 = SpatialRef::from_proj4("+proj=longlat +datum=WGS84 +no_defs ").unwrap(); let spatial_ref5 = SpatialRef::from_esri("GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]]").unwrap(); - assert_eq!(true, spatial_ref1 == spatial_ref2); - assert_eq!(false, spatial_ref2 == spatial_ref3); - assert_eq!(true, spatial_ref4 == spatial_ref2); - assert_eq!(true, spatial_ref5 == spatial_ref4); + assert!(spatial_ref1 == spatial_ref2); + assert!(spatial_ref2 != spatial_ref3); + assert!(spatial_ref4 == spatial_ref2); + assert!(spatial_ref5 == spatial_ref4); } #[test] @@ -155,7 +155,7 @@ fn failing_transformation() { let trafo = CoordTransform::new(&wgs84, &dhd_2).unwrap(); let r = trafo.transform_coords(&mut x, &mut y, &mut z); - assert_eq!(r.is_err(), true); + assert!(r.is_err()); let wgs84 = SpatialRef::from_epsg(4326).unwrap(); let webmercator = SpatialRef::from_epsg(3857).unwrap(); @@ -174,7 +174,7 @@ fn failing_transformation() { let trafo = CoordTransform::new(&wgs84, &webmercator).unwrap(); let r = trafo.transform_coords(&mut x, &mut y, &mut z); - assert_eq!(r.is_err(), true); + assert!(r.is_err()); if let GdalError::InvalidCoordinateRange { .. } = r.unwrap_err() { // assert_eq!(msg, &Some("latitude or longitude exceeded limits".into())); } else { diff --git a/src/vector/geometry.rs b/src/vector/geometry.rs index a1e34f00..72d5bd94 100644 --- a/src/vector/geometry.rs +++ b/src/vector/geometry.rs @@ -48,7 +48,7 @@ impl Geometry { /// This method operates on a raw C pointer pub unsafe fn set_c_geometry(&self, c_geometry: OGRGeometryH) { assert!(!self.has_gdal_ptr()); - assert_eq!(self.owned, false); + assert!(!self.owned); *(self.c_geometry_ref.borrow_mut()) = Some(c_geometry); } diff --git a/src/vector/vector_tests/mod.rs b/src/vector/vector_tests/mod.rs index 3fc81ea5..04961749 100644 --- a/src/vector/vector_tests/mod.rs +++ b/src/vector/vector_tests/mod.rs @@ -70,11 +70,11 @@ fn test_layer_capabilities() { let mut ds = Dataset::open(fixture!("roads.geojson")).unwrap(); let layer = ds.layer(0).unwrap(); - assert_eq!(layer.has_capability(OLCFastSpatialFilter), false); - assert_eq!(layer.has_capability(OLCFastFeatureCount), true); - assert_eq!(layer.has_capability(OLCFastGetExtent), false); - assert_eq!(layer.has_capability(OLCRandomRead), true); - assert_eq!(layer.has_capability(OLCStringsAsUTF8), true); + assert!(!layer.has_capability(OLCFastSpatialFilter)); + assert!(layer.has_capability(OLCFastFeatureCount)); + assert!(!layer.has_capability(OLCFastGetExtent)); + assert!(layer.has_capability(OLCRandomRead)); + assert!(layer.has_capability(OLCStringsAsUTF8)); } fn ds_with_layer(ds_name: &str, layer_name: &str, f: F) From b575aee147a1ef859c306795a2a37d5df2298cb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Dr=C3=B6nner?= Date: Sun, 25 Apr 2021 12:03:25 +0200 Subject: [PATCH 09/10] more upper_case_acronyms --- src/vector/layer.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/vector/layer.rs b/src/vector/layer.rs index 870304d5..f41abece 100644 --- a/src/vector/layer.rs +++ b/src/vector/layer.rs @@ -14,6 +14,7 @@ use std::{convert::TryInto, ffi::CString, marker::PhantomData}; use crate::errors::*; /// Layer capabilities +#[allow(clippy::upper_case_acronyms)] pub enum LayerCaps { /// Layer capability for random read OLCRandomRead, From b81ba0b44e75b04881398282d90dec89630d7ca7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Dr=C3=B6nner?= Date: Sun, 25 Apr 2021 12:18:14 +0200 Subject: [PATCH 10/10] use allowlist_function --- gdal-sys/build.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gdal-sys/build.rs b/gdal-sys/build.rs index e75c71c6..21d82f62 100644 --- a/gdal-sys/build.rs +++ b/gdal-sys/build.rs @@ -13,12 +13,12 @@ pub fn write_bindings(include_paths: Vec, out_path: &Path) { .header("wrapper.h") .constified_enum_module(".*") .ctypes_prefix("libc") - .whitelist_function("CPL.*") - .whitelist_function("GDAL.*") - .whitelist_function("OGR.*") - .whitelist_function("OSR.*") - .whitelist_function("OCT.*") - .whitelist_function("VSI.*"); + .allowlist_function("CPL.*") + .allowlist_function("GDAL.*") + .allowlist_function("OGR.*") + .allowlist_function("OSR.*") + .allowlist_function("OCT.*") + .allowlist_function("VSI.*"); for path in include_paths { builder = builder.clang_arg("-I");