AK: Relax ensure_capacity assertion to allow allocator-rounded capacity#8897
Open
officialasishkumar wants to merge 1 commit intoLadybirdBrowser:masterfrom
Open
AK: Relax ensure_capacity assertion to allow allocator-rounded capacity#8897officialasishkumar wants to merge 1 commit intoLadybirdBrowser:masterfrom
officialasishkumar wants to merge 1 commit intoLadybirdBrowser:masterfrom
Conversation
Collaborator
|
Hello! One or more of the commit messages in this PR do not match the Ladybird code submission policy, please check the |
The ensure_capacity contract guarantees that the resulting capacity is at least the requested value, not exactly equal to it. Allocators such as mimalloc may round up the allocation to an internally efficient size (via mi_good_size), so the actual capacity can exceed the requested amount when building with BUILD_PRESET=Debug. Replace EXPECT_EQ with EXPECT_GE in the json_array_ensure_capacity test to reflect the weaker, correct postcondition. Fixes LadybirdBrowser#8876.
b3fcabc to
4e63abb
Compare
Contributor
|
Hi @officialasishkumar, its a good idea, but did you try the fix locally? I don't think EXPECT_GE is available, which would be available with gtest, but this is not gtest. Have a look at: and for the BigInt some additional macros are created which could give you ideas. See |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
ensure_capacityfunction guarantees that the resulting capacity isat least the requested value; it does not guarantee an exact match. The
underlying
try_ensure_capacityimplementation asks the allocator for a"good" size via
kmalloc_good_size, which maps tomi_good_sizewhenmimalloc is in use. In debug builds mimalloc may return a size larger than
requested, causing the raw element count to exceed
new_capacity.The
json_array_ensure_capacitytest checked for exact equality (EXPECT_EQ)which fails in debug builds with mimalloc. Switch to
EXPECT_GEto testonly the weaker, actually-guaranteed postcondition.
Fixes #8876.