Upgrades to PyO3 0.17

pull/246/head
Tpt 2 years ago committed by Thomas Tanon
parent 6c6a36ec49
commit 8636de227e
  1. 21
      Cargo.lock
  2. 2
      python/Cargo.toml
  3. 46
      python/src/io.rs
  4. 17
      python/src/model.rs

21
Cargo.lock generated

@ -1004,13 +1004,14 @@ dependencies = [
[[package]]
name = "pyo3"
version = "0.16.6"
version = "0.17.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0220c44442c9b239dd4357aa856ac468a4f5e1f0df19ddb89b2522952eb4c6ca"
checksum = "12f72538a0230791398a0986a6518ebd88abc3fded89007b506ed072acc831e1"
dependencies = [
"cfg-if",
"indoc",
"libc",
"memoffset",
"parking_lot",
"pyo3-build-config",
"pyo3-ffi",
@ -1020,9 +1021,9 @@ dependencies = [
[[package]]
name = "pyo3-build-config"
version = "0.16.6"
version = "0.17.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c819d397859445928609d0ec5afc2da5204e0d0f73d6bf9e153b04e83c9cdc2"
checksum = "fc4cf18c20f4f09995f3554e6bcf9b09bd5e4d6b67c562fdfaafa644526ba479"
dependencies = [
"once_cell",
"target-lexicon",
@ -1030,9 +1031,9 @@ dependencies = [
[[package]]
name = "pyo3-ffi"
version = "0.16.6"
version = "0.17.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca882703ab55f54702d7bfe1189b41b0af10272389f04cae38fe4cd56c65f75f"
checksum = "a41877f28d8ebd600b6aa21a17b40c3b0fc4dfe73a27b6e81ab3d895e401b0e9"
dependencies = [
"libc",
"pyo3-build-config",
@ -1040,9 +1041,9 @@ dependencies = [
[[package]]
name = "pyo3-macros"
version = "0.16.6"
version = "0.17.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "568749402955ad7be7bad9a09b8593851cd36e549ac90bfd44079cea500f3f21"
checksum = "2e81c8d4bcc2f216dc1b665412df35e46d12ee8d3d046b381aad05f1fcf30547"
dependencies = [
"proc-macro2",
"pyo3-macros-backend",
@ -1052,9 +1053,9 @@ dependencies = [
[[package]]
name = "pyo3-macros-backend"
version = "0.16.6"
version = "0.17.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "611f64e82d98f447787e82b8e7b0ebc681e1eb78fc1252668b2c605ffb4e1eb8"
checksum = "85752a767ee19399a78272cc2ab625cd7d373b2e112b4b13db28de71fa892784"
dependencies = [
"proc-macro2",
"quote",

@ -17,4 +17,4 @@ doctest = false
[dependencies]
oxigraph = { version = "0.3.6", path="../lib", features = ["http_client"] }
pyo3 = { version = "0.16", features = ["extension-module", "abi3-py37"] }
pyo3 = { version = "0.17", features = ["extension-module", "abi3-py37"] }

@ -286,37 +286,37 @@ pub(crate) struct PyIo(PyObject);
impl Read for PyIo {
fn read(&mut self, mut buf: &mut [u8]) -> io::Result<usize> {
let gil = Python::acquire_gil();
let py = gil.python();
let read = self
.0
.call_method(py, "read", (buf.len(),), None)
.map_err(to_io_err)?;
let bytes = read
.extract::<&[u8]>(py)
.or_else(|e| read.extract::<&str>(py).map(|s| s.as_bytes()).or(Err(e)))
.map_err(to_io_err)?;
buf.write_all(bytes)?;
Ok(bytes.len())
Python::with_gil(|py| {
let read = self
.0
.call_method(py, "read", (buf.len(),), None)
.map_err(to_io_err)?;
let bytes = read
.extract::<&[u8]>(py)
.or_else(|e| read.extract::<&str>(py).map(|s| s.as_bytes()).or(Err(e)))
.map_err(to_io_err)?;
buf.write_all(bytes)?;
Ok(bytes.len())
})
}
}
impl Write for PyIo {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
let gil = Python::acquire_gil();
let py = gil.python();
self.0
.call_method(py, "write", (PyBytes::new(py, buf),), None)
.map_err(to_io_err)?
.extract::<usize>(py)
.map_err(to_io_err)
Python::with_gil(|py| {
self.0
.call_method(py, "write", (PyBytes::new(py, buf),), None)
.map_err(to_io_err)?
.extract::<usize>(py)
.map_err(to_io_err)
})
}
fn flush(&mut self) -> io::Result<()> {
let gil = Python::acquire_gil();
let py = gil.python();
self.0.call_method(py, "flush", (), None)?;
Ok(())
Python::with_gil(|py| {
self.0.call_method(py, "flush", (), None)?;
Ok(())
})
}
}

@ -97,7 +97,7 @@ impl PyNamedNode {
fn __richcmp__(&self, other: &PyAny, op: CompareOp) -> PyResult<bool> {
if let Ok(other) = other.downcast::<PyCell<Self>>() {
Ok(eq_ord_compare(self, &other.borrow(), op))
Ok(op.matches(self.cmp(&other.borrow())))
} else if PyBlankNode::is_type_of(other)
|| PyLiteral::is_type_of(other)
|| PyDefaultGraph::is_type_of(other)
@ -831,9 +831,7 @@ impl PyQuad {
4
}
fn __getitem__(&self, input: usize) -> PyResult<PyObject> {
let gil = Python::acquire_gil();
let py = gil.python();
fn __getitem__(&self, input: usize, py: Python<'_>) -> PyResult<PyObject> {
match input {
0 => Ok(PySubject::from(self.inner.subject.clone()).into_py(py)),
1 => Ok(PyNamedNode::from(self.inner.predicate.clone()).into_py(py)),
@ -1126,17 +1124,6 @@ fn eq_compare_other_type(op: CompareOp) -> PyResult<bool> {
}
}
fn eq_ord_compare<T: Eq + Ord>(a: &T, b: &T, op: CompareOp) -> bool {
match op {
CompareOp::Lt => a < b,
CompareOp::Le => a <= b,
CompareOp::Eq => a == b,
CompareOp::Ne => a != b,
CompareOp::Gt => a > b,
CompareOp::Ge => a >= b,
}
}
fn hash(t: &impl Hash) -> u64 {
let mut s = DefaultHasher::new();
t.hash(&mut s);

Loading…
Cancel
Save