Add ImageMetadata::store_string() and document why _GLIBCXX_USE_CXX11_ABI=0 #1149
[Optional] Use a source with no byte beyond the view
AI-assisted review comment (optional suggestion 1/1).
Optional: the truncated-view case checks the destination terminator, but its source literal has valid storage beyond the four-byte view. A four-byte array with no terminator would also catch a future size() + 1 source read under ASan. The present implementation already passes this case; this is regression-test strengthening, not a correctness finding.
Validation: The actual store_string() body passed a host harness with a real monotonic_buffer_resource under AddressSanitizer and UndefinedBehaviorSanitizer, including empty, bounded/nonterminated, embedded-NUL, and arena-growth cases. The harness used macOS libc++, not Linux libstdc++'s dual ABI. Full cuCIM/Catch2, plugin, and slide integration tests were not run. The optional patch passed git apply --check without being applied.
<details>
<summary>Detailed reasoning, proposed patch, and regression coverage</summary>
Location: cpp/tests/test_metadata.cpp:143-157.
Classification: Non-blocking test-strengthening suggestion, not a bug in the current implementation.
The existing truncated-view test is useful, but its source is the string literal "DAPI/FITC". Reading one extra byte would still be within that literal's storage. A four-byte nonterminated source, run under ASan, more directly guards against future reintroduction of a size() + 1 source read.
Suggested test patch
diff --git a/cpp/tests/test_metadata.cpp b/cpp/tests/test_metadata.cpp
--- a/cpp/tests/test_metadata.cpp
+++ b/cpp/tests/test_metadata.cpp
@@ -152,6 +152,16 @@
REQUIRE(stored.data()[4] == '\0');
}
+ SECTION("a bounded view does not require a source terminator")
+ {
+ const char source[] = { 'D', 'A', 'P', 'I' };
+ std::string_view stored = metadata.store_string(
+ std::string_view{ source, sizeof(source) });
+
+ REQUIRE(stored == "DAPI");
+ REQUIRE(stored.data()[stored.size()] == '\0');
+ }
+
SECTION("an empty value is still a valid null-terminated string")
{
std::string_view stored = metadata.store_string(std::string_view{});
</details>
Thank you @cdinea for the change!
AI-assisted review. No actionable correctness defect was identified in this review. Sharing one explicitly optional, non-blocking test-strengthening suggestion inline.
Reviewed commit: 8831f7ef45c40acf9afc65567b6dc3b3f05caebd. The PR description was read before the diff; the current head and inline locations were rechecked before publication.
Validation and limitations: The actual store_string() body passed a host harness with a real monotonic_buffer_resource under AddressSanitizer and UndefinedBehaviorSanitizer, including empty, bounded/nonterminated, embedded-NUL, and arena-growth cases. The harness used macOS libc++, not Linux libstdc++'s dual ABI. Full cuCIM/Catch2, plugin, and slide integration tests were not run. The optional patch passed git apply --check without being applied.
This is a non-blocking COMMENT review, not an approval or formal request for changes. No implementation changes or fixes were applied.
<details>
<summary>Review scope and additional context</summary>
Scope and method
Ran gh pr checkout 1149, read gh pr view 1149, then reviewed gh pr diff 1149 --color never. Reviewed all eleven changed files, including the three refactored call sites, metadata resource lifetime, descriptor setters, test registration, and all six CMake ABI-definition sites.
The description explicitly preserves the old ABI and defers any ABI migration. This review does not treat retaining _GLIBCXX_USE_CXX11_ABI=0 as a defect.
Source locations refer to the reviewed head. PR diff excerpts are contextual, not standalone patches. The optional test patch is a proposal only.
Implementation assessment
The new helper is in cpp/src/io/format/image_format.cpp:27-38:
--- a/cpp/src/io/format/image_format.cpp
+++ b/cpp/src/io/format/image_format.cpp
@@ -26,0 +27,12 @@
+std::string_view ImageMetadata::store_string(std::string_view value)
+{
+ char* buf = static_cast<char*>(res_.allocate(value.size() + 1, alignof(char)));
+ if (!value.empty())
+ {
+ std::memcpy(buf, value.data(), value.size());
+ }
+ // Terminate explicitly rather than copying value.size() + 1 bytes: `value` may
+ // be a view into a longer buffer, in which case the extra byte is not a '\0'.
+ buf[value.size()] = '\0';
+ return std::string_view{ buf, value.size() };
+}
The implementation correctly:
ImageMetadata object's monotonic resource that owns the resulting view's storage.memcpy for an empty, null-data string_view, while still returning an allocated one-byte empty C string.value.size().The three refactored call sites preserve the relevant source lifetime and termination behavior:
| Call site | Reviewed location | Assessment |
| --- | --- | --- |
| cuslide2 channel names | cpp/plugins/cucim.kit.cuslide2/src/cuslide/cuslide.cpp:284-289 | Copies each temporary std::string into out_metadata before the temporary vector is destroyed |
| Read-region spacing units | cpp/src/cuimage.cpp:857-868 | Retains the null-pointer fallback and bounded source length |
| Read-region coordinate system | cpp/src/cuimage.cpp:897-906 | Retains the null guard and bounded source length |
The existing descriptor setters may reuse already-terminated views. Views returned by this helper have a valid byte at data()[size()] and storage tied to the metadata object, so that reuse is safe at these changed sites.
Adding a nonvirtual member function does not alter the metadata descriptor layout or change the existing ABI macro. All six CMake sites still set the same value, 0.
Remaining integration coverage
cucim_tests executable with the specific Catch2 test name ImageMetadata::store_string copies into metadata memory; the broader [test_metadata.cpp] tag also includes slide-dependent tests.No implementation files were changed during this review.
</details>
thank you for the review @gigony - I addressed the review in this commit https://github.com/rapidsai/cucim/pull/1149/commits/3b2c0d9601a4a83273731feec8595b28582bb04c
Thank you @cdinea for handling this.
It looks good to me!
Agree we should revisit this. Think it is reasonable to switch to the new C++11 string ABI. Have raised an issue to track this: https://github.com/rapidsai/cucim/issues/1163
Though also agree it should be in a dedicated PR that makes this change. Let's revisit in 26.12
Thanks Cristiana! 🙏
As a clarifying comment/change, think this is ok.
Though agree we should revisit this setting and switch to the newer C++11 string ABI. Let's discuss in 26.12
For now 26.10, this change looks good
/ok to test cdab1f9c2efcbf48c0a7d3f3b8b5198c067a9402
/merge
Looks like we are missing style fixes. Once those are pushed (and CI passes). This should be good to go
/ok to test d67894b
/ok to test 971ab8e
thank you for the guidance @jakirkham
/ok to test 0a17cd1
gigony
cdinea
Summary
Addresses review feedback on the OME channel-name change, which asked two things:
Answering the question
_GLIBCXX_USE_CXX11_ABI=0dates to the initial commit and was set for manylinux2014 wheels: that platform tag requires a gcc4-compatible libstdc++ ABI (gcc configured with--with-default-libstdcxx-abi=gcc4-compatible), which forces the old ABI on CentOS 7. The reason was recorded in exactly one place — a comment insideimage_format.h— while all six CMake files that actually set the flag carried a misleading# TODO: create two library, one with CXX11 ABI and one without it.Why the two asks are coupled
std::pmr::stringis only defined for the new libstdc++ ABI, so this flag removes it. Confirmed directly:That is also why
ImageMetadatakeeps two sets of member declarations under#if _GLIBCXX_USE_CXX11_ABI, and why the suggested form was already sitting commented out incuimage.cpp:Why not just flip the flag
cpp/CMakeLists.txtexports the definition as anINTERFACEcompile definition, so it lands in the installedcucim-targets.cmakeand is part of the package's contract — flipping it is an ABI break for anything already linked againstlibcucim, not a local cleanup. Worth noting the original justification does look obsolete (the repo no longer references manylinux anywhere andrequires-pythonis>=3.11), but that deserves its own deliberate change. This PR documents the situation instead of acting on it.Changes
ImageMetadata::store_string()— copies a string into the metadata's own memory resource and returns astd::string_viewof the copy. This is what the call sites actually wanted, and it is whatstd::pmr::stringwould have been used for. It works under either ABI setting, so it needs no revisiting if the flag is ever flipped.coord_sysstrings inCuImage::read_region(). The stale commented-outstd::pmr::stringattempts are removed.CMakeLists.txt.cpp/tests/test_metadata.cpp.One subtlety worth a reviewer's eye:
store_string()writes the terminator itself rather than copyingsize() + 1bytes, because the input may be a view into a longer buffer whose following byte is not'\0'(e.g.std::string_view{"DAPI/FITC", 4}). The old channel-name code copiedsize() + 1and was only safe because its source was always astd::string.Testing
store_string()cases need no GPU or slide files, unlike the rest oftest_metadata.cpp.-fsanitize=address,undefinedwith_GLIBCXX_USE_CXX11_ABI=0; all assertions pass clean, including the truncated-view and empty-string cases.image_format.cpp,cuimage.cpp,cuslide.cpp, andtest_metadata.cppall pass full semantic analysis (-fsyntax-onlywith each file's real compile-database flags).