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

cleanup initialization and move operations for pinnable_mapped_file #52

Merged
merged 1 commit into from
Aug 15, 2024

Conversation

greg7mdp
Copy link
Contributor

pinnable_mapped_file has some member which are not consistently initialized or updated when constructed or assigned to with an rvalue:

  • _database_size
  • _writable
  • _sharable

Also , in the move assignment operator, we overwrite _segment_manager without giving it a chance to be removed from the static _segment_manager_map.

This PR attemps to cleanup the construction and move operations.

o._segment_manager = nullptr;
o._writable = false; //prevent dtor from doing anything interesting
// all members are correctly default-initialized, so we can just move into *this
*this = std::move(o);
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't this leave items like _segment_manager and _writable still "live" from what is being moved from? The old move constructor nulls these out so the dtor doesn't do stuff to something that has been moved from, but now it seems like it would

Copy link
Contributor Author

@greg7mdp greg7mdp Aug 15, 2024

Choose a reason for hiding this comment

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

I believe this would execute pinnable_mapped_file::operator=(pinnable_mapped_file&& o), which swaps all the members, so o._segment_manager would get the current value of this->_segment_manager which is nullptr as initialized in the member declaration.

Copy link
Member

Choose a reason for hiding this comment

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

okay yeah that makes sense

@greg7mdp greg7mdp merged commit 1dc5316 into main Aug 15, 2024
7 checks passed
@greg7mdp greg7mdp deleted the construct_copy_destruct_cleanup branch August 15, 2024 19:02
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.

3 participants