You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by bn...@apache.org on 2024/01/30 16:26:59 UTC
(trafficserver-libswoc) 05/09: Fix override of operator delete and constructor for MemArena::Block.
This is an automated email from the ASF dual-hosted git repository.
bneradt pushed a commit to branch dev-1-2-7
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git
commit 9d8f6f5338544d7810648e1029c485c3bed4985a
Author: Alan M. Carroll <am...@apache.org>
AuthorDate: Fri Jun 19 12:32:39 2020 -0500
Fix override of operator delete and constructor for MemArena::Block.
---
code/include/swoc/MemArena.h | 38 ++++++++++++++++++++++++++++++--------
code/src/MemArena.cc | 5 -----
2 files changed, 30 insertions(+), 13 deletions(-)
diff --git a/code/include/swoc/MemArena.h b/code/include/swoc/MemArena.h
index 36cf131..2bdaf68 100644
--- a/code/include/swoc/MemArena.h
+++ b/code/include/swoc/MemArena.h
@@ -72,17 +72,36 @@ public:
/// @return @c true if the block has at least @c MIN_FREE_SPACE bytes free.
bool is_full() const;
- /** Override standard delete.
+
+ protected:
+ friend MemArena;
+
+ /** Override @c operator @c delete.
*
- * This is required because the allocated memory size is larger than the class size which requires
- * calling @c free differently.
+ * This is required because the allocated memory size is larger than the class size which
+ * requires calling @c free directly, skipping the destructor and avoiding complaints about size
+ * mismatches.
*
* @param ptr Memory to be de-allocated.
*/
- static void operator delete(void *ptr);
+ static void operator delete(void * ptr) noexcept;
- protected:
- friend MemArena;
+ /** Override placement (non-allocated) @c delete.
+ *
+ * @param ptr Pointer returned from @c new
+ * @param place Value passed to @c new.
+ *
+ * This is called only when the class constructor throws an exception during placement new.
+ *
+ * @note I think the parameters are described correctly, the documentation I can find is a bit
+ * vague on the source of these values. It is required even if the constructor is marked @c
+ * noexcept. Both are kept in order to be documented.
+ *
+ * @internal This is required by ICC, but not GCC. Annoying, but it appears this is a valid
+ * interpretation of the spec. In practice this is never called because the constructor does
+ * not throw.
+ */
+ static void operator delete([[maybe_unused]] void * ptr, void * place) noexcept;
/** Construct to have @a n bytes of available storage.
*
@@ -90,7 +109,7 @@ public:
* memory already allocated immediately after this instance.
* @param n The amount of storage.
*/
- explicit Block(size_t n);
+ explicit Block(size_t n) noexcept;
size_t size; ///< Actual block size.
size_t allocated{0}; ///< Current allocated (in use) bytes.
@@ -389,7 +408,7 @@ inline auto MemArena::Block::Linkage::prev_ptr(Block *b) -> Block *& {
return b->_link._prev;
}
-inline MemArena::Block::Block(size_t n) : size(n) {}
+inline MemArena::Block::Block(size_t n) noexcept : size(n) {}
inline char *MemArena::Block::data() {
return reinterpret_cast<char *>(this + 1);
@@ -441,6 +460,9 @@ inline MemArena::Block& MemArena::Block::discard() {
return *this;
}
+inline void MemArena::Block::operator delete(void *ptr) noexcept { ::free(ptr); }
+inline void MemArena::Block::operator delete([[maybe_unused]] void * ptr, void * place) noexcept { ::free(place); }
+
inline size_t MemArena::size() const {
return _active_allocated;
}
diff --git a/code/src/MemArena.cc b/code/src/MemArena.cc
index f5a3e77..fe22823 100644
--- a/code/src/MemArena.cc
+++ b/code/src/MemArena.cc
@@ -10,11 +10,6 @@
namespace swoc { inline namespace SWOC_VERSION_NS {
-void
-MemArena::Block::operator delete(void *ptr) {
- ::free(ptr);
-}
-
// Need to break these out because the default implementation doesn't clear the
// integral values in @a that.