Skip to content

Commit

Permalink
- Explicitly static_assert if raw pointers are used when calling "gro…
Browse files Browse the repository at this point in the history
…w" as it was never supported.

- Update documentation to state this.

- Fixes #220 ("basic_managed_shared_memory::grow() do not return when using raw pointers")
  • Loading branch information
igaztanaga committed Sep 26, 2024
1 parent e7ed694 commit a22d498
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/boost/interprocess/managed_external_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ class basic_managed_external_buffer
return *this;
}

//!Tries to resize internal heap memory so that
//!we have room for more objects.
void grow(size_type extra_bytes)
{ base_t::grow(extra_bytes); }

Expand Down
3 changes: 3 additions & 0 deletions include/boost/interprocess/managed_mapped_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ class basic_managed_mapped_file
//!
//!This function is not synchronized so no other thread or process should
//!be reading or writing the file
//!
//!Since the memory will be remapped after the underlying file
//!is grown, it can't work with segments using raw pointers.
static bool grow(const char *filename, size_type extra_bytes)
{
return base_t::template grow
Expand Down
3 changes: 3 additions & 0 deletions include/boost/interprocess/managed_shared_memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ class basic_managed_shared_memory
//!
//!This function is not synchronized so no other thread or process should
//!be reading or writing the file
//!
//!Since the memory will be remapped after the underlying shared memory
//!is grown, it can't work with segments using raw pointers.
static bool grow(const char *shmname, size_type extra_bytes)
{
return base_t::template grow
Expand Down
6 changes: 5 additions & 1 deletion include/boost/interprocess/segment_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,11 @@ class segment_manager_base
//!Increases managed memory in extra_size bytes more. This only works
//!with single-segment management.
void grow(size_type extra_size)
{ MemoryAlgorithm::grow(extra_size); }
{
//Growing managed segments that use raw pointers is UB, so disallow it.
BOOST_INTERPROCESS_STATIC_ASSERT(!(ipcdetail::is_same<void*, void_pointer>::value));
MemoryAlgorithm::grow(extra_size);
}

//!Decreases managed memory to the minimum. This only works
//!with single-segment management.
Expand Down

0 comments on commit a22d498

Please sign in to comment.