diff options
Diffstat (limited to 'src/core/lib/gprpp/memory.h')
-rw-r--r-- | src/core/lib/gprpp/memory.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/core/lib/gprpp/memory.h b/src/core/lib/gprpp/memory.h index ba2f546675..28fcdf1779 100644 --- a/src/core/lib/gprpp/memory.h +++ b/src/core/lib/gprpp/memory.h @@ -27,6 +27,17 @@ #include <memory> #include <utility> +// Add this to a class that want to use Delete(), but has a private or +// protected destructor. +#define GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE \ + template <typename T> \ + friend void Delete(T*); +// Add this to a class that want to use New(), but has a private or +// protected constructor. +#define GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_NEW \ + template <typename T, typename... Args> \ + friend T* New(Args&&...); + namespace grpc_core { // The alignment of memory returned by gpr_malloc(). @@ -44,6 +55,7 @@ inline T* New(Args&&... args) { // Alternative to delete, since we cannot use it (for fear of libstdc++) template <typename T> inline void Delete(T* p) { + if (p == nullptr) return; p->~T(); if (alignof(T) > kAlignmentForDefaultAllocationInBytes) { gpr_free_aligned(p); |