Merge pull request #19336 from muxi/v1.21.x

Backport #19309: Fix usage of new and delete
v1.21.x
Muxi Yan 6 years ago committed by GitHub
commit c0441667f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/core/ext/filters/client_channel/resolver.h
  2. 4
      src/core/lib/channel/channelz_registry.h
  3. 4
      src/core/lib/gprpp/memory.h
  4. 2
      src/core/lib/gprpp/orphanable.h
  5. 6
      src/core/lib/gprpp/ref_counted.h
  6. 2
      src/core/lib/iomgr/buffer_list.h
  7. 5
      src/core/lib/iomgr/cfstream_handle.cc
  8. 4
      src/core/lib/iomgr/cfstream_handle.h
  9. 4
      src/core/lib/slice/slice.cc

@ -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

@ -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();

@ -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&&...);

@ -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>

@ -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

@ -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) {}

@ -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);
}
}

@ -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

@ -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_; }

Loading…
Cancel
Save