Skip to content

Commit 8acb504

Browse files
authored
Merge pull request #89 from JSorngard/dependencies/pyo3
Update the `pyo3` dependency to version 0.27.1.
2 parents eb61d4f + 76bb265 commit 8acb504

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ peroxide-num = "0.1"
3939
anyhow = "1.0"
4040
paste = "1.0"
4141
netcdf = { version = "0.7", optional = true, default-features = false }
42-
pyo3 = { version = "0.22", optional = true, features = [
42+
pyo3 = { version = "0.27.1", optional = true, features = [
4343
"auto-initialize",
44-
"gil-refs",
4544
] }
4645
blas = { version = "0.22", optional = true }
4746
lapack = { version = "0.19", optional = true }

src/util/plot.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,14 @@
7777
//! - `savefig` : Save plot with given path
7878
7979
extern crate pyo3;
80-
use self::pyo3::types::IntoPyDict;
80+
use self::pyo3::types::{IntoPyDict, PyDictMethods};
8181
use self::pyo3::{PyResult, Python};
8282
pub use self::Grid::{Off, On};
8383
use self::PlotOptions::{Domain, Images, Pairs, Path};
8484
use std::collections::HashMap;
8585
use std::fmt::Display;
86+
use std::borrow::BorrowMut;
87+
use std::ffi::CString;
8688

8789
type Vector = Vec<f64>;
8890

@@ -463,7 +465,7 @@ impl Plot for Plot2D {
463465
}
464466

465467
// Plot
466-
Python::with_gil(|py| {
468+
Python::attach(|py| {
467469
// Input data
468470
let x = self.domain.clone();
469471
let ys = self.images.clone();
@@ -502,24 +504,24 @@ impl Plot for Plot2D {
502504
let plot_type = self.plot_type.clone();
503505

504506
// Global variables to plot
505-
let globals =
506-
vec![("plt", py.import_bound("matplotlib.pyplot")?)].into_py_dict_bound(py);
507-
globals.as_gil_ref().set_item("x", x)?;
508-
globals.as_gil_ref().set_item("y", ys)?;
509-
globals.as_gil_ref().set_item("pair", pairs)?;
510-
globals.as_gil_ref().set_item("n", y_length)?;
511-
globals.as_gil_ref().set_item("p", pair_length)?;
507+
let mut globals =
508+
vec![("plt", py.import("matplotlib.pyplot")?)].into_py_dict(py)?;
509+
globals.borrow_mut().set_item("x", x)?;
510+
globals.borrow_mut().set_item("y", ys)?;
511+
globals.borrow_mut().set_item("pair", pairs)?;
512+
globals.borrow_mut().set_item("n", y_length)?;
513+
globals.borrow_mut().set_item("p", pair_length)?;
512514
if let Some(fs) = fig_size {
513-
globals.as_gil_ref().set_item("fs", fs)?;
515+
globals.borrow_mut().set_item("fs", fs)?;
514516
}
515-
globals.as_gil_ref().set_item("dp", dpi)?;
516-
globals.as_gil_ref().set_item("gr", grid)?;
517-
globals.as_gil_ref().set_item("pa", path)?;
517+
globals.borrow_mut().set_item("dp", dpi)?;
518+
globals.borrow_mut().set_item("gr", grid)?;
519+
globals.borrow_mut().set_item("pa", path)?;
518520
if let Some(xl) = self.xlim {
519-
globals.as_gil_ref().set_item("xl", xl)?;
521+
globals.borrow_mut().set_item("xl", xl)?;
520522
}
521523
if let Some(yl) = self.ylim {
522-
globals.as_gil_ref().set_item("yl", yl)?;
524+
globals.borrow_mut().set_item("yl", yl)?;
523525
}
524526

525527
// Plot Code
@@ -702,7 +704,7 @@ impl Plot for Plot2D {
702704
plot_string.push_str(&format!("plt.savefig(pa, dpi={})", dpi)[..]);
703705
}
704706

705-
py.run_bound(&plot_string[..], Some(&globals), None)?;
707+
py.run(&CString::new(plot_string)?, Some(&globals), None)?;
706708
Ok(())
707709
})
708710
}

0 commit comments

Comments
 (0)