Skip to content

Use the provided allocator in destroy() (#4842) - #4843

Closed
veselink1 wants to merge 3 commits into
nlohmann:developfrom
veselink1:develop
Closed

veselink1 wants to merge 3 commits into
nlohmann:developfrom
veselink1:develop

Conversation

@veselink1

Copy link
Copy Markdown
Contributor

Uses the provided allocator to allocate the stack used to avoid recursion in the destroy() implementation used by ~basic_json.

This addresses issue #4842, by changing the std::vector to use the user-provided allocatorl

Uses the provided allocator to allocate the stack used to avoid
recursion in the destroy() implementation used by ~basic_json.
@veselink1
veselink1 requested a review from nlohmann as a code owner July 4, 2025 11:52
@github-actions github-actions Bot added the S label Jul 4, 2025
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 99.19%. remained the same
when pulling ff3eaf8 on veselink1:develop
into d33ecd3 on nlohmann:develop.

@github-actions

github-actions Bot commented Aug 4, 2025

Copy link
Copy Markdown

This pull request has been marked as stale because it has had no activity for 30 days. While we won’t close it automatically, we encourage you to update or comment if it is still relevant. Keeping pull requests active and up-to-date helps us review and merge changes more efficiently. Thank you for your contributions!

@github-actions github-actions Bot added the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label Aug 4, 2025
@nlohmann nlohmann added please rebase Please rebase your branch to origin/develop and removed state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated labels Aug 7, 2025
@nlohmann

nlohmann commented Aug 7, 2025

Copy link
Copy Markdown
Owner

Please rebase to the latest develop branch to have a green CI.

@github-actions

github-actions Bot commented Sep 7, 2025

Copy link
Copy Markdown

This pull request has been marked as stale because it has had no activity for 30 days. While we won’t close it automatically, we encourage you to update or comment if it is still relevant. Keeping pull requests active and up-to-date helps us review and merge changes more efficiently. Thank you for your contributions!

@github-actions github-actions Bot added the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label Sep 7, 2025
@github-actions github-actions Bot removed the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label Oct 24, 2025
@github-actions

Copy link
Copy Markdown

This pull request has been marked as stale because it has had no activity for 30 days. While we won’t close it automatically, we encourage you to update or comment if it is still relevant. Keeping pull requests active and up-to-date helps us review and merge changes more efficiently. Thank you for your contributions!

@github-actions github-actions Bot added the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label Nov 23, 2025
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
Adds a regression test for nlohmann#4842: destroying a nested array or object must allocate its temporary stack through the basic_json allocator, not std::allocator.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
@nlohmann nlohmann removed state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated state: waiting for PR please rebase Please rebase your branch to origin/develop labels Sep 24, 2026
@nlohmann

Copy link
Copy Markdown
Owner

Thanks a lot for the fix, @veselink1, and sorry this sat for so long. I merged the latest develop into your branch and added a regression test to unit-allocator.cpp. The test uses a counting allocator and checks that destroying a nested array or object allocates the temporary stack through it. It fails without your change and passes with it. Once CI is green, this is good to go.

This comment was written by Claude Code on behalf of @nlohmann.

@nlohmann nlohmann linked an issue Sep 24, 2026 that may be closed by this pull request
2 tasks done
@gregmarr

Copy link
Copy Markdown
Contributor

@nlohmann I wonder if any of the other temporary vectors added in the recent iterative cleanups should also use the provided allocator.

@nlohmann

Copy link
Copy Markdown
Owner

@gregmarr Good question, thanks! I went through them. Most of the new temporary vectors hold only pointers, iterators and counters: the copy worklist and the stacks for merging (#5547), hashing (#5546), dump() (#5285) and the binary readers (#5505). That's the same as the parser's ref_stack or the lexer's token_string, which have always used std::allocator.

The one exception is the deep copy's key scratch space from #5389. It holds std::pair<key_type, basic_json> values, so it should use the provided allocator just like the destructor's stack here. That's #5573, which also documents that AllocatorType allocates the JSON values while most temporary storage still uses std::allocator.

This comment was written by Claude Code on behalf of @nlohmann.

@github-actions github-actions Bot added M tests and removed S labels Sep 25, 2026
@nlohmann

Copy link
Copy Markdown
Owner

@veselink1 Are you willing to complete this?

@nlohmann

nlohmann commented Oct 4, 2026

Copy link
Copy Markdown
Owner

Thanks a lot for this fix, @veselink1! Since we didn't hear back, we continued in #5762. Your commit is included there with you as author. With the allocator in place, a failing allocator could make the destructor throw (#5135), so #5762 goes one step further and makes destruction completely allocation-free.

This comment was written by Claude Code on behalf of @nlohmann.

@nlohmann nlohmann closed this Oct 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

json destructor does not use the provided allocator

4 participants