-
Notifications
You must be signed in to change notification settings - Fork 154
Refactor bmqu::AlignedPrinter to accept vector of strings #895
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
base: main
Are you sure you want to change the base?
Conversation
7a4041a
to
34b70d7
Compare
@bloomberg/blazingmq-maintainers : Can you please take a look at the PR and approve running workflows on it? The PR is not ready for review yet! I saw review comments #605 (comment) from another PR that was submitted for the same issue. This PR's scope is about AlignedPrinter refactoring (issue #564) |
ae9a976
to
d2fd5a0
Compare
…r of strings Complete implementation from PR bloomberg#895: - Updated AlignedPrinter constructor to accept bsl::vector<bsl::string>* - Updated JsonPrinter to maintain API consistency - Replaced bsl::strlen() with bsl::string::length() calls - Added comprehensive unit test suite (bmqu_alignedprinter.t.cpp) - Updated all usage sites across bmqstoragetool, bmqtool, and mqbs modules - Optimized performance with emplace_back() instead of push_back() - Preserved const char* usage for hash/data pointers (not string literals) Files modified: - Core classes: bmqu_alignedprinter.h, bmqu_jsonprinter.h - Test suite: bmqu_alignedprinter.t.cpp (new) - Tools: m_bmqstoragetool_*, m_bmqtool_storageinspector.cpp - Storage: mqbs_filestoreprotocolprinter.* This addresses issue bloomberg#564 by eliminating raw pointer usage for string literals while improving memory safety and following modern C++ practices. Signed-off-by: Kapil Jain <[email protected]>
521d8dd
to
d40cad8
Compare
Apply clang-format to ensure code adheres to project formatting standards. Signed-off-by: Kapil Jain <[email protected]>
9502cf9
to
8b94d64
Compare
The pr-895.patch file was used temporarily to apply changes and should not be included in the final commit. Signed-off-by: Kapil Jain <[email protected]>
9a20961
to
f97164c
Compare
Replace double quotes with single quotes in GitHub Actions if conditions to fix YAML parsing errors. Signed-off-by: Kapil Jain <[email protected]>
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.
Have some comments
, d_counter(0) | ||
{ | ||
BSLS_ASSERT_SAFE(0 <= d_indent); | ||
BSLS_ASSERT_SAFE(0 < d_fields_p->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.
BSLS_ASSERT_SAFE(0 < d_fields_p->size()); | |
BSLS_ASSERT_SAFE(d_fields_p); | |
BSLS_ASSERT_SAFE(0 < d_fields_p->size()); |
There is a small overlook here, we should probably check that the provided fields
arg is not NULL before dereferencing it
bmqu::MemOutStream stream; | ||
bsl::vector<bsl::string> fields; | ||
fields.emplace_back("Queue URI"); | ||
fields.emplace_back("QueueKey"); | ||
fields.emplace_back("Number of AppIds"); | ||
|
||
const int indent = 4; | ||
bmqu::AlignedPrinter printer(stream, &fields, indent); | ||
|
||
// Test printing various types | ||
bsl::string uri = "bmq://bmq.tutorial.workqueue/sample-queue"; | ||
bsl::string queueKey = "sample"; |
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.
bmqu::MemOutStream stream; | |
bsl::vector<bsl::string> fields; | |
fields.emplace_back("Queue URI"); | |
fields.emplace_back("QueueKey"); | |
fields.emplace_back("Number of AppIds"); | |
const int indent = 4; | |
bmqu::AlignedPrinter printer(stream, &fields, indent); | |
// Test printing various types | |
bsl::string uri = "bmq://bmq.tutorial.workqueue/sample-queue"; | |
bsl::string queueKey = "sample"; | |
bslma::Allocator* alloc = bmqtst::TestHelperUtil::allocator(); | |
bmqu::MemOutStream stream(alloc); | |
bsl::vector<bsl::string> fields(alloc); | |
fields.emplace_back("Queue URI"); | |
fields.emplace_back("QueueKey"); | |
fields.emplace_back("Number of AppIds"); | |
const int indent = 4; | |
bmqu::AlignedPrinter printer(stream, &fields, indent); | |
// Test printing various types | |
bsl::string uri("bmq://bmq.tutorial.workqueue/sample-queue", alloc); | |
bsl::string queueKey("sample", alloc); |
We have default allocator checks in UTs
|
||
printer << uri << queueKey << numAppIds; | ||
|
||
bsl::string output = stream.str(); |
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.
bsl::string output = stream.str(); | |
bsl::string output(stream.str(), alloc); |
bmqu::MemOutStream stream; | ||
bsl::vector<bsl::string> fields; | ||
fields.emplace_back("Short"); | ||
fields.emplace_back("Very Long Field Name"); | ||
fields.emplace_back("Med"); | ||
|
||
bmqu::AlignedPrinter printer(stream, &fields, 2); | ||
|
||
printer << "value1" << "value2" << "value3"; | ||
|
||
bsl::string output = stream.str(); |
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.
bmqu::MemOutStream stream; | |
bsl::vector<bsl::string> fields; | |
fields.emplace_back("Short"); | |
fields.emplace_back("Very Long Field Name"); | |
fields.emplace_back("Med"); | |
bmqu::AlignedPrinter printer(stream, &fields, 2); | |
printer << "value1" << "value2" << "value3"; | |
bsl::string output = stream.str(); | |
bslma::Allocator* alloc = bmqtst::TestHelperUtil::allocator(); | |
bmqu::MemOutStream stream(alloc); | |
bsl::vector<bsl::string> fields(alloc); | |
fields.emplace_back("Short"); | |
fields.emplace_back("Very Long Field Name"); | |
fields.emplace_back("Med"); | |
bmqu::AlignedPrinter printer(stream, &fields, 2); | |
printer << "value1" << "value2" << "value3"; | |
bsl::string output(stream.str(), alloc); |
} | ||
|
||
TEST_EPILOG(bmqtst::TestHelper::e_DEFAULT); | ||
} No newline at end of file |
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.
} | |
} | |
#ifdef BDE_BUILD_TARGET_SAFE_2 | ||
// In safe mode, this should assert | ||
BMQTST_ASSERT_SAFE_FAIL(bmqu::AlignedPrinter(stream, &fields, 4)); | ||
#endif |
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.
I think that this test is not necessary. It checks a basic precondition in the code, and this precondition is just 1 line and much simpler than the test itself.
} break; | ||
} | ||
|
||
TEST_EPILOG(bmqtst::TestHelper::e_DEFAULT); |
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.
TEST_EPILOG(bmqtst::TestHelper::e_DEFAULT); | |
TEST_EPILOG(bmqtst::TestHelper::e_CHECK_DEF_GBL_ALLOC); |
Replace bsl::vector<const char*> with bsl::vectorbsl::string in:
Benefits:
Fixes #564
Issue number of the reported bug or feature request: #
Describe your changes
Refactor bmqu::AlignedPrinter to use bsl::vectorbsl::string instead of bsl::vector<const char*> for improved type safety and modern C++ practices.
Key Changes:
Testing performed
Unit Testing:
Additional context
Addresses Issue #564:
This PR directly resolves the "Refactor bmqu::AlignedPrinter to accept vector of strings" issue, implementing the requested modernization of the string handling approach.
Learning from Previous Attempts:
Analyzed failed PR #605 to avoid common pitfalls:
Backward Compatibility:
Code Quality Improvements: