Skip to content

Commit

Permalink
Auto merge of #465 - JustForFun88:fix_bugs_clone_from, r=Amanieu
Browse files Browse the repository at this point in the history
Fix two bugs in `clone_from` one of which is mine πŸ˜… (was introduced in  #458)

My bad πŸ˜…, I totally forgot that we can modify table from another thread, which can result in an invalid `self` table in case if we have a panic during the cloning of elements (we will have an empty table with invalid control bytes to which we can get accessed via `RawIterRange` during parallel iteration or via the `find` function).
This pull request fixes my bug by partially reverting the old implementation of the `clone_from` function.

Also fixes leaking allocator when `self_.buckets() != source.buckets`. We used to rewrite the table (`&mut **self_ as *mut Self).write()`), forgetting that although we freed the old table memory, we forgot about the old allocator (**this behavior was found during testing**). Now, to allocate a new table, we use the old allocator, via `ptr::read(&self_.table.alloc)`.

The latter is worth thinking about. Maybe instead of using the old allocator, it's better to use the new one via `alloc.clone()` and just drop the old one?

**P.S.** Added tests for the cases described above.
  • Loading branch information
bors committed Sep 1, 2023
2 parents ec75914 + 8a4a1c7 commit a33acbe
Show file tree
Hide file tree
Showing 3 changed files with 494 additions and 94 deletions.

0 comments on commit a33acbe

Please sign in to comment.