Skip to content

[FIX] Make object construction exception-safe#650

Merged
tqchen merged 3 commits into
apache:mainfrom
tqchen:make-object-exception-safe
Jul 4, 2026
Merged

[FIX] Make object construction exception-safe#650
tqchen merged 3 commits into
apache:mainfrom
tqchen:make-object-exception-safe

Conversation

@tqchen

@tqchen tqchen commented Jul 4, 2026

Copy link
Copy Markdown
Member

This change makes SimpleObjAllocator strongly exception-safe when placement construction throws.

It adds an allocator-local allocation guard to both ordinary object and variable-sized array creation. The guard frees the matching aligned allocation during exception unwinding and is disarmed after successful construction. A focused object test verifies constructor exceptions propagate through make_object.

tqchen added 3 commits July 4, 2026 01:26
GCC 11.4 -O3 unsafe-vs-final A/B keeps the no-throw path at 22/22 executed instructions and a byte-identical 85-byte section, while throwing object and array paths remain 28/28 instructions through their first ret with no added guard branch, disarm store, destructor/free call, or memory operation.

The throwing hot sections grow 112 to 130 bytes and 115 to 133 bytes: 6 bytes are accepted register/encoding changes and 12 bytes are an unreachable post-ret EH trampoline. free remains exclusive to the cold landing pads, whose sections grow from 5 to 21 bytes.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces exception safety to SimpleObjAllocator by implementing an AllocGuard RAII helper. This guard ensures that allocated memory is properly freed if an exception is thrown during the in-place construction of an object. Additionally, a unit test has been added to verify that constructor exceptions are correctly propagated. I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@tqchen tqchen merged commit 331664c into apache:main Jul 4, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants