Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚡️ zv,zn,zb,zd,zm: Add zvariant::parsed::Signature & use that in ser/de #966

Merged
merged 22 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
184b702
🎨 zb,zv: Better arrange deps in Cargo.toml
zeenix Jul 27, 2024
2ba8216
➕ zv: Add dependency on `nom`
zeenix Jul 27, 2024
9e028ba
🏷️ zv: Add Error::InvalidSignature variant
zeenix Jul 27, 2024
66ddbef
🔥 zv: Drop unneeded trait bounds on internal types
zeenix Aug 15, 2024
922d104
✨ zv: Add parsed::Signature
zeenix Jul 27, 2024
d7b9d35
⚡️ zv: ser now based on parsed::Signature
zeenix Aug 14, 2024
551ba5c
🔥 zv: Drop a new redundant internal function
zeenix Aug 21, 2024
422f8c7
⚡️ zv: de machinery now based on parsed::Signature
zeenix Aug 14, 2024
e9416be
🔨 zv: Use parsed::Signature in benchmarks
zeenix Aug 21, 2024
6738ce8
🔥 zv: Drop now unneeded internal API
zeenix Aug 27, 2024
1b84c5f
✨ zv: Add Basic::SIGNATURE const
zeenix Aug 28, 2024
f43e2fc
✨ zv,zd,zn,zb,zm: Add Type::parsed_signature()
zeenix Aug 28, 2024
fe8cc21
✨ zv: Add DynamicType::dynamic_parsed_signature
zeenix Aug 29, 2024
10fba23
✨ zv: Add DynamicDeserialize::deserializer_for_parsed_signature()
zeenix Aug 29, 2024
fd4b4b5
✨ zv: Add serialized::Data::deserialize_for_dynamic_parsed_signature
zeenix Aug 30, 2024
754a5bf
⚡️ zv: serialized::Data::deserialize methods now use parsed signatures
zeenix Aug 30, 2024
04eb46e
⚡️ zv: ser functions now primarily use parsed signature
zeenix Aug 30, 2024
d4767eb
🔨 zv: Benchmarks can now directly make use of Type
zeenix Aug 30, 2024
f6d5f2c
🔥 zv: Drop all use of internal SignatureParser
zeenix Aug 31, 2024
ff3369c
🔥 zv: Drop internal SignatureParser type
zeenix Aug 31, 2024
bd168bc
🔥 zv,zn: Basic::alignment now implemented for you
zeenix Sep 1, 2024
54a8462
🔨 zv: Don't enable `gvariant` feature for `dbus` fuzz target
zeenix Sep 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ jobs:
run: |
cargo --locked install cargo-fuzz
cargo --locked fuzz run --fuzz-dir zvariant/fuzz dbus -- -max_total_time=30 -max_len=100M
cargo --locked fuzz run --fuzz-dir zvariant/fuzz gvariant -- -max_total_time=30 -max_len=100M
cargo --locked fuzz run --fuzz-dir zvariant/fuzz --features gvariant gvariant -- -max_total_time=30 -max_len=100M
doc_build:
runs-on: ubuntu-latest
Expand Down
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 13 additions & 10 deletions zbus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,33 +39,38 @@ vsock = ["dep:vsock", "dep:async-io"]
tokio-vsock = ["dep:tokio-vsock", "tokio"]

[dependencies]
serde = { version = "1.0.200", features = ["derive"] }
serde_repr = "0.1.19"
zbus_macros = { path = "../zbus_macros", version = "=4.4.0" }
zvariant = { path = "../zvariant", version = "4.2.0", default-features = false, features = [
"enumflags2",
] }
zbus_names = { path = "../zbus_names", version = "3.0" }
zbus_macros = { path = "../zbus_macros", version = "=4.4.0" }
serde = { version = "1.0.200", features = ["derive"] }
serde_repr = "0.1.19"
enumflags2 = { version = "0.7.9", features = ["serde"] }
async-io = { version = "2.3.2", optional = true }
futures-core = "0.3.30"
futures-sink = "0.3.30"
futures-util = { version = "0.3.30", default-features = false, features = [
"sink",
"std",
] }
async-lock = { version = "3.3.0", optional = true }
async-broadcast = "0.7.0"
async-executor = { version = "1.11.0", optional = true }
blocking = { version = "1.6.0", optional = true }
async-task = { version = "4.7.1", optional = true }
hex = "0.4.3"
ordered-stream = "0.2"
rand = "0.8.5"
sha1 = { version = "0.10.6", features = ["std"] }
event-listener = "5.3.0"
static_assertions = "1.1.0"
async-trait = "0.1.80"
xdg-home = "1.1.0"
tracing = "0.1.40"

# Optional and target-specific dependencies.

async-io = { version = "2.3.2", optional = true }
async-lock = { version = "3.3.0", optional = true }
async-executor = { version = "1.11.0", optional = true }
blocking = { version = "1.6.0", optional = true }
async-task = { version = "4.7.1", optional = true }
async-fs = { version = "2.1.2", optional = true }
# FIXME: We should only enable process feature for Mac OS. See comment on async-process below for why we can't.
tokio = { version = "1.37.0", optional = true, features = [
Expand All @@ -78,10 +83,8 @@ tokio = { version = "1.37.0", optional = true, features = [
"sync",
"tracing",
] }
tracing = "0.1.40"
vsock = { version = "0.5.0", optional = true }
tokio-vsock = { version = "0.4", optional = true }
xdg-home = "1.1.0"

[target.'cfg(windows)'.dependencies]
windows-sys = { version = "0.59", features = [
Expand Down
7 changes: 4 additions & 3 deletions zbus/src/message/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use serde_repr::{Deserialize_repr, Serialize_repr};

use static_assertions::assert_impl_all;
use zbus_names::{BusName, ErrorName, InterfaceName, MemberName, UniqueName};
use zvariant::{ObjectPath, Signature, Type, Value};
use zvariant::{parsed, ObjectPath, Signature, Type, Value};

/// The message field code.
///
Expand Down Expand Up @@ -97,8 +97,9 @@ pub(crate) enum Field<'f> {
assert_impl_all!(Field<'_>: Send, Sync, Unpin);

impl<'f> Type for Field<'f> {
fn signature() -> Signature<'static> {
Signature::from_static_str_unchecked("(yv)")
#[inline]
fn parsed_signature() -> parsed::Signature {
parsed::Signature::static_structure(&[&parsed::Signature::U8, &parsed::Signature::Variant])
}
}

Expand Down
7 changes: 4 additions & 3 deletions zbus/src/object_server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use tracing::{debug, instrument, trace, trace_span, Instrument};

use static_assertions::assert_impl_all;
use zbus_names::InterfaceName;
use zvariant::{ObjectPath, OwnedObjectPath, OwnedValue, Signature, Type, Value};
use zvariant::{parsed::Signature, ObjectPath, OwnedObjectPath, OwnedValue, Type, Value};

use crate::{
async_lock::{RwLock, RwLockReadGuard, RwLockWriteGuard},
Expand Down Expand Up @@ -904,8 +904,9 @@ impl<R> Type for ResponseDispatchNotifier<R>
where
R: Type,
{
fn signature() -> Signature<'static> {
R::signature()
#[inline]
fn parsed_signature() -> Signature {
R::parsed_signature()
}
}

Expand Down
5 changes: 3 additions & 2 deletions zbus_macros/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,9 @@ pub fn create_proxy<M: AttrParse + Into<MethodAttrs>>(
}

impl<'p> #zbus::zvariant::Type for #proxy_name<'p> {
fn signature() -> #zbus::zvariant::Signature<'static> {
#zbus::zvariant::OwnedObjectPath::signature()
#[inline]
fn parsed_signature() -> #zbus::zvariant::parsed::Signature {
#zbus::zvariant::parsed::Signature::ObjectPath
}
}

Expand Down
5 changes: 3 additions & 2 deletions zbus_names/src/bus_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,9 @@ impl<'de: 'name, 'name> Deserialize<'de> for BusName<'name> {
}

impl Type for BusName<'_> {
fn signature() -> zvariant::Signature<'static> {
<&str>::signature()
#[inline]
fn parsed_signature() -> zvariant::parsed::Signature {
zvariant::parsed::Signature::Str
}
}

Expand Down
4 changes: 0 additions & 4 deletions zbus_names/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ macro_rules! impl_str_basic {
impl zvariant::Basic for $type {
const SIGNATURE_CHAR: char = <zvariant::Str<'_>>::SIGNATURE_CHAR;
const SIGNATURE_STR: &'static str = <zvariant::Str<'_>>::SIGNATURE_STR;

fn alignment(format: zvariant::serialized::Format) -> usize {
<zvariant::Str<'_>>::alignment(format)
}
}
};
}
Expand Down
9 changes: 6 additions & 3 deletions zvariant/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@ ostree-tests = ["gvariant"]
option-as-array = []

[dependencies]
zvariant_derive = { version = "=4.2.0", path = "../zvariant_derive" }
endi = "1.1.0"
serde = { version = "1.0.200", features = ["derive"] }
static_assertions = "1.1.0"
nom = "7"

# Optional dependencies

arrayvec = { version = "0.7.4", features = ["serde"], optional = true }
enumflags2 = { version = "0.7.9", features = ["serde"], optional = true }
zvariant_derive = { version = "=4.2.0", path = "../zvariant_derive" }
serde_bytes = { version = "0.11.14", optional = true }
static_assertions = "1.1.0"
uuid = { version = "1.8.0", features = ["serde"], optional = true }
url = { version = "2.5.0", features = ["serde"], optional = true }
time = { version = "0.3.36", features = ["serde"], optional = true }
Expand Down Expand Up @@ -59,4 +63,3 @@ all-features = true

[lints]
workspace = true

30 changes: 7 additions & 23 deletions zvariant/benches/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ use std::{collections::HashMap, vec};

use criterion::{black_box, criterion_group, criterion_main, Criterion};

use zvariant::{serialized::Context, to_bytes_for_signature, Type, Value, LE};
use zvariant::{serialized::Context, to_bytes, Type, Value, LE};

macro_rules! benchmark {
($c:ident, $data:ident, $data_type:ty, $func_prefix:literal) => {
let signature = <$data_type>::signature();

let ser_function_name = format!("{}_ser", $func_prefix);
let de_function_name = format!("{}_de", $func_prefix);

Expand All @@ -20,22 +18,15 @@ macro_rules! benchmark {
group.measurement_time(std::time::Duration::from_secs(30));
group.bench_function(&ser_function_name, |b| {
b.iter(|| {
let encoded = to_bytes_for_signature(
black_box(ctxt),
black_box(&signature),
black_box(&$data),
)
.unwrap();
let encoded = to_bytes(black_box(ctxt), black_box(&$data)).unwrap();
black_box(encoded);
})
});

let encoded = to_bytes_for_signature(ctxt, &signature, &$data).unwrap();
let encoded = to_bytes(ctxt, &$data).unwrap();
group.bench_function(&de_function_name, |b| {
b.iter(|| {
let (s, _): ($data_type, _) = encoded
.deserialize_for_signature(black_box(&signature))
.unwrap();
let (s, _): ($data_type, _) = encoded.deserialize().unwrap();
black_box(s);
})
});
Expand All @@ -50,22 +41,15 @@ macro_rules! benchmark {

group.bench_function(&ser_function_name, |b| {
b.iter(|| {
let encoded = to_bytes_for_signature(
black_box(ctxt),
black_box(&signature),
black_box(&$data),
)
.unwrap();
let encoded = to_bytes(black_box(ctxt), black_box(&$data)).unwrap();
black_box(encoded);
})
});

let encoded = to_bytes_for_signature(ctxt, &signature, &$data).unwrap();
let encoded = to_bytes(ctxt, &$data).unwrap();
group.bench_function(&de_function_name, |b| {
b.iter(|| {
let (s, _): ($data_type, _) = encoded
.deserialize_for_signature(black_box(&signature))
.unwrap();
let (s, _): ($data_type, _) = encoded.deserialize().unwrap();
black_box(s);
})
});
Expand Down
7 changes: 6 additions & 1 deletion zvariant/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ edition = "2021"
[package.metadata]
cargo-fuzz = true

[features]
# `gvariant` is only needed for the `gvariant` fuzz target. However, we don't want it to
# be enabled for running the `dbus` fuzz target, as that can cause certain assertions to fail.
# FIXME: Is there a better way to do this?
gvariant = ["zvariant/gvariant"]

[dependencies]
libfuzzer-sys = "0.4.7"
endi = "1.1.0"

[dependencies.zvariant]
path = ".."
features = ["gvariant"]

# Prevent this from interfering with workspaces
[workspace]
Expand Down
Loading