-
-
Notifications
You must be signed in to change notification settings - Fork 85
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: Equal Signature
s irrespective of D-Bus marshalled state
#381
🩹 🚸 zv: Equal Signature
s irrespective of D-Bus marshalled state
#381
Conversation
959ce71
to
5fe0d63
Compare
Signature
s regardless of outer parentheses / marshalled state
Signature
s regardless of outer parentheses / marshalled stateSignature
s irrespective of D-Bus marshalled state
9de8ab1
to
c1456d4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good otherwise. Also, it would be great to modify zbus code to make use of this in message-handling code.
135d1d9
to
8631aa6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand you're still grasping around git rebasing etc so I understand completely (I'd make a lot more mistakes in your shoes for sure) but kindly review each line of every commit before (or after) pushing) to catch such mistakes.
Unfortunately I have messed up. I will take your advise to heart, sorry to trouble you with it. |
40ef548
to
2e5af75
Compare
More comfortable with the commits' outline, but shape is just a prerequisite I remember you mention a preference for string comparisons in favor of the byte slice comparisons. fn eq(&self, other: &Signature<'_>) -> bool {
match (
self.without_outer_parentheses(),
other.without_outer_parentheses(),
) {
(Some(lhs_without), None) => *lhs_without == **other,
(None, Some(rhs_without)) => **self == *rhs_without,
_ => **self == **other,
}
} I am a bit torn, as the dereferences do different things and make it less clear what actually happens but on the other hand, this is prettier than having six |
👍
hmm..
|
2e5af75
to
e0f9fc1
Compare
It can - and it does now. Now, I am pondering whether the method I misunderstood how
|
Being curious what the differences would be between the approaches, I rolled a quick bench crate |
Nice. 👍
Nah, |
I wrote
Yes (at least, see if we do something like that elsewhere too in code please). |
e0f9fc1
to
280296b
Compare
280296b
to
057d770
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually apart from these minor things, I don't see why we can't merge this work. Am I forgetting something from our conversations on Matrix? 🤔
You'll have to rebase on main in any case.
Funny we end up in this situation where you suggest to merge and I have concerns. On matrix I shared that I had come to realize that An "ii" body deserializes to "(((ii)))" just fine, which is understandable, because D-Bus and zvariant don't care about the outer shape, and happily accommodate how the user wants the data. But if some user does this, we are more than one pair of parentheses apart The question is, should The first way offers least chance of surprise and most expensive In tests, people probably will not care about more expensive equality. Either way, I do think the associated functions on |
😆
Right, I recall now. :) As I tried to explain, I do not care much for theoretical issues. We already need to treat
Yeah, I think this is a good compromise. Hence why I'm thinking this PR is the way to go.
I don't think we need to cover all cases. You'll notice that |
@luukvanderduim You've more than a 100 commits on the PR now. Something went horribly wrong in your rebase. :( |
Unfortunate. |
b84fdf6
to
7bab9a7
Compare
Sanity seems to have been restored. We are back at three commits, which - looking at the changes - are what we want. |
Great, thanks again for still not giving up. :)
It exists in another form (see commit a0b92da). Please make sure the new code doesn't need these changes that were dropped. Btw, I think the CI can be fixed by just rebasing on the latest |
Looks like it does:
Which errors when it would find an empty struct.
Long story short, yes I believe 'balanced parantheses' are checked this way. Note, there are things the parser does not do, but also is not that important:
Seems #440 is related. |
👍 so these changes are good then, good.
Right, it should work now. I restarted the failing job. 🤞
Hmm.. currently these are checked by the serializers and deserializers so it is ultimately checked. However, now I wonder if the checks should be on |
7bab9a7
to
89b42ad
Compare
Rebased to main.
Does moving those checks solve a problem? |
Well ser/de process isn't currently as fast as it should be so maybe it would help there. Signature creation is typically amortized. So it'll definitely optimize the overall code but can't be sure if it'd be significant enough to care. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, i still found something not right. :)
89b42ad
to
fc9acaf
Compare
This commit adjusts the `PartialEq` impl to evaluate equality, even if the type was marshalled and has seen outer parentheses stripped. Two signatures representing the same type can differ as a result of D-Bus marshalling. D-Bus marshalling will omit outer parentheses from body singatures. Consider a `MyType { a: i32, b: i32}`: `MyType::signature()` returns a "(ii)" `Signature` whereas `Message::body_signature()` with `MyType` as body, would return a "ii" `Signature`, which may lead to unexpected inequality of `Signature`s. Note: `PartialEq` on `Signature` accounts for marshalling only. One can construct- or deserialize into deeper nested structs or tuples than than the signature describes but at that point the divergence is expected.
Adds test for `PartialEq` on Signature. The test verifies if equality is correctly evaluated, both with and without marshalled `Signature`s, as marshalling omits outer parentheses.
As per [`Eq`](https://doc.rust-lang.org/stable/std/cmp/trait.Eq.html#derivable) docs on deriving: "Note that the derive strategy requires all fields are `Eq, which isn’t always desired." We specify conditional `Signature` equality that does not include all fields are (derivable) `Eq`. This is why `Eq` for `Signature` is manually implemented.
fc9acaf
to
ed6b035
Compare
Moved the associated functions out. I hope you are happy with where they landed (just above where they are needed, above |
This adjusts the
PartialEq
impls to evaluate equality irrespective ofof marshalling of the type.
Two signatures representing the same type can differ as a result of
D-Bus marshalling. D-Bus marshalling will omit outer parentheses from body
singatures.
Consider a
MyType { a: i32, b: i32}
:MyType::signature()
returns a "(ii)"Signature
whereasMessage::body_signature()
withMyType
as body, would returna "ii"
Signature
, which may lead to unexpected inequality ofSignature
s.Note:
PartialEq
onSignature
accounts for marshalling only.One can construct- or deserialize into deeper nested structs or tuples than
than the signature describes but at that point the divergence is expected.