aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMuxi Yan <muxi@users.noreply.github.com>2019-06-14 16:42:55 -0700
committerGitHub <noreply@github.com>2019-06-14 16:42:55 -0700
commitc0441667f41fabe41158179e5f6ecfb75e1b2ed0 (patch)
treee6dd2bc77bd029e0ebececd15945b027fa737962
parent76a381869413834692b8ed305fbe923c0f9c4472 (diff)
parentc0d9289a7e4093f40ffb89a2c162cbfb56dcc5f1 (diff)
downloadgrpc-grpc-c0441667f41fabe41158179e5f6ecfb75e1b2ed0.tar.gz
Merge pull request #19336 from muxi/v1.21.xupstream-v1.21.x
Backport #19309: Fix usage of new and delete
-rw-r--r--src/core/ext/filters/client_channel/resolver.h2
-rw-r--r--src/core/lib/channel/channelz_registry.h4
-rw-r--r--src/core/lib/gprpp/memory.h4
-rw-r--r--src/core/lib/gprpp/orphanable.h2
-rw-r--r--src/core/lib/gprpp/ref_counted.h6
-rw-r--r--src/core/lib/iomgr/buffer_list.h2
-rw-r--r--src/core/lib/iomgr/cfstream_handle.cc5
-rw-r--r--src/core/lib/iomgr/cfstream_handle.h4
-rw-r--r--src/core/lib/slice/slice.cc4
9 files changed, 19 insertions, 14 deletions
diff --git a/src/core/ext/filters/client_channel/resolver.h b/src/core/ext/filters/client_channel/resolver.h
index 9aa504225a..87a4442d75 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<Resolver> {
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 73b330785d..a0c431e091 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 b4b63ae771..70ad430c51 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 <typename T> \
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 <typename T, typename... Args> \
friend T* grpc_core::New(Args&&...);
diff --git a/src/core/lib/gprpp/orphanable.h b/src/core/lib/gprpp/orphanable.h
index 2e467e4906..82350a19a2 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 <typename T>
diff --git a/src/core/lib/gprpp/ref_counted.h b/src/core/lib/gprpp/ref_counted.h
index 83e9429ba3..3ef210e025 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 8bb271867c..755ce02ba9 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/iomgr/cfstream_handle.cc b/src/core/lib/iomgr/cfstream_handle.cc
index 2fda160f68..8d01386a8f 100644
--- a/src/core/lib/iomgr/cfstream_handle.cc
+++ b/src/core/lib/iomgr/cfstream_handle.cc
@@ -18,6 +18,7 @@
#include <grpc/support/port_platform.h>
+#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<CFStreamHandle>(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<CFStreamHandle>(this);
}
}
diff --git a/src/core/lib/iomgr/cfstream_handle.h b/src/core/lib/iomgr/cfstream_handle.h
index 4f4d15966e..05f45ed625 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 <CoreFoundation/CoreFoundation.h>
+#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
diff --git a/src/core/lib/slice/slice.cc b/src/core/lib/slice/slice.cc
index 2bf2b0f499..4a17188fdd 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_; }