Skip to content

const correctness for public interfaces in MemoryManagedResource#110

Open
ShoroukRamzy wants to merge 2 commits intoeclipse-score:mainfrom
Valeo-S-CORE-Organization:const-correctness-managedmemoryresource
Open

const correctness for public interfaces in MemoryManagedResource#110
ShoroukRamzy wants to merge 2 commits intoeclipse-score:mainfrom
Valeo-S-CORE-Organization:const-correctness-managedmemoryresource

Conversation

@ShoroukRamzy
Copy link
Contributor

@ShoroukRamzy ShoroukRamzy commented Feb 25, 2026

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.

@github-actions
Copy link

The created documentation from the pull request is available at: docu-html

@4og
Copy link
Member

4og commented Feb 27, 2026

Hi @ShoroukRamzy, thank you for your contribution. Can you please rebase your commits? There have been changes in score/memory/shared in 1198d85

@ShoroukRamzy ShoroukRamzy force-pushed the const-correctness-managedmemoryresource branch from f9fbb6d to 9aed359 Compare March 1, 2026 09:46
@ShoroukRamzy ShoroukRamzy force-pushed the const-correctness-managedmemoryresource branch from 9aed359 to d25e03c Compare March 1, 2026 12:06
@ShoroukRamzy
Copy link
Contributor Author

Hi @ShoroukRamzy, thank you for your contribution. Can you please rebase your commits? There have been changes in score/memory/shared in 1198d85

Hi @4og, Thank you for your feedback. Done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

2 participants