You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use hashbrown::raw::RawTable;fnmain(){letmut table = RawTable::new();loop{
table.insert_no_grow(0,0);}}
If I change this to have some initial capacity, then in debug mode it panics decrementing growth_left:
thread 'main' panicked at 'attempt to subtract with overflow', /home/jistone/.cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/hashbrown-0.11.2/src/raw/mod.rs:882:13
In release mode that loops forever. I added debug prints for len/capacity, and that gets up to 16/14 before hanging entirely.
I suppose panic/infinite-loop is somewhat acceptable from a safety perspective, as long as we're sure to do one of those without corrupting memory, but the empty case is definitely a problem. Maybe we should assert the same condition that the regular insert uses when it decides to resize? We could even use/mimic try_insert_no_grow and then panic on error.
The text was updated successfully, but these errors were encountered:
The main use case for insert_no_grow is to support the Entry type in libstd which isn't parameterized by S. This means that libstd's entry must reserve space when the Entry is created so that it can later call insert_no_grow without a hasher.
Since it is barely used outside hashbrown, I'm happy to switch this function to being unsafe.
Make `RawTable::insert_no_grow` unsafe
For performance reasons, this method _assumes_ that there is sufficient
capacity for the new element, and it misbehaves otherwise, breaking
invariants or even segfaulting. The necessary conditions could be
checked, but if we're to keep it lean, it should be `unsafe`, so the
burden is on the caller to ensure capacity.
Fixes#253.
This program segfaults:
If I change this to have some initial capacity, then in debug mode it panics decrementing
growth_left
:In release mode that loops forever. I added debug prints for len/capacity, and that gets up to 16/14 before hanging entirely.
I suppose panic/infinite-loop is somewhat acceptable from a safety perspective, as long as we're sure to do one of those without corrupting memory, but the empty case is definitely a problem. Maybe we should assert the same condition that the regular
insert
uses when it decides to resize? We could even use/mimictry_insert_no_grow
and then panic on error.The text was updated successfully, but these errors were encountered: