-
Notifications
You must be signed in to change notification settings - Fork 12
chore: any_buffers are value types #67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
An automated preview of the documentation is available at https://67.buffers.prtest.cppalliance.org/index.html If more commits are pushed to the pull request, the docs will rebuild at the same URL. 2025-12-06 23:22:04 UTC |
|
GCOVR code coverage report https://67.buffers.prtest.cppalliance.org/gcovr/index.html Build time: 2025-12-06 23:37:39 UTC |
33146f5 to
b03f2fb
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #67 +/- ##
===========================================
- Coverage 94.38% 93.57% -0.81%
===========================================
Files 17 18 +1
Lines 694 825 +131
===========================================
+ Hits 655 772 +117
- Misses 39 53 +14
... and 2 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
|
@claude review this pull request and write a summary of its quality, pros and cons |
|
Claude finished @vinniefalco's task —— View job Code Review CompleteSummaryThis PR refactors AnalysisArchitectural ChangesBefore (implied): After: Based on the code visible in the current implementation and the PR title "any_buffers are value types," the refactoring provides:
Code Quality Assessment✅ Strengths
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR transforms any_buffers from a non-owning reference type to a value type with proper copy semantics and ownership. The implementation uses small buffer optimization (SBO) to store small buffer sequences inline, and uses atomic reference counting for larger sequences that require heap allocation. This is a significant architectural change that makes any_buffers safer and easier to use.
Key Changes
- Added destructor, copy constructor, and copy assignment operator to
any_buffersto enable value semantics - Implemented reference counting with
std::atomicfor large buffer sequences that don't fit in SBO - Removed the old
any_buffers_implandmake_any_buffershelper, as they're no longer needed with value semantics - Added comprehensive tests for empty buffer sequences and value type behavior
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 9 comments.
| File | Description |
|---|---|
| src/any_buffers.cpp | Implements default constructors for any_buffers<true> and any_buffers<false>, plus iterator default constructors |
| include/boost/buffers/any_buffers.hpp | Major refactoring: added value type semantics (destructor, copy constructor, assignment), implemented SBO with reference counting, removed old wrapper classes |
| test/unit/any_buffers.cpp | Added comprehensive tests for empty buffers, value semantics, and helper functions for testing const/mutable buffers |
| std::size_t len_ = 0; | ||
| iter_ops const* ops_ = nullptr; | ||
| alignas(std::max_align_t) | ||
| unsigned char mutable storage_[sbo_size] = {}; |
Copilot
AI
Dec 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mutable keyword is incorrectly placed. It should come before the type (unsigned char), not between alignas and the type. The correct syntax is:
alignas(std::max_align_t) unsigned char storage_[sbo_size] = {};Then add mutable before unsigned char:
alignas(std::max_align_t) mutable unsigned char storage_[sbo_size] = {};| unsigned char mutable storage_[sbo_size] = {}; | |
| mutable unsigned char storage_[sbo_size] = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot how do you explain that it compiles on the many targets in CI?
|
|
||
| void destroy(std::false_type) const | ||
| { | ||
| if(--refs_ == 0) |
Copilot
AI
Dec 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The atomic decrement operation is not thread-safe in this context. The check-then-delete pattern if(--refs_ == 0) delete this; creates a race condition. Use fetch_sub with memory ordering:
if(refs_.fetch_sub(1, std::memory_order_acq_rel) == 1)
delete this;The same issue exists at line 355-356.
| if(--refs_ == 0) | |
| // atomically decrement and delete if last reference | |
| if(refs_.fetch_sub(1, std::memory_order_acq_rel) == 1) |
|
|
||
| void copy(any_buffers& dest, std::false_type) const | ||
| { | ||
| ++refs_; |
Copilot
AI
Dec 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The atomic increment operation should use an explicit memory ordering. Use:
refs_.fetch_add(1, std::memory_order_relaxed);This is more explicit about the intended semantics. The same issue exists at line 374.
| ++refs_; | |
| refs_.fetch_add(1, std::memory_order_relaxed); |
| void copy(any_buffers<IsConst>& dest, | ||
| std::false_type) const | ||
| { | ||
| ++refs_; |
Copilot
AI
Dec 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The atomic increment operation should use an explicit memory ordering. Use:
refs_.fetch_add(1, std::memory_order_relaxed);This is more explicit about the intended semantics.
| ++refs_; | |
| refs_.fetch_add(1, std::memory_order_relaxed); |
| /** Constructor. | ||
| Default-constructed objects are empty with zero length. | ||
| */ |
Copilot
AI
Dec 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per coding guidelines, brief documentation comments should be followed by a newline before additional details. The format should be:
/** Default constructor.
Default-constructed objects are empty with zero length.
*/| /** Constructor. | ||
| The type-erased buffer sequence is constructed | ||
| from the specified buffer sequence, which must satisfy | ||
| `ConstBufferSequence`. If `IsConst` is `false`, must | ||
| also satisfy `MutableBufferSequence`. | ||
| @param buffers The buffer sequence to type-erase. | ||
| */ |
Copilot
AI
Dec 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per coding guidelines, documentation should have a newline after the brief, and @param should come last in the documentation. Suggested format:
/** Constructor.
The type-erased buffer sequence is constructed
from the specified buffer sequence, which must satisfy
`ConstBufferSequence`. If `IsConst` is `false`, must
also satisfy `MutableBufferSequence`.
@param buffers The buffer sequence to type-erase.
*/|
|
||
| void destroy(std::false_type) const | ||
| { | ||
| if(--refs_ == 0) |
Copilot
AI
Dec 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The atomic decrement operation is not thread-safe in this context. The check-then-delete pattern if(--refs_ == 0) delete this; creates a race condition. Use fetch_sub with memory ordering:
if(refs_.fetch_sub(1, std::memory_order_acq_rel) == 1)
delete this;| if(--refs_ == 0) | |
| // atomically decrement and delete if last reference | |
| if(refs_.fetch_sub(1, std::memory_order_acq_rel) == 1) |
| /** Constructor. | ||
| */ |
Copilot
AI
Dec 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per coding guidelines, this comment lacks a proper brief description. It should have a brief followed by a newline and details:
/** Copy constructor.
Constructs a copy of the buffer sequence wrapped by `other`.
*/| /** Assignment. | ||
| */ |
Copilot
AI
Dec 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per coding guidelines, this comment lacks a proper brief description. It should have a brief followed by a newline and details:
/** Copy assignment.
Assigns a copy of the buffer sequence wrapped by `other`.
*/
No description provided.