const correctness for public interfaces in MemoryManagedResource#110
Open
ShoroukRamzy wants to merge 2 commits intoeclipse-score:mainfrom
Open
Conversation
|
The created documentation from the pull request is available at: docu-html |
2 tasks
Member
|
Hi @ShoroukRamzy, thank you for your contribution. Can you please rebase your commits? There have been changes in |
f9fbb6d to
9aed359
Compare
9aed359 to
d25e03c
Compare
Contributor
Author
Hi @4og, Thank you for your feedback. Done! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This pull request solves this issue (eclipse-score/communication#84) and improves the API safety and robustness of the score::memory::shared library by enforcing const-correctness on key methods. The primary goal is to prevent accidental modification of internal bookkeeping data within shared memory segments, which could lead to memory corruption.
The following key changes have been implemented:
const Return Types and Methods:
ManagedMemoryResource::getBaseAddress() now returns const void*. This protects the underlying ControlBlock from being modified by external callers.
ManagedMemoryResource::getMemoryResourceProxy() now returns const MemoryResourceProxy* and is a const method. This ensures the integrity of the proxy's identifier.
Derived Class and Mock Updates:
All classes inheriting from ManagedMemoryResource or ISharedMemoryResource (including SharedMemoryResource, NewDeleteDelegateMemoryResource, and all test mocks/fakes) have been updated to correctly override the new const-correct signatures.
Call Site Adjustments:
All call sites that invoke getBaseAddress() or getMemoryResourceProxy() have been updated to correctly handle the const return types.
const_cast has been used in a few specific, controlled instances (primarily in test fakes interacting with the MemoryResourceRegistry) to maintain compatibility with older APIs that were not yet const-aware. This was a pragmatic choice to limit the scope of the refactoring while still achieving the primary safety goal.
How to Test
Build the score/memory library and its dependencies:
bash
bazel build --config=bl-x86_64-linux //score/memory/...Run all associated tests to ensure no regressions have been introduced:
bash
bazel test --config=bl-x86_64-linux //score/memory/...All tests should pass, confirming that the const-correctness changes have been applied consistently and correctly throughout the library and its test suite.