Skip to content

Commit f96a41b

Browse files
committed
Update to PyO3 beta
1 parent 6a40fe2 commit f96a41b

5 files changed

Lines changed: 39 additions & 37 deletions

File tree

Cargo.lock

Lines changed: 28 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rlbot-flatbuffers-py"
3-
version = "0.1.6"
3+
version = "0.1.7"
44
edition = "2021"
55
description = "A Python module implemented in Rust for serializing and deserializing RLBot's flatbuffers"
66
repository = "https://github.com/VirxEC/rlbot-flatbuffers-py"
@@ -18,7 +18,7 @@ name = "rlbot_flatbuffers"
1818
crate-type = ["cdylib"]
1919

2020
[dependencies]
21-
pyo3 = "0.20.3"
21+
pyo3 = "0.21.0-beta.0"
2222
serde = "1.0.197"
2323
flatbuffers = { git = "https://github.com/google/flatbuffers", branch = "master" }
2424
get-size = { version = "0.1.4", features = ["derive"] }

build.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ impl PythonBindGenerator {
7777
if bind_type == PythonBindType::Union {
7878
file_contents.push(Cow::Borrowed("use pyo3::{pyclass, pymethods};"));
7979
} else {
80-
file_contents.push(Cow::Borrowed("use pyo3::{pyclass, pymethods, types::PyBytes, Python};"));
80+
file_contents.push(Cow::Borrowed(
81+
"use pyo3::{pyclass, pymethods, types::PyBytes, Bound, Python};",
82+
));
8183
}
8284

8385
file_contents.push(Cow::Borrowed(""));
@@ -917,7 +919,7 @@ impl PythonBindGenerator {
917919
}
918920

919921
fn generate_pack_method(&mut self) {
920-
self.write_str(" fn pack<'p>(&self, py: Python<'p>) -> &'p PyBytes {");
922+
self.write_str(" fn pack<'py>(&self, py: Python<'py>) -> Bound<'py, PyBytes> {");
921923
if self.has_complex_pack {
922924
self.write_str(" let size = self.get_size();");
923925
self.write_str(" let mut builder = FlatBufferBuilder::with_capacity(size);");
@@ -935,13 +937,13 @@ impl PythonBindGenerator {
935937
self.write_str(" let offset = flat_t.pack(&mut builder);");
936938
self.write_str(" builder.finish(offset, None);");
937939
self.write_str("");
938-
self.write_str(" PyBytes::new(py, builder.finished_data())");
940+
self.write_str(" PyBytes::new_bound(py, builder.finished_data())");
939941
} else if self.bind_type == PythonBindType::Enum {
940-
self.write_str(" PyBytes::new(py, &[flat_t.0])");
942+
self.write_str(" PyBytes::new_bound(py, &[flat_t.0])");
941943
} else {
942944
self.write_str(" let item = flat_t.pack();");
943945
self.write_str("");
944-
self.write_str(" PyBytes::new(py, &item.0)");
946+
self.write_str(" PyBytes::new_bound(py, &item.0)");
945947
}
946948

947949
self.write_str(" }");

pytest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from time import time_ns
1414

15-
num_trials = 1_000
15+
num_trials = 10_000_000
1616

1717
total_pack_time = 0
1818
total_unpack_time = 0

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ macro_rules! pynamedmodule {
2727
#[doc = $doc]
2828
#[pymodule]
2929
#[allow(redundant_semicolons)]
30-
fn $name(_py: Python, m: &PyModule) -> PyResult<()> {
30+
fn $name(_py: Python, m: Bound<PyModule>) -> PyResult<()> {
3131
$(m.add_class::<$class_name>()?);*;
3232
$(m.add($var_name, $value)?);*;
3333
Ok(())

0 commit comments

Comments
 (0)