Skip to content

Commit

Permalink
src: inline macro DISALLOW_COPY_AND_ASSIGN
Browse files Browse the repository at this point in the history
PR-URL: nodejs#26634
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>
  • Loading branch information
gengjiawen authored and targos committed Mar 27, 2019
1 parent 6239913 commit 5b7c4d6
Show file tree
Hide file tree
Showing 14 changed files with 82 additions and 48 deletions.
34 changes: 20 additions & 14 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,8 @@ class IsolateData {

std::unordered_map<nghttp2_rcbuf*, v8::Eternal<v8::String>> http2_static_strs;
inline v8::Isolate* isolate() const;
IsolateData(const IsolateData&) = delete;
IsolateData& operator=(const IsolateData&) = delete;

private:
#define VP(PropertyName, StringValue) V(v8::Private, PropertyName)
Expand All @@ -445,8 +447,6 @@ class IsolateData {
const bool uses_node_allocator_;
MultiIsolatePlatform* platform_;
std::shared_ptr<PerIsolateOptions> options_;

DISALLOW_COPY_AND_ASSIGN(IsolateData);
};

struct ContextInfo {
Expand Down Expand Up @@ -531,6 +531,9 @@ class AsyncRequest : public MemoryRetainer {

class Environment {
public:
Environment(const Environment&) = delete;
Environment& operator=(const Environment&) = delete;

class AsyncHooks {
public:
// Reason for both UidFields and Fields are that one is stored as a double*
Expand Down Expand Up @@ -568,6 +571,9 @@ class Environment {
inline bool pop_async_id(double async_id);
inline void clear_async_id_stack(); // Used in fatal exceptions.

AsyncHooks(const AsyncHooks&) = delete;
AsyncHooks& operator=(const AsyncHooks&) = delete;

// Used to set the kDefaultTriggerAsyncId in a scope. This is instead of
// passing the trigger_async_id along with other constructor arguments.
class DefaultTriggerAsyncIdScope {
Expand All @@ -578,11 +584,13 @@ class Environment {
explicit DefaultTriggerAsyncIdScope(AsyncWrap* async_wrap);
~DefaultTriggerAsyncIdScope();

DefaultTriggerAsyncIdScope(const DefaultTriggerAsyncIdScope&) = delete;
DefaultTriggerAsyncIdScope& operator=(const DefaultTriggerAsyncIdScope&) =
delete;

private:
AsyncHooks* async_hooks_;
double old_default_trigger_async_id_;

DISALLOW_COPY_AND_ASSIGN(DefaultTriggerAsyncIdScope);
};


Expand All @@ -600,20 +608,18 @@ class Environment {
AliasedBuffer<double, v8::Float64Array> async_id_fields_;

void grow_async_ids_stack();

DISALLOW_COPY_AND_ASSIGN(AsyncHooks);
};

class AsyncCallbackScope {
public:
AsyncCallbackScope() = delete;
explicit AsyncCallbackScope(Environment* env);
~AsyncCallbackScope();
AsyncCallbackScope(const AsyncCallbackScope&) = delete;
AsyncCallbackScope& operator=(const AsyncCallbackScope&) = delete;

private:
Environment* env_;

DISALLOW_COPY_AND_ASSIGN(AsyncCallbackScope);
};

inline size_t makecallback_depth() const;
Expand All @@ -631,6 +637,9 @@ class Environment {
inline void ref_count_inc(uint32_t increment);
inline void ref_count_dec(uint32_t decrement);

ImmediateInfo(const ImmediateInfo&) = delete;
ImmediateInfo& operator=(const ImmediateInfo&) = delete;

private:
friend class Environment; // So we can call the constructor.
inline explicit ImmediateInfo(v8::Isolate* isolate);
Expand All @@ -643,8 +652,6 @@ class Environment {
};

AliasedBuffer<uint32_t, v8::Uint32Array> fields_;

DISALLOW_COPY_AND_ASSIGN(ImmediateInfo);
};

class TickInfo {
Expand All @@ -653,6 +660,9 @@ class Environment {
inline bool has_tick_scheduled() const;
inline bool has_rejection_to_warn() const;

TickInfo(const TickInfo&) = delete;
TickInfo& operator=(const TickInfo&) = delete;

private:
friend class Environment; // So we can call the constructor.
inline explicit TickInfo(v8::Isolate* isolate);
Expand All @@ -664,8 +674,6 @@ class Environment {
};

AliasedBuffer<uint8_t, v8::Uint8Array> fields_;

DISALLOW_COPY_AND_ASSIGN(TickInfo);
};

enum Flags {
Expand Down Expand Up @@ -1214,8 +1222,6 @@ class Environment {
#define V(PropertyName, TypeName) Persistent<TypeName> PropertyName ## _;
ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES(V)
#undef V

DISALLOW_COPY_AND_ASSIGN(Environment);
};

} // namespace node
Expand Down
5 changes: 3 additions & 2 deletions src/inspector_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ class InspectorSocket {
void SwitchProtocol(ProtocolHandler* handler);
std::string GetHost();

InspectorSocket(const InspectorSocket&) = delete;
InspectorSocket& operator=(const InspectorSocket&) = delete;

private:
static void Shutdown(ProtocolHandler*);
InspectorSocket() = default;

DeleteFnPtr<ProtocolHandler, Shutdown> protocol_handler_;

DISALLOW_COPY_AND_ASSIGN(InspectorSocket);
};


Expand Down
4 changes: 2 additions & 2 deletions src/node_binding.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ class DLib {
#endif
bool has_entry_in_global_handle_map_ = false;

private:
DISALLOW_COPY_AND_ASSIGN(DLib);
DLib(const DLib&) = delete;
DLib& operator=(const DLib&) = delete;
};

// Call _register<module_name> functions for all of
Expand Down
5 changes: 4 additions & 1 deletion src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ class CallbackInfo {
FreeCallback callback,
char* data,
void* hint = nullptr);

CallbackInfo(const CallbackInfo&) = delete;
CallbackInfo& operator=(const CallbackInfo&) = delete;

private:
static void WeakCallback(const WeakCallbackInfo<CallbackInfo>&);
inline void WeakCallback(Isolate* isolate);
Expand All @@ -99,7 +103,6 @@ class CallbackInfo {
FreeCallback const callback_;
char* const data_;
void* const hint_;
DISALLOW_COPY_AND_ASSIGN(CallbackInfo);
};


Expand Down
5 changes: 3 additions & 2 deletions src/node_crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,9 @@ class ByteSource {

static ByteSource FromSymmetricKeyObject(v8::Local<v8::Value> handle);

ByteSource(const ByteSource&) = delete;
ByteSource& operator=(const ByteSource&) = delete;

private:
const char* data_ = nullptr;
char* allocated_data_ = nullptr;
Expand All @@ -376,8 +379,6 @@ class ByteSource {

static ByteSource Allocated(char* data, size_t size);
static ByteSource Foreign(const char* data, size_t size);

DISALLOW_COPY_AND_ASSIGN(ByteSource);
};

enum PKEncodingType {
Expand Down
4 changes: 2 additions & 2 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -682,8 +682,8 @@ class FSReqWrapSync {
~FSReqWrapSync() { uv_fs_req_cleanup(&req); }
uv_fs_t req;

private:
DISALLOW_COPY_AND_ASSIGN(FSReqWrapSync);
FSReqWrapSync(const FSReqWrapSync&) = delete;
FSReqWrapSync& operator=(const FSReqWrapSync&) = delete;
};

// Returns nullptr if the operation fails from the start.
Expand Down
9 changes: 5 additions & 4 deletions src/node_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ class FSReqBase : public ReqWrap<uv_fs_t> {
return static_cast<FSReqBase*>(ReqWrap::from_req(req));
}

FSReqBase(const FSReqBase&) = delete;
FSReqBase& operator=(const FSReqBase&) = delete;

private:
enum encoding encoding_ = UTF8;
bool has_data_ = false;
Expand All @@ -123,8 +126,6 @@ class FSReqBase : public ReqWrap<uv_fs_t> {
// Typically, the content of buffer_ is something like a file name, so
// something around 64 bytes should be enough.
FSReqBuffer buffer_;

DISALLOW_COPY_AND_ASSIGN(FSReqBase);
};

class FSReqCallback : public FSReqBase {
Expand All @@ -144,8 +145,8 @@ class FSReqCallback : public FSReqBase {
SET_MEMORY_INFO_NAME(FSReqCallback)
SET_SELF_SIZE(FSReqCallback)

private:
DISALLOW_COPY_AND_ASSIGN(FSReqCallback);
FSReqCallback(const FSReqCallback&) = delete;
FSReqCallback& operator=(const FSReqCallback&) = delete;
};

// Wordaround a GCC4.9 bug that C++14 N3652 was not implemented
Expand Down
16 changes: 12 additions & 4 deletions src/node_mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class MutexBase {
inline void Lock();
inline void Unlock();

MutexBase(const MutexBase&) = delete;
MutexBase& operator=(const MutexBase&) = delete;

class ScopedLock;
class ScopedUnlock;

Expand All @@ -32,28 +35,31 @@ class MutexBase {
inline explicit ScopedLock(const ScopedUnlock& scoped_unlock);
inline ~ScopedLock();

ScopedLock(const ScopedLock&) = delete;
ScopedLock& operator=(const ScopedLock&) = delete;

private:
template <typename> friend class ConditionVariableBase;
friend class ScopedUnlock;
const MutexBase& mutex_;
DISALLOW_COPY_AND_ASSIGN(ScopedLock);
};

class ScopedUnlock {
public:
inline explicit ScopedUnlock(const ScopedLock& scoped_lock);
inline ~ScopedUnlock();

ScopedUnlock(const ScopedUnlock&) = delete;
ScopedUnlock& operator=(const ScopedUnlock&) = delete;

private:
friend class ScopedLock;
const MutexBase& mutex_;
DISALLOW_COPY_AND_ASSIGN(ScopedUnlock);
};

private:
template <typename> friend class ConditionVariableBase;
mutable typename Traits::MutexT mutex_;
DISALLOW_COPY_AND_ASSIGN(MutexBase);
};

template <typename Traits>
Expand All @@ -67,9 +73,11 @@ class ConditionVariableBase {
inline void Signal(const ScopedLock&);
inline void Wait(const ScopedLock& scoped_lock);

ConditionVariableBase(const ConditionVariableBase&) = delete;
ConditionVariableBase& operator=(const ConditionVariableBase&) = delete;

private:
typename Traits::CondT cond_;
DISALLOW_COPY_AND_ASSIGN(ConditionVariableBase);
};

struct LibuvMutexTraits {
Expand Down
12 changes: 10 additions & 2 deletions src/node_union_bytes.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@ class NonOwningExternalOneByteResource
}
size_t length() const override { return length_; }

NonOwningExternalOneByteResource(const NonOwningExternalOneByteResource&) =
delete;
NonOwningExternalOneByteResource& operator=(
const NonOwningExternalOneByteResource&) = delete;

private:
const uint8_t* data_;
size_t length_;
DISALLOW_COPY_AND_ASSIGN(NonOwningExternalOneByteResource);
};

class NonOwningExternalTwoByteResource
Expand All @@ -40,10 +44,14 @@ class NonOwningExternalTwoByteResource
const uint16_t* data() const override { return data_; }
size_t length() const override { return length_; }

NonOwningExternalTwoByteResource(const NonOwningExternalTwoByteResource&) =
delete;
NonOwningExternalTwoByteResource& operator=(
const NonOwningExternalTwoByteResource&) = delete;

private:
const uint16_t* data_;
size_t length_;
DISALLOW_COPY_AND_ASSIGN(NonOwningExternalTwoByteResource);
};

// Similar to a v8::String, but it's independent from Isolates
Expand Down
11 changes: 6 additions & 5 deletions src/node_zlib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ class ZlibContext : public MemoryRetainer {
tracker->TrackField("dictionary", dictionary_);
}

ZlibContext(const ZlibContext&) = delete;
ZlibContext& operator=(const ZlibContext&) = delete;

private:
CompressionError ErrorForMessage(const char* message) const;
CompressionError SetDictionary();
Expand All @@ -160,8 +163,6 @@ class ZlibContext : public MemoryRetainer {
std::vector<unsigned char> dictionary_;

z_stream strm_;

DISALLOW_COPY_AND_ASSIGN(ZlibContext);
};

// Brotli has different data types for compression and decompression streams,
Expand All @@ -175,6 +176,9 @@ class BrotliContext : public MemoryRetainer {
void GetAfterWriteOffsets(uint32_t* avail_in, uint32_t* avail_out) const;
inline void SetMode(node_zlib_mode mode) { mode_ = mode; }

BrotliContext(const BrotliContext&) = delete;
BrotliContext& operator=(const BrotliContext&) = delete;

protected:
node_zlib_mode mode_ = NONE;
uint8_t* next_in_ = nullptr;
Expand All @@ -188,9 +192,6 @@ class BrotliContext : public MemoryRetainer {
brotli_alloc_func alloc_ = nullptr;
brotli_free_func free_ = nullptr;
void* alloc_opaque_ = nullptr;

private:
DISALLOW_COPY_AND_ASSIGN(BrotliContext);
};

class BrotliEncoderContext final : public BrotliContext {
Expand Down
4 changes: 3 additions & 1 deletion src/tracing/trace_event_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,11 @@
// void AppendAsTraceFormat(std::string* out) const override {
// out->append("{\"foo\":1}");
// }
// MyData(const MyData&) = delete;
// MyData& operator=(const MyData&) = delete;
//
// private:
// ~MyData() override {}
// DISALLOW_COPY_AND_ASSIGN(MyData);
// };
//
// TRACE_EVENT1("foo", "bar", "data",
Expand Down
5 changes: 3 additions & 2 deletions src/tracing/traced_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class TracedValue : public v8::ConvertableToTraceFormat {
// ConvertableToTraceFormat implementation.
void AppendAsTraceFormat(std::string* out) const override;

TracedValue(const TracedValue&) = delete;
TracedValue& operator=(const TracedValue&) = delete;

private:
explicit TracedValue(bool root_is_array = false);

Expand All @@ -59,8 +62,6 @@ class TracedValue : public v8::ConvertableToTraceFormat {
std::string data_;
bool first_item_;
bool root_is_array_;

DISALLOW_COPY_AND_ASSIGN(TracedValue);
};

} // namespace tracing
Expand Down
Loading

0 comments on commit 5b7c4d6

Please sign in to comment.