Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #465 - JustForFun88:fix_bugs_clone_from, r=Amanieu
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