Skip to content

Commit c18e1f5

Browse files
committed
Generate __slots__
1 parent 28813b0 commit c18e1f5

File tree

4 files changed

+42
-33
lines changed

4 files changed

+42
-33
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rlbot_flatbuffers"
3-
version = "0.13.0"
3+
version = "0.13.1"
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"

codegen/structs.rs

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -614,45 +614,55 @@ impl StructBindGenerator {
614614
write_str!(self, " }");
615615
}
616616

617-
fn generate_long_match_args(&mut self) {
618-
write_str!(self, " #[classattr]");
619-
write_str!(
620-
self,
621-
" fn __match_args__(py: Python) -> Bound<pyo3::types::PyTuple> {"
622-
);
623-
write_str!(self, " pyo3::types::PyTuple::new(py, [");
617+
fn generate_long_args(&mut self) {
618+
let funcs = ["match_args", "slots"];
619+
// let funcs = ["match_args"];
624620

625-
for variable_info in &self.types {
626-
write_fmt!(self, " \"{}\",", variable_info.name);
621+
for func in funcs {
622+
write_str!(self, " #[classattr]");
623+
write_fmt!(
624+
self,
625+
" fn __{func}__(py: Python) -> Bound<pyo3::types::PyTuple> {{"
626+
);
627+
write_str!(self, " pyo3::types::PyTuple::new(py, [");
628+
629+
for variable_info in &self.types {
630+
write_fmt!(self, " \"{}\",", variable_info.name);
631+
}
632+
633+
write_str!(self, " ]).unwrap()");
634+
write_str!(self, " }\n");
627635
}
628-
629-
write_str!(self, " ]).unwrap()");
630-
write_str!(self, " }");
631636
}
632637

633-
fn generate_match_args(&mut self) {
638+
fn generate_args(&mut self) {
634639
if self.types.is_empty() {
635640
return;
636641
}
637642

638643
if self.types.len() > 12 {
639-
self.generate_long_match_args();
644+
self.generate_long_args();
640645
return;
641646
}
642647

643648
let sig_parts: Vec<_> = repeat("&'static str").take(self.types.len()).collect();
644649
let sig = sig_parts.join(", ");
645650

646-
write_str!(self, " #[classattr]");
647-
write_fmt!(self, " fn __match_args__() -> ({sig},) {{",);
648-
write_str!(self, " (");
651+
let funcs = ["match_args", "slots"];
652+
// let funcs = ["match_args"];
649653

650-
for variable_info in &self.types {
651-
write_fmt!(self, " \"{}\",", variable_info.name);
654+
for func in funcs {
655+
write_str!(self, " #[classattr]");
656+
write_fmt!(self, " fn __{func}__() -> ({sig},) {{",);
657+
write_str!(self, " (");
658+
659+
for variable_info in &self.types {
660+
write_fmt!(self, " \"{}\",", variable_info.name);
661+
}
662+
663+
write_str!(self, " )");
664+
write_str!(self, " }\n");
652665
}
653-
654-
write_str!(self, " )");
655-
write_str!(self, " }");
656666
}
657667

658668
fn generate_pack_method(&mut self) {
@@ -1186,8 +1196,7 @@ impl Generator for StructBindGenerator {
11861196
self.generate_repr_method();
11871197
write_str!(self, "");
11881198

1189-
self.generate_match_args();
1190-
write_str!(self, "");
1199+
self.generate_args();
11911200

11921201
self.generate_pack_method();
11931202
write_str!(self, "");

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl FromGil<Bools> for Py<Bool> {
149149
macro_rules! pynamedmodule {
150150
(doc: $doc:literal, name: $name:tt, classes: [$($class_name:ident),*], vars: [$(($var_name:literal, $value:expr)),*], exceptions: [$($except:expr),*]) => {
151151
#[doc = $doc]
152-
#[pymodule]
152+
#[pymodule(gil_used = false)]
153153
#[allow(redundant_semicolons)]
154154
fn $name(py: Python, m: Bound<PyModule>) -> PyResult<()> {
155155
$(m.add_class::<$class_name>()?);*;

0 commit comments

Comments
 (0)