Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upRecycled values cannot contain references to other values from the same Pool #17
Comments
pushed a commit
that referenced
this issue
Nov 13, 2018
This comment has been minimized.
This comment has been minimized.
|
Fixed by 5bd809b. |
zslayton
closed this
Nov 13, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
zslayton commentedNov 8, 2018
The
Dropimplementation for theRecycledInnertype is responsible for returning the value being dropped to thePoolthat originally issued it.The
insert_or_dropmethod performs two operations:CappedCollectionhas available capacity, the provided value will bereset()and then added to thePoolagain.drop()ed.If the value contains other values from the same
Pool(e.g. it's a nested container, like aVecthat indirectly contains otherVecs), the call toreset()in step 1 will cause the program topanic!(). This happens because the call toinsert_or_dropuses a mutable borrow of theRefCell<CappedCollection<_>>. A nested call toinsert_or_dropwill also try to mutably borrow theRefCell<CappedCollection<_>>, causingRefCell's runtime validation logic topanic!().This can be fixed by refactoring the
Dropimplementation to:RefCell<CappedCollection<_>>to test its available capacity.reset()on the value being returned to thePool. (Notice that we're now resetting it without holding a mutable reference to theRefCell<CappedCollection<_>>.) Then mutably borrow the collection and add the value to it.