Skip to content

Commit

Permalink
Merge pull request #77 from GuillaumeGomez/big-update
Browse files Browse the repository at this point in the history
Update to geos-sys 2.0 and fix multiple issues
  • Loading branch information
GuillaumeGomez authored Jul 29, 2020
2 parents aa5cfac + ce62460 commit f014049
Show file tree
Hide file tree
Showing 23 changed files with 3,054 additions and 2,627 deletions.
28 changes: 25 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: rust

dist: xenial
dist: groovy

rust:
- stable
Expand All @@ -13,14 +13,33 @@ matrix:

before_install:
- sudo apt-get update
- sudo apt-get install libgeos-dev libgdal-dev valgrind
- sudo apt-get install valgrind
- sudo apt-get remove libgeos-dev -y

script:
# First we install the 3.8 version of libgeos
- git clone https://github.com/libgeos/geos
- cd geos
# checking out 3.8.1 version
- git checkout 24650422b3982f17cc493fe92a70228f2ad624b4
- ./autogen.sh
- ./configure
- make
- sudo make install
- sudo ldconfig
- cd ..
- export LD_LIBRARY_PATH=/usr/local/lib
# Now we can run tests
- cargo build
- cargo build --features v3_8_0
- cargo build --features v3_7_0
- cargo build --features v3_6_0
- cargo test --features v3_8_0
- cargo test --features v3_7_0
- cargo test --features v3_6_0
- cargo test --features geo
- cargo test --features json
- cargo test --features 'v3_8_0,geo,json'
- cargo test
- cargo doc --features dox
- cargo doc
Expand All @@ -31,7 +50,10 @@ script:
- cargo run --features geo --example from_geo
# run valgrind to check that there are no memoryleaks
# Note: cargo seems to randomly name the executable, so we use find to find all the tests
- find ./target/debug/deps -name "geos*" -type f -executable | xargs -n 1 valgrind --leak-check=full --error-exitcode=42
#
# As long as leaks come from "geos::geom::GeometryFactory::getDefaultInstance", then
# it's fine (singleton).
- find ./target/debug/deps -name "geos*" -type f -executable | xargs -n 1 valgrind --leak-check=full --error-exitcode=42 --show-leak-kinds=all
- valgrind --leak-check=full --error-exitcode=42 ./target/debug/examples/from_geo
- valgrind --leak-check=full --error-exitcode=42 ./target/debug/examples/verbose_example
- valgrind --leak-check=full --error-exitcode=42 ./target/debug/examples/prepared_geom
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "geos"
version = "5.0.0"
version = "6.0.0"
authors = ["Matthieu Viry <[email protected]>", "Adrien Matissart <[email protected]>", "Antoine Desbordes <[email protected]>", "Guillaume Pinot <[email protected]>", "Guillaume Gomez <[email protected]>"]
license = "MIT"
repository = "https://github.com/georust/geos"
Expand All @@ -21,10 +21,10 @@ dox = ["geo-types", "wkt", "json"]
libc = "0.2"
num = "0.2"
c_vec = "1.3"
geojson = { version = "0.17", optional = true }
geojson = { version = "0.19", optional = true }
geo-types = { version = "0.4", optional = true }
wkt = { version = "0.5", optional = true }
geos-sys = "1.0"
geos-sys = "2.0"
doc-comment = "0.3"

[package.metadata.docs.rs]
Expand Down
5 changes: 2 additions & 3 deletions examples/from_geo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use geo_types::{Coordinate, LineString, Polygon};
#[cfg(feature = "geo")]
use geos::from_geo::TryInto;
#[cfg(feature = "geo")]
use geos::{Error, Geometry};
use geos::{Error, Geom, Geometry};

#[cfg(feature = "geo")]
fn fun() -> Result<(), Error> {
Expand Down Expand Up @@ -45,8 +45,7 @@ fn main() {
fun().unwrap();
}


#[cfg(not(feature = "geo"))]
fn main() {
eprintln!("You need to enable the \"geo\" feature to run this example!", );
eprintln!("You need to enable the \"geo\" feature to run this example!",);
}
6 changes: 3 additions & 3 deletions examples/prepared_geom.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(feature = "geo")]
extern crate geos;
#[cfg(feature = "geo")]
use geos::{version, Error, Geometry, PreparedGeometry};
use geos::{version, Error, Geom, Geometry, PreparedGeometry};

#[cfg(feature = "geo")]
fn fun() -> Result<(), Error> {
Expand All @@ -24,7 +24,7 @@ fn fun() -> Result<(), Error> {
Geometry::new_from_wkt("POINT (0.4 4.1)").unwrap(),
];
for geom in &vec_geoms {
print!("{:?} ", pg1.intersects(&geom)?);
print!("{:?} ", pg1.intersects(geom)?);
}
println!("");
Ok(())
Expand All @@ -37,5 +37,5 @@ fn main() {

#[cfg(not(feature = "geo"))]
fn main() {
eprintln!("You need to enable the \"geo\" feature to run this example!", );
eprintln!("You need to enable the \"geo\" feature to run this example!",);
}
7 changes: 5 additions & 2 deletions examples/verbose_example.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
extern crate geos;
use geos::{version, Error, Geometry};
use geos::{version, Error, Geom, Geometry};

fn fun() -> Result<(), Error> {
println!("geos_c version: {}", version().expect("failed to get version"));
println!(
"geos_c version: {}",
version().expect("failed to get version")
);
let g1 = Geometry::new_from_wkt("POLYGON ((0 0, 0 5, 5 5, 5 0, 0 0))")?;
println!("Geometry 1 created");
println!("Area : {}", g1.area()?);
Expand Down
32 changes: 25 additions & 7 deletions src/context_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ use error::{Error, GResult};
use geos_sys::*;
use libc::{c_char, c_void, strlen};
use std::ffi::CStr;
use std::ops::Deref;
use std::slice;
use std::sync::Mutex;
use std::ops::Deref;

macro_rules! set_callbacks {
($c_func:ident, $kind:ident, $callback_name:ident, $last:ident) => {
fn $kind<'a>(ptr: GEOSContextHandle_t, nf: *mut InnerContext<'a>) {
unsafe extern "C" fn message_handler_func<'a>(message: *const c_char, data: *mut c_void) {
unsafe extern "C" fn message_handler_func<'a>(
message: *const c_char,
data: *mut c_void,
) {
let inner_context: &InnerContext<'a> = &*(data as *mut _);

if let Ok(callback) = inner_context.$callback_name.lock() {
Expand All @@ -31,8 +34,18 @@ macro_rules! set_callbacks {
};
}

set_callbacks!(GEOSContext_setNoticeMessageHandler_r, set_notif, notif_callback, last_notification);
set_callbacks!(GEOSContext_setErrorMessageHandler_r, set_error, error_callback, last_error);
set_callbacks!(
GEOSContext_setNoticeMessageHandler_r,
set_notif,
notif_callback,
last_notification
);
set_callbacks!(
GEOSContext_setErrorMessageHandler_r,
set_error,
error_callback,
last_error
);

pub(crate) struct PtrWrap<T>(pub T);

Expand Down Expand Up @@ -77,16 +90,21 @@ impl<'a> ContextHandle<'a> {
let ptr = unsafe { GEOS_init_r() };
if ptr.is_null() {
return if let Some(ref caller) = caller {
Err(Error::GenericError(format!("GEOS_init_r failed from \"{}\"", caller)))
Err(Error::GenericError(format!(
"GEOS_init_r failed from \"{}\"",
caller
)))
} else {
Err(Error::GenericError("GEOS_init_r failed".to_owned()))
};
}
let last_notification = Mutex::new(None);
let last_error = Mutex::new(None);

let notif_callback: Mutex<Box<dyn Fn(&str) + Send + Sync + 'a>> = Mutex::new(Box::new(|_| {}));
let error_callback: Mutex<Box<dyn Fn(&str) + Send + Sync + 'a>> = Mutex::new(Box::new(|_| {}));
let notif_callback: Mutex<Box<dyn Fn(&str) + Send + Sync + 'a>> =
Mutex::new(Box::new(|_| {}));
let error_callback: Mutex<Box<dyn Fn(&str) + Send + Sync + 'a>> =
Mutex::new(Box::new(|_| {}));

let inner = Box::into_raw(Box::new(InnerContext {
notif_callback,
Expand Down
Loading

0 comments on commit f014049

Please sign in to comment.