Skip to content

Commit a3b2a64

Browse files
authored
Update PyO3 to 0.23.4 (#54)
1 parent dd0917a commit a3b2a64

File tree

5 files changed

+44
-44
lines changed

5 files changed

+44
-44
lines changed

.github/workflows/release.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ jobs:
3636

3737
- os: macos
3838
target: x86_64
39-
interpreter: pypy3.8 pypy3.9 pypy3.10
39+
interpreter: pypy3.9 pypy3.10
4040
- os: macos
4141
target: aarch64
4242
# actions/setup-python@v5 does not support 3.8 and 3.9 on arm64
43-
interpreter: 3.8 3.9 pypy3.8 pypy3.9 pypy3.10
43+
interpreter: 3.8 3.9 pypy3.9 pypy3.10
4444

4545
- os: ubuntu
4646
target: x86_64
@@ -90,7 +90,7 @@ jobs:
9090
target: ${{ matrix.target }}
9191
manylinux: ${{ matrix.manylinux || 'auto' }}
9292
container: ${{ matrix.container }}
93-
args: --release --out dist --interpreter ${{ matrix.maturin-interpreter || matrix.interpreter || '3.8 3.9 3.10 3.11 3.12 3.13 pypy3.8 pypy3.9 pypy3.10' }} ${{ matrix.extra-build-args }}
93+
args: --release --out dist --interpreter ${{ matrix.maturin-interpreter || matrix.interpreter || '3.8 3.9 3.10 3.11 3.12 3.13 pypy3.9 pypy3.10' }} ${{ matrix.extra-build-args }}
9494
rust-toolchain: 1.76.0
9595
docker-options: -e CI
9696

@@ -108,7 +108,7 @@ jobs:
108108
strategy:
109109
fail-fast: false
110110
matrix:
111-
os: [ ubuntu-latest, windows-latest, macos-12, macos-14 ]
111+
os: [ ubuntu-latest, windows-latest, macos-13, macos-14 ]
112112
interpreter: [ '3.8', '3.9', '3.10', '3.11', '3.12', '3.13' ]
113113
exclude:
114114
# actions/setup-python@v5 does not support 3.8 and 3.9 on arm64

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "libipld"
3-
version = "3.0.0"
3+
version = "3.0.1"
44
edition = "2021"
55
license = "MIT"
66
description = "Python binding to the Rust IPLD library"
@@ -13,11 +13,11 @@ name = "libipld"
1313
crate-type = ["rlib", "cdylib"]
1414

1515
[dependencies]
16-
pyo3 = { version = "0.22.5", features = ["generate-import-lib", "anyhow"] }
17-
python3-dll-a = "0.2.10"
18-
anyhow = "1.0.75"
16+
pyo3 = { version = "0.23.4", features = ["generate-import-lib", "anyhow"] }
17+
python3-dll-a = "0.2.13"
18+
anyhow = "1.0.95"
1919
libipld = { version = "0.16.0", features = ["dag-cbor"] }
20-
multibase = "0.9"
20+
multibase = "0.9.1"
2121
byteorder = "1.5.0"
2222
multihash = "0.18.1"
2323

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2024 Ilya Siamionau
3+
Copyright (c) 2025 Ilya Siamionau
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

profiling/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ edition = "2021"
88
libipld = { path = ".." }
99

1010
structopt = "0.3.26"
11-
clap = "4.5.1"
11+
clap = "4.5.29"
1212

1313
[dependencies.pyo3]
14-
version = "0.22.2"
14+
version = "0.23.4"

src/lib.rs

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,24 @@ use ::libipld::cid::{Cid, Error as CidError, Result as CidResult, Version};
77
use anyhow::{anyhow, Result};
88
use byteorder::{BigEndian, ByteOrder};
99
use multihash::Multihash;
10-
use pyo3::{ffi, prelude::*, types::*, PyObject, Python};
11-
use pyo3::conversion::ToPyObject;
10+
use pyo3::{ffi, prelude::*, types::*, BoundObject, PyObject, Python};
1211
use pyo3::pybacked::PyBackedStr;
1312

1413
fn cid_hash_to_pydict<'py>(py: Python<'py>, cid: &Cid) -> Bound<'py, PyDict> {
1514
let hash = cid.hash();
16-
let dict_obj = PyDict::new_bound(py);
15+
let dict_obj = PyDict::new(py);
1716

1817
dict_obj.set_item("code", hash.code()).unwrap();
1918
dict_obj.set_item("size", hash.size()).unwrap();
2019
dict_obj
21-
.set_item("digest", PyBytes::new_bound(py, &hash.digest()))
20+
.set_item("digest", PyBytes::new(py, &hash.digest()))
2221
.unwrap();
2322

2423
dict_obj
2524
}
2625

2726
fn cid_to_pydict<'py>(py: Python<'py>, cid: &Cid) -> Bound<'py, PyDict> {
28-
let dict_obj = PyDict::new_bound(py);
27+
let dict_obj = PyDict::new(py);
2928

3029
dict_obj.set_item("version", cid.version() as u64).unwrap();
3130
dict_obj.set_item("codec", cid.codec()).unwrap();
@@ -122,15 +121,15 @@ fn decode_dag_cbor_to_pyobject<R: Read + Seek>(
122121

123122
let major = decode::read_major(r)?;
124123
Ok(match major.kind() {
125-
MajorKind::UnsignedInt => decode::read_uint(r, major)?.to_object(py),
126-
MajorKind::NegativeInt => (-1 - decode::read_uint(r, major)? as i64).to_object(py),
124+
MajorKind::UnsignedInt => decode::read_uint(r, major)?.into_pyobject(py)?.into(),
125+
MajorKind::NegativeInt => (-1 - decode::read_uint(r, major)? as i64).into_pyobject(py)?.into(),
127126
MajorKind::ByteString => {
128127
let len = decode::read_uint(r, major)?;
129-
PyBytes::new_bound(py, &decode::read_bytes(r, len)?).to_object(py)
128+
PyBytes::new(py, &decode::read_bytes(r, len)?).into_pyobject(py)?.into()
130129
}
131130
MajorKind::TextString => {
132131
let len = decode::read_uint(r, major)?;
133-
string_new_bound(py, &decode::read_bytes(r, len)?).to_object(py)
132+
string_new_bound(py, &decode::read_bytes(r, len)?).into_pyobject(py)?.into()
134133
}
135134
MajorKind::Array => {
136135
let len: ffi::Py_ssize_t = decode_len(decode::read_uint(r, major)?)?.try_into()?;
@@ -143,12 +142,12 @@ fn decode_dag_cbor_to_pyobject<R: Read + Seek>(
143142
}
144143

145144
let list: Bound<'_, PyList> = Bound::from_owned_ptr(py, ptr).downcast_into_unchecked();
146-
list.to_object(py)
145+
list.into_pyobject(py)?.into()
147146
}
148147
}
149148
MajorKind::Map => {
150149
let len = decode_len(decode::read_uint(r, major)?)?;
151-
let dict = PyDict::new_bound(py);
150+
let dict = PyDict::new(py);
152151

153152
let mut prev_key: Option<Vec<u8>> = None;
154153
for _ in 0..len {
@@ -168,14 +167,14 @@ fn decode_dag_cbor_to_pyobject<R: Read + Seek>(
168167
}
169168
}
170169

171-
let key_py = string_new_bound(py, key.as_slice()).to_object(py);
170+
let key_py = string_new_bound(py, key.as_slice()).into_pyobject(py)?;
172171
prev_key = Some(key);
173172

174173
let value_py = decode_dag_cbor_to_pyobject(py, r, depth + 1)?;
175174
dict.set_item(key_py, value_py)?;
176175
}
177176

178-
dict.to_object(py)
177+
dict.into_pyobject(py)?.into()
179178
}
180179
MajorKind::Tag => {
181180
let value = decode::read_uint(r, major)?;
@@ -185,14 +184,15 @@ fn decode_dag_cbor_to_pyobject<R: Read + Seek>(
185184

186185
// FIXME(MarshalX): to_bytes allocates
187186
let cid = decode::read_link(r)?.to_bytes();
188-
PyBytes::new_bound(py, &cid).to_object(py)
187+
PyBytes::new(py, &cid).into_pyobject(py)?.into()
189188
}
190189
MajorKind::Other => match major {
191-
cbor::FALSE => false.to_object(py),
192-
cbor::TRUE => true.to_object(py),
190+
// FIXME(MarshalX): should be more clear for bool?
191+
cbor::FALSE => false.into_pyobject(py)?.into_any().unbind(),
192+
cbor::TRUE => true.into_pyobject(py)?.into_any().unbind(),
193193
cbor::NULL => py.None(),
194-
cbor::F32 => decode::read_f32(r)?.to_object(py),
195-
cbor::F64 => decode::read_f64(r)?.to_object(py),
194+
cbor::F32 => decode::read_f32(r)?.into_pyobject(py)?.into(),
195+
cbor::F64 => decode::read_f64(r)?.into_pyobject(py)?.into(),
196196
_ => return Err(anyhow!("Unsupported major type".to_string())),
197197
},
198198
})
@@ -311,7 +311,7 @@ fn encode_dag_cbor_from_pyobject<'py, W: Write>(
311311
#[pyfunction]
312312
fn decode_dag_cbor_multi<'py>(py: Python<'py>, data: &[u8]) -> PyResult<Bound<'py, PyList>> {
313313
let mut reader = BufReader::new(Cursor::new(data));
314-
let decoded_parts = PyList::empty_bound(py);
314+
let decoded_parts = PyList::empty(py);
315315

316316
loop {
317317
let py_object = decode_dag_cbor_to_pyobject(py, &mut reader, 0);
@@ -420,7 +420,7 @@ pub fn decode_car<'py>(py: Python<'py>, data: &[u8]) -> PyResult<(PyObject, Boun
420420

421421
// FIXME (MarshalX): we are not verifying if the roots are valid CIDs
422422

423-
let parsed_blocks = PyDict::new_bound(py);
423+
let parsed_blocks = PyDict::new(py);
424424

425425
loop {
426426
if let Err(_) = read_u64_leb128(buf) {
@@ -452,7 +452,7 @@ pub fn decode_car<'py>(py: Python<'py>, data: &[u8]) -> PyResult<(PyObject, Boun
452452
};
453453

454454
// FIXME(MarshalX): to_bytes allocates
455-
let key = PyBytes::new_bound(py, &cid.to_bytes()).to_object(py);
455+
let key = PyBytes::new(py, &cid.to_bytes()).into_pyobject(py)?;
456456
parsed_blocks.set_item(key, block)?;
457457
}
458458

@@ -494,7 +494,7 @@ pub fn encode_dag_cbor<'py>(
494494
if let Err(e) = buf.flush() {
495495
return Err(get_err("Failed to flush buffer", e.to_string()));
496496
}
497-
Ok(PyBytes::new_bound(py, &buf.get_ref()))
497+
Ok(PyBytes::new(py, &buf.get_ref()))
498498
}
499499

500500
fn get_cid_from_py_any<'py>(data: &Bound<PyAny>) -> PyResult<Cid> {
@@ -522,14 +522,14 @@ fn decode_cid<'py>(py: Python<'py>, data: &Bound<PyAny>) -> PyResult<Bound<'py,
522522

523523
#[pyfunction]
524524
fn encode_cid<'py>(py: Python<'py>, data: &Bound<PyAny>) -> PyResult<Bound<'py, PyString>> {
525-
Ok(PyString::new_bound(py, get_cid_from_py_any(data)?.to_string().as_str()))
525+
Ok(PyString::new(py, get_cid_from_py_any(data)?.to_string().as_str()))
526526
}
527527

528528
#[pyfunction]
529529
fn decode_multibase<'py>(py: Python<'py>, data: &str) -> PyResult<(char, Bound<'py, PyBytes>)> {
530530
let base = multibase::decode(data);
531531
if let Ok((base, data)) = base {
532-
Ok((base.code(), PyBytes::new_bound(py, &data)))
532+
Ok((base.code(), PyBytes::new(py, &data)))
533533
} else {
534534
Err(get_err(
535535
"Failed to decode multibase",
@@ -558,17 +558,17 @@ fn get_err(msg: &str, err: String) -> PyErr {
558558

559559
#[pymodule]
560560
fn libipld(m: &Bound<'_, PyModule>) -> PyResult<()> {
561-
m.add_function(wrap_pyfunction_bound!(decode_cid, m)?)?;
562-
m.add_function(wrap_pyfunction_bound!(encode_cid, m)?)?;
561+
m.add_function(wrap_pyfunction!(decode_cid, m)?)?;
562+
m.add_function(wrap_pyfunction!(encode_cid, m)?)?;
563563

564-
m.add_function(wrap_pyfunction_bound!(decode_car, m)?)?;
564+
m.add_function(wrap_pyfunction!(decode_car, m)?)?;
565565

566-
m.add_function(wrap_pyfunction_bound!(decode_dag_cbor, m)?)?;
567-
m.add_function(wrap_pyfunction_bound!(decode_dag_cbor_multi, m)?)?;
568-
m.add_function(wrap_pyfunction_bound!(encode_dag_cbor, m)?)?;
566+
m.add_function(wrap_pyfunction!(decode_dag_cbor, m)?)?;
567+
m.add_function(wrap_pyfunction!(decode_dag_cbor_multi, m)?)?;
568+
m.add_function(wrap_pyfunction!(encode_dag_cbor, m)?)?;
569569

570-
m.add_function(wrap_pyfunction_bound!(decode_multibase, m)?)?;
571-
m.add_function(wrap_pyfunction_bound!(encode_multibase, m)?)?;
570+
m.add_function(wrap_pyfunction!(decode_multibase, m)?)?;
571+
m.add_function(wrap_pyfunction!(encode_multibase, m)?)?;
572572

573573
Ok(())
574574
}

0 commit comments

Comments
 (0)