From 0054afef6e3985a7a6aba61204995b4799c00b20 Mon Sep 17 00:00:00 2001 From: Muxi Yan Date: Mon, 10 Jun 2019 13:32:59 -0700 Subject: [PATCH 1/2] Fix usage of new and delete --- src/core/lib/iomgr/cfstream_handle.cc | 5 +++-- src/core/lib/iomgr/cfstream_handle.h | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/core/lib/iomgr/cfstream_handle.cc b/src/core/lib/iomgr/cfstream_handle.cc index 2fda160f68a..8d01386a8f9 100644 --- a/src/core/lib/iomgr/cfstream_handle.cc +++ b/src/core/lib/iomgr/cfstream_handle.cc @@ -18,6 +18,7 @@ #include +#include "src/core/lib/gprpp/memory.h" #include "src/core/lib/iomgr/port.h" #ifdef GRPC_CFSTREAM @@ -47,7 +48,7 @@ void CFStreamHandle::Release(void* info) { CFStreamHandle* CFStreamHandle::CreateStreamHandle( CFReadStreamRef read_stream, CFWriteStreamRef write_stream) { - return new CFStreamHandle(read_stream, write_stream); + return grpc_core::New(read_stream, write_stream); } void CFStreamHandle::ReadCallback(CFReadStreamRef stream, @@ -188,7 +189,7 @@ void CFStreamHandle::Unref(const char* file, int line, const char* reason) { reason, val, val - 1); } if (gpr_unref(&refcount_)) { - delete this; + grpc_core::Delete(this); } } diff --git a/src/core/lib/iomgr/cfstream_handle.h b/src/core/lib/iomgr/cfstream_handle.h index 4f4d15966e4..05f45ed6251 100644 --- a/src/core/lib/iomgr/cfstream_handle.h +++ b/src/core/lib/iomgr/cfstream_handle.h @@ -29,6 +29,7 @@ #ifdef GRPC_CFSTREAM #import +#include "src/core/lib/gprpp/memory.h" #include "src/core/lib/iomgr/closure.h" #include "src/core/lib/iomgr/lockfree_event.h" @@ -65,6 +66,9 @@ class CFStreamHandle final { dispatch_queue_t dispatch_queue_; gpr_refcount refcount_; + + GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_NEW + GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE }; #ifdef DEBUG From c0d9289a7e4093f40ffb89a2c162cbfb56dcc5f1 Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Thu, 6 Jun 2019 10:25:37 -0700 Subject: [PATCH 2/2] Stop misspelling our own project name --- src/core/ext/filters/client_channel/resolver.h | 2 +- src/core/lib/channel/channelz_registry.h | 4 ++-- src/core/lib/gprpp/memory.h | 4 ++-- src/core/lib/gprpp/orphanable.h | 2 +- src/core/lib/gprpp/ref_counted.h | 6 +++--- src/core/lib/iomgr/buffer_list.h | 2 +- src/core/lib/slice/slice.cc | 4 ++-- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/core/ext/filters/client_channel/resolver.h b/src/core/ext/filters/client_channel/resolver.h index 9aa504225ad..87a4442d75b 100644 --- a/src/core/ext/filters/client_channel/resolver.h +++ b/src/core/ext/filters/client_channel/resolver.h @@ -128,7 +128,7 @@ class Resolver : public InternallyRefCounted { GRPC_ABSTRACT_BASE_CLASS protected: - GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE + GRPC_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/channel/channelz_registry.h b/src/core/lib/channel/channelz_registry.h index 73b330785d2..a0c431e091d 100644 --- a/src/core/lib/channel/channelz_registry.h +++ b/src/core/lib/channel/channelz_registry.h @@ -67,8 +67,8 @@ class ChannelzRegistry { static void LogAllEntities() { Default()->InternalLogAllEntities(); } private: - GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_NEW - GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE + GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_NEW + GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE friend class testing::ChannelzRegistryPeer; ChannelzRegistry(); diff --git a/src/core/lib/gprpp/memory.h b/src/core/lib/gprpp/memory.h index b4b63ae771a..70ad430c51d 100644 --- a/src/core/lib/gprpp/memory.h +++ b/src/core/lib/gprpp/memory.h @@ -29,12 +29,12 @@ // 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 \ +#define GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE \ template \ friend void grpc_core::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 \ +#define GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_NEW \ template \ friend T* grpc_core::New(Args&&...); diff --git a/src/core/lib/gprpp/orphanable.h b/src/core/lib/gprpp/orphanable.h index 2e467e49060..82350a19a2c 100644 --- a/src/core/lib/gprpp/orphanable.h +++ b/src/core/lib/gprpp/orphanable.h @@ -84,7 +84,7 @@ class InternallyRefCounted : public Orphanable { GRPC_ABSTRACT_BASE_CLASS protected: - GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE + GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE // Allow RefCountedPtr<> to access Unref() and IncrementRefCount(). template diff --git a/src/core/lib/gprpp/ref_counted.h b/src/core/lib/gprpp/ref_counted.h index 83e9429ba37..3ef210e025f 100644 --- a/src/core/lib/gprpp/ref_counted.h +++ b/src/core/lib/gprpp/ref_counted.h @@ -44,7 +44,7 @@ class PolymorphicRefCount { GRPC_ABSTRACT_BASE_CLASS protected: - GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE + GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE virtual ~PolymorphicRefCount() = default; }; @@ -57,7 +57,7 @@ class NonPolymorphicRefCount { GRPC_ABSTRACT_BASE_CLASS protected: - GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE + GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE ~NonPolymorphicRefCount() = default; }; @@ -228,7 +228,7 @@ class RefCounted : public Impl { GRPC_ABSTRACT_BASE_CLASS protected: - GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE + GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE // TraceFlagT is defined to accept both DebugOnlyTraceFlag and TraceFlag. // Note: RefCount tracing is only enabled on debug builds, even when a diff --git a/src/core/lib/iomgr/buffer_list.h b/src/core/lib/iomgr/buffer_list.h index 8bb271867c2..755ce02ba95 100644 --- a/src/core/lib/iomgr/buffer_list.h +++ b/src/core/lib/iomgr/buffer_list.h @@ -133,7 +133,7 @@ class TracedBuffer { grpc_error* shutdown_err); private: - GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_NEW + GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_NEW TracedBuffer(uint32_t seq_no, void* arg) : seq_no_(seq_no), arg_(arg), next_(nullptr) {} diff --git a/src/core/lib/slice/slice.cc b/src/core/lib/slice/slice.cc index 2bf2b0f499f..4a17188fdda 100644 --- a/src/core/lib/slice/slice.cc +++ b/src/core/lib/slice/slice.cc @@ -105,7 +105,7 @@ class NewSliceRefcount { user_destroy_(destroy), user_data_(user_data) {} - GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE + GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE grpc_slice_refcount* base_refcount() { return &rc_; } @@ -154,7 +154,7 @@ class NewWithLenSliceRefcount { user_length_(user_length), user_destroy_(destroy) {} - GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE + GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE grpc_slice_refcount* base_refcount() { return &rc_; }