diff options
author | Noah Eisen <ncteisen@gmail.com> | 2018-05-16 15:47:10 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-16 15:47:10 -0700 |
commit | bc946acd7e089f85228de977849e1d9d5eb5a718 (patch) | |
tree | b3f585cc5e624a40f287331c090d5a2c86f1d7df /src | |
parent | 0721c94e9ef983b5663eaba5e86a288ef5a99b82 (diff) | |
parent | 15a521e8143e8e6adcdf558fb1ea31668964ac3c (diff) |
Merge pull request #15339 from ncteisen/new-delete-hack
Add Single Point of Maintenance for New/Delete friend Declarations
Diffstat (limited to 'src')
-rw-r--r-- | src/core/ext/filters/client_channel/lb_policy.h | 4 | ||||
-rw-r--r-- | src/core/ext/filters/client_channel/resolver.h | 4 | ||||
-rw-r--r-- | src/core/lib/gprpp/memory.h | 11 | ||||
-rw-r--r-- | src/core/lib/gprpp/orphanable.h | 8 | ||||
-rw-r--r-- | src/core/lib/gprpp/ref_counted.h | 8 |
5 files changed, 17 insertions, 18 deletions
diff --git a/src/core/ext/filters/client_channel/lb_policy.h b/src/core/ext/filters/client_channel/lb_policy.h index 454e00a690..dab4466b21 100644 --- a/src/core/ext/filters/client_channel/lb_policy.h +++ b/src/core/ext/filters/client_channel/lb_policy.h @@ -162,9 +162,7 @@ class LoadBalancingPolicy GRPC_ABSTRACT_BASE_CLASS protected: - // So Delete() can access our protected dtor. - template <typename T> - friend void Delete(T*); + GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE explicit LoadBalancingPolicy(const Args& args); virtual ~LoadBalancingPolicy(); diff --git a/src/core/ext/filters/client_channel/resolver.h b/src/core/ext/filters/client_channel/resolver.h index 02380314dd..c7e37e4468 100644 --- a/src/core/ext/filters/client_channel/resolver.h +++ b/src/core/ext/filters/client_channel/resolver.h @@ -105,9 +105,7 @@ class Resolver : public InternallyRefCountedWithTracing<Resolver> { GRPC_ABSTRACT_BASE_CLASS protected: - // So Delete() can access our protected dtor. - template <typename T> - friend void Delete(T*); + GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE /// Does NOT take ownership of the reference to \a combiner. // TODO(roth): Once we have a C++-like interface for combiners, this diff --git a/src/core/lib/gprpp/memory.h b/src/core/lib/gprpp/memory.h index ba2f546675..1354109bf3 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(). diff --git a/src/core/lib/gprpp/orphanable.h b/src/core/lib/gprpp/orphanable.h index 73a73995c7..d0ec9b6461 100644 --- a/src/core/lib/gprpp/orphanable.h +++ b/src/core/lib/gprpp/orphanable.h @@ -83,9 +83,7 @@ class InternallyRefCounted : public Orphanable { GRPC_ABSTRACT_BASE_CLASS protected: - // Allow Delete() to access destructor. - template <typename T> - friend void Delete(T*); + GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE // Allow RefCountedPtr<> to access Unref() and IncrementRefCount(). friend class RefCountedPtr<Child>; @@ -128,9 +126,7 @@ class InternallyRefCountedWithTracing : public Orphanable { GRPC_ABSTRACT_BASE_CLASS protected: - // Allow Delete() to access destructor. - template <typename T> - friend void Delete(T*); + GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE // Allow RefCountedPtr<> to access Unref() and IncrementRefCount(). friend class RefCountedPtr<Child>; diff --git a/src/core/lib/gprpp/ref_counted.h b/src/core/lib/gprpp/ref_counted.h index c67e3f315c..ddac5bd475 100644 --- a/src/core/lib/gprpp/ref_counted.h +++ b/src/core/lib/gprpp/ref_counted.h @@ -65,9 +65,7 @@ class RefCounted { GRPC_ABSTRACT_BASE_CLASS protected: - // Allow Delete() to access destructor. - template <typename T> - friend void Delete(T*); + GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE RefCounted() { gpr_ref_init(&refs_, 1); } @@ -135,9 +133,7 @@ class RefCountedWithTracing { GRPC_ABSTRACT_BASE_CLASS protected: - // Allow Delete() to access destructor. - template <typename T> - friend void Delete(T*); + GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE RefCountedWithTracing() : RefCountedWithTracing(static_cast<TraceFlag*>(nullptr)) {} |