Skip to content

Serialize std::shared_ptr and std::weak_ptr #1352

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

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from

Conversation

leekillough
Copy link
Contributor

@leekillough leekillough commented Jun 4, 2025

This PR provides an initial implementation of serialization of std::shared_ptr and std::weak_ptr.

Unfinished work:

  • Custom deleter functions need to be supported with the SST::Core::Serialization::shared_ptr() and SST::Core::Serialization::weak_ptr() wrapper functions, by adding an extra deleter member to the shared_ptr_wrapper class, and a DELETER template parameter added.

Implementation notes:

std::shared_ptr and std::weak_ptr must both be handled, and a std::shared_ptr does not necessarily return the pointer to the allocated memory when .get() is called, since an aliasing std::shared_ptr can point to a sub-object of the owning std::shared_ptr.

The owning std::shared_ptr must be determined with the std::owner_less functor and .owner_before() methods.

std::shared_ptr and std::weak_ptr can be directly serialized if they point directly to the memory-managed object, but SST::Core::Serialization::shared_ptr() and SST::Core::Serialization::weak_ptr() wrapper functions must be used when the std::shared_ptr or std::weak_ptr may alias another object which manages the memory, in which case the owning object must be passed as well during serialization.

std::shared_ptr and std::weak_ptr to unbounded array types, such as std::shared_ptr<int[]> must also use helpers similar to SST::Core::Serialization::array() to indicate a size variable for the size of the array which is serialized/deserialized when the std::shared_ptr or std::weak_ptr is serialized.

When a std::shared_ptr or std::weak_ptr is (de)serialized, std::map/std::deque are searched to find out if its owner has been seen before, and to (de)serialize the owning object the first time it is seen.

@github-actions github-actions bot added AT: WIP Mark PR as a Work in Progress (No Autotesting Performed) AT: CLANG-FORMAT PASS and removed AT: WIP Mark PR as a Work in Progress (No Autotesting Performed) labels Jun 4, 2025
Copy link

github-actions bot commented Jun 4, 2025

CLANG-FORMAT TEST - PASSED

@github-actions github-actions bot added AT: WIP Mark PR as a Work in Progress (No Autotesting Performed) AT: CMAKE-FORMAT PASS and removed AT: WIP Mark PR as a Work in Progress (No Autotesting Performed) labels Jun 4, 2025
Copy link

github-actions bot commented Jun 4, 2025

CMAKE-FORMAT TEST - PASSED

@sst-autotester
Copy link
Contributor

Status Flag 'Pre-Test Inspection' - - This Pull Request Requires Inspection... The code must be inspected by a member of the Team before Testing/Merging
NO INSPECTION HAS BEEN PERFORMED ON THIS PULL REQUEST! - This PR must be inspected by setting label 'AT: PRE-TEST INSPECTED'.

@leekillough leekillough force-pushed the serialize_shared_ptr branch from f495b09 to 65030ea Compare June 4, 2025 19:11
@github-actions github-actions bot added AT: WIP Mark PR as a Work in Progress (No Autotesting Performed) and removed AT: WIP Mark PR as a Work in Progress (No Autotesting Performed) labels Jun 4, 2025
Copy link

github-actions bot commented Jun 4, 2025

CLANG-FORMAT TEST - PASSED

@github-actions github-actions bot added AT: WIP Mark PR as a Work in Progress (No Autotesting Performed) and removed AT: WIP Mark PR as a Work in Progress (No Autotesting Performed) labels Jun 4, 2025
Copy link

github-actions bot commented Jun 4, 2025

CMAKE-FORMAT TEST - PASSED

@sst-autotester
Copy link
Contributor

Status Flag 'Pre-Test Inspection' - - This Pull Request Requires Inspection... The code must be inspected by a member of the Team before Testing/Merging
NO INSPECTION HAS BEEN PERFORMED ON THIS PULL REQUEST! - This PR must be inspected by setting label 'AT: PRE-TEST INSPECTED'.

@leekillough leekillough force-pushed the serialize_shared_ptr branch from 65030ea to 18e518a Compare June 6, 2025 02:47
@github-actions github-actions bot added AT: WIP Mark PR as a Work in Progress (No Autotesting Performed) AT: CLANG-FORMAT FAIL labels Jun 6, 2025
Copy link

github-actions bot commented Jun 6, 2025

CLANG-FORMAT TEST - FAILED (on last commit):
Run > ./scripts/clang-format-test.sh using clang-format v20 to check formatting

@github-actions github-actions bot removed AT: CLANG-FORMAT PASS AT: WIP Mark PR as a Work in Progress (No Autotesting Performed) labels Jun 6, 2025
Copy link

github-actions bot commented Jun 6, 2025

CMAKE-FORMAT TEST - PASSED

@sst-autotester
Copy link
Contributor

Status Flag 'Pre-Test Inspection' - - This Pull Request Requires Inspection... The code must be inspected by a member of the Team before Testing/Merging
NO INSPECTION HAS BEEN PERFORMED ON THIS PULL REQUEST! - This PR must be inspected by setting label 'AT: PRE-TEST INSPECTED'.

@leekillough leekillough force-pushed the serialize_shared_ptr branch from 18e518a to 8d9f792 Compare June 6, 2025 02:54
@github-actions github-actions bot added AT: WIP Mark PR as a Work in Progress (No Autotesting Performed) and removed AT: WIP Mark PR as a Work in Progress (No Autotesting Performed) labels Jun 6, 2025
Copy link

github-actions bot commented Jun 6, 2025

CMAKE-FORMAT TEST - PASSED

@github-actions github-actions bot added the AT: WIP Mark PR as a Work in Progress (No Autotesting Performed) label Jun 6, 2025
@sst-autotester
Copy link
Contributor

Status Flag 'Pre-Test Inspection' - - This Pull Request Requires Inspection... The code must be inspected by a member of the Team before Testing/Merging
NO INSPECTION HAS BEEN PERFORMED ON THIS PULL REQUEST! - This PR must be inspected by setting label 'AT: PRE-TEST INSPECTED'.

@leekillough leekillough marked this pull request as ready for review July 19, 2025 02:50
@github-actions github-actions bot added AT: WIP Mark PR as a Work in Progress (No Autotesting Performed) AT: CLANG-FORMAT FAIL and removed AT: CLANG-FORMAT PASS labels Jul 20, 2025
Copy link

CLANG-FORMAT TEST - FAILED (on last commit):
Run > ./scripts/clang-format-test.sh using clang-format v20 to check formatting

@github-actions github-actions bot removed the AT: WIP Mark PR as a Work in Progress (No Autotesting Performed) label Jul 20, 2025
Copy link

CMAKE-FORMAT TEST - PASSED

@leekillough leekillough force-pushed the serialize_shared_ptr branch from 88b2765 to 769a1cf Compare July 20, 2025 07:58
@github-actions github-actions bot added the AT: WIP Mark PR as a Work in Progress (No Autotesting Performed) label Jul 20, 2025
Copy link

CLANG-FORMAT TEST - FAILED (on last commit):
Run > ./scripts/clang-format-test.sh using clang-format v20 to check formatting

@github-actions github-actions bot removed the AT: WIP Mark PR as a Work in Progress (No Autotesting Performed) label Jul 20, 2025
Copy link

CMAKE-FORMAT TEST - PASSED

@leekillough leekillough force-pushed the serialize_shared_ptr branch from 769a1cf to 1f5b9af Compare July 20, 2025 08:01
@github-actions github-actions bot added AT: WIP Mark PR as a Work in Progress (No Autotesting Performed) AT: CLANG-FORMAT PASS and removed AT: WIP Mark PR as a Work in Progress (No Autotesting Performed) AT: CLANG-FORMAT FAIL labels Jul 20, 2025
Copy link

CLANG-FORMAT TEST - PASSED

Copy link

CMAKE-FORMAT TEST - PASSED

@sst-autotester
Copy link
Contributor

Status Flag 'Pre-Test Inspection' - - This Pull Request Requires Inspection... The code must be inspected by a member of the Team before Testing/Merging
NO INSPECTION HAS BEEN PERFORMED ON THIS PULL REQUEST! - This PR must be inspected by setting label 'AT: PRE-TEST INSPECTED'.

@leekillough leekillough force-pushed the serialize_shared_ptr branch from 1f5b9af to 9e0da66 Compare July 20, 2025 20:40
@github-actions github-actions bot added AT: WIP Mark PR as a Work in Progress (No Autotesting Performed) and removed AT: WIP Mark PR as a Work in Progress (No Autotesting Performed) labels Jul 20, 2025
Copy link

CMAKE-FORMAT TEST - PASSED

Copy link

CLANG-FORMAT TEST - PASSED

@sst-autotester
Copy link
Contributor

Status Flag 'Pre-Test Inspection' - - This Pull Request Requires Inspection... The code must be inspected by a member of the Team before Testing/Merging
NO INSPECTION HAS BEEN PERFORMED ON THIS PULL REQUEST! - This PR must be inspected by setting label 'AT: PRE-TEST INSPECTED'.

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

Successfully merging this pull request may close these issues.

3 participants