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

Avoid creating references to invalid data #22

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

HadrienG2
Copy link

@HadrienG2 HadrienG2 commented Sep 19, 2019

This implements the changes discussed in #17 . Areas in the code where references are still necessary are properly annotated in the code, along with a discussion of what language-level fixes are needed to fix the problem in a zero-cost way.

(Non-zero cost ways are also envisionable, of course, for example Vec<T> len could be dumped alongside the serialized data, but I fear that such unsatisfactory performance compromises go against the spirit of abomonation.)

I also moved all tests to assert_eq so that they produce more exhaustive error messages and engaged in a few formatting tweaks which make the code more readable in my subjective opinion. Since looks are subjective, feel free to disagree and request me to revert any part of that ;)

Fixes #17.

@frankmcsherry
Copy link
Member

Thanks very much! Let me get some time to walk through this, to make sure I grok what is going on, but the intent sounds very solid.

src/lib.rs Outdated Show resolved Hide resolved
@HadrienG2
Copy link
Author

Apologies for the big rebase, but it should ultimately be a net benefit: commits serve a clearer purpose (and can thus be reviewed one by one easily) and irrelevant changes were pushed out of this PR.

@frankmcsherry
Copy link
Member

No worries. Sorry for the delay in the review. I'm moving house this week, and employment is moving offices at the same time.

// One possibility would be a C++11-style combination of variadic generics and recursion.
let ($(ref mut $ty,)*) = *self_.as_ptr();
$(
let field_ptr : NonNull<$ty> = From::from($ty);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My inner programming language nerd is amazed by the fact that Rust's grammar is so well designed that we can have a type and a variable with the same name and use these at the same time without any issues.

I also wish we didn't need this hack

@HadrienG2
Copy link
Author

HadrienG2 commented Sep 26, 2019

By the way, this PR breaks the API of the Abomonation trait, so 1/a version bump is in order and 2/abomonation_derive will need an update. I can provide a PR for said update as soon as a matching version of abomonation is available on crates.io.

(FWIW, #25 also breaks the API, so you may want to batch both into a single release if you choose to merge them)

@HadrienG2
Copy link
Author

Ping @frankmcsherry, do you have more time to look into these PRs nowadays?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Shouldn't exhume take a NonNull<Self> rather than a &mut Self?
2 participants