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

Node::null, and clippy lints #43

Merged
merged 2 commits into from
Sep 27, 2018
Merged

Node::null, and clippy lints #43

merged 2 commits into from
Sep 27, 2018

Conversation

dginev
Copy link
Member

@dginev dginev commented Sep 26, 2018

cc @triptec - another one to review.

I got lucky and found the trick to running valgrind in my other project (which keeps evolving as new features appear in nightly), more in the issue for anyone interested.

And that revealed that using Node::mock() in an implementation of the Default trait is leaking memory - albeit tiny amounts.

So in this PR I finally did the C approach properly - I added Node::null() method, which uses a ptr::null_mut, and added an internal sibling of that method for DocumentRef. So now there is a memory-free placeholder node, which is more appropriate for my use case.

One could argue that the other project has an API mistake, and should really use an Option<Node> instead, but that makes the entire API way too cumbersome. In fact what I really want is a PartialDefault trait, as I would love to provide fallbacks for all fields except the node... But that's a brainstorm for another day.

I also added some recent clippy lint suggestions, and a new test. And naturally verified that no memory is leaked after refactoring to using Node::null(), which is happily indeed the case.

Copy link
Collaborator

@triptec triptec left a comment

Choose a reason for hiding this comment

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

LGTM

@triptec
Copy link
Collaborator

triptec commented Sep 26, 2018

do you think you could add a few lines on how you are running valgrind to the readme or some other file if you have that fresh in mind. I've never used it and it might be good to know how when I work on this =)

@dginev
Copy link
Member Author

dginev commented Sep 27, 2018

@triptec thanks for the suggestion, I added a new markdown file under tests/ for now, which can evolve further later. Merging and releasing a minor version next.

@dginev dginev merged commit 21060ee into master Sep 27, 2018
@dginev dginev deleted the node-null-method branch March 28, 2019 22:46
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.

2 participants