Browse Source

src: fix whitespace/indent cpplint warnings

PR-URL: https://github.com/nodejs/node/pull/7462
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
v4.x
Ben Noordhuis 8 years ago
committed by Myles Borins
parent
commit
4f4d3e77ef
  1. 144
      src/node_internals.h
  2. 108
      src/string_bytes.cc
  3. 162
      src/util.h

144
src/node_internals.h

@ -247,78 +247,78 @@ void ClearFatalExceptionHandlers(Environment* env);
enum NodeInstanceType { MAIN, WORKER }; enum NodeInstanceType { MAIN, WORKER };
class NodeInstanceData { class NodeInstanceData {
public: public:
NodeInstanceData(NodeInstanceType node_instance_type, NodeInstanceData(NodeInstanceType node_instance_type,
uv_loop_t* event_loop, uv_loop_t* event_loop,
int argc, int argc,
const char** argv, const char** argv,
int exec_argc, int exec_argc,
const char** exec_argv, const char** exec_argv,
bool use_debug_agent_flag) bool use_debug_agent_flag)
: node_instance_type_(node_instance_type), : node_instance_type_(node_instance_type),
exit_code_(1), exit_code_(1),
event_loop_(event_loop), event_loop_(event_loop),
argc_(argc), argc_(argc),
argv_(argv), argv_(argv),
exec_argc_(exec_argc), exec_argc_(exec_argc),
exec_argv_(exec_argv), exec_argv_(exec_argv),
use_debug_agent_flag_(use_debug_agent_flag) { use_debug_agent_flag_(use_debug_agent_flag) {
CHECK_NE(event_loop_, nullptr); CHECK_NE(event_loop_, nullptr);
} }
uv_loop_t* event_loop() const { uv_loop_t* event_loop() const {
return event_loop_; return event_loop_;
} }
int exit_code() { int exit_code() {
CHECK(is_main()); CHECK(is_main());
return exit_code_; return exit_code_;
} }
void set_exit_code(int exit_code) { void set_exit_code(int exit_code) {
CHECK(is_main()); CHECK(is_main());
exit_code_ = exit_code; exit_code_ = exit_code;
} }
bool is_main() { bool is_main() {
return node_instance_type_ == MAIN; return node_instance_type_ == MAIN;
} }
bool is_worker() { bool is_worker() {
return node_instance_type_ == WORKER; return node_instance_type_ == WORKER;
} }
int argc() { int argc() {
return argc_; return argc_;
} }
const char** argv() { const char** argv() {
return argv_; return argv_;
} }
int exec_argc() { int exec_argc() {
return exec_argc_; return exec_argc_;
} }
const char** exec_argv() { const char** exec_argv() {
return exec_argv_; return exec_argv_;
} }
bool use_debug_agent() { bool use_debug_agent() {
return is_main() && use_debug_agent_flag_; return is_main() && use_debug_agent_flag_;
} }
private: private:
const NodeInstanceType node_instance_type_; const NodeInstanceType node_instance_type_;
int exit_code_; int exit_code_;
uv_loop_t* const event_loop_; uv_loop_t* const event_loop_;
const int argc_; const int argc_;
const char** argv_; const char** argv_;
const int exec_argc_; const int exec_argc_;
const char** exec_argv_; const char** exec_argv_;
const bool use_debug_agent_flag_; const bool use_debug_agent_flag_;
DISALLOW_COPY_AND_ASSIGN(NodeInstanceData); DISALLOW_COPY_AND_ASSIGN(NodeInstanceData);
}; };
namespace Buffer { namespace Buffer {

108
src/string_bytes.cc

@ -27,75 +27,75 @@ using v8::MaybeLocal;
template <typename ResourceType, typename TypeName> template <typename ResourceType, typename TypeName>
class ExternString: public ResourceType { class ExternString: public ResourceType {
public: public:
~ExternString() override { ~ExternString() override {
free(const_cast<TypeName*>(data_)); free(const_cast<TypeName*>(data_));
isolate()->AdjustAmountOfExternalAllocatedMemory(-byte_length()); isolate()->AdjustAmountOfExternalAllocatedMemory(-byte_length());
} }
const TypeName* data() const override {
return data_;
}
size_t length() const override { const TypeName* data() const override {
return length_; return data_;
} }
int64_t byte_length() const { size_t length() const override {
return length() * sizeof(*data()); return length_;
} }
static Local<String> NewFromCopy(Isolate* isolate, int64_t byte_length() const {
const TypeName* data, return length() * sizeof(*data());
size_t length) { }
EscapableHandleScope scope(isolate);
if (length == 0) static Local<String> NewFromCopy(Isolate* isolate,
return scope.Escape(String::Empty(isolate)); const TypeName* data,
size_t length) {
EscapableHandleScope scope(isolate);
TypeName* new_data = if (length == 0)
static_cast<TypeName*>(malloc(length * sizeof(*new_data))); return scope.Escape(String::Empty(isolate));
if (new_data == nullptr) {
return Local<String>();
}
memcpy(new_data, data, length * sizeof(*new_data));
return scope.Escape(ExternString<ResourceType, TypeName>::New(isolate, TypeName* new_data =
new_data, static_cast<TypeName*>(malloc(length * sizeof(*new_data)));
length)); if (new_data == nullptr) {
return Local<String>();
} }
memcpy(new_data, data, length * sizeof(*new_data));
// uses "data" for external resource, and will be free'd on gc return scope.Escape(ExternString<ResourceType, TypeName>::New(isolate,
static Local<String> New(Isolate* isolate, new_data,
const TypeName* data, length));
size_t length) { }
EscapableHandleScope scope(isolate);
if (length == 0) // uses "data" for external resource, and will be free'd on gc
return scope.Escape(String::Empty(isolate)); static Local<String> New(Isolate* isolate,
const TypeName* data,
size_t length) {
EscapableHandleScope scope(isolate);
if (length == 0)
return scope.Escape(String::Empty(isolate));
ExternString* h_str = new ExternString<ResourceType, TypeName>(isolate, ExternString* h_str = new ExternString<ResourceType, TypeName>(isolate,
data, data,
length); length);
MaybeLocal<String> str = String::NewExternal(isolate, h_str); MaybeLocal<String> str = String::NewExternal(isolate, h_str);
isolate->AdjustAmountOfExternalAllocatedMemory(h_str->byte_length()); isolate->AdjustAmountOfExternalAllocatedMemory(h_str->byte_length());
if (str.IsEmpty()) {
delete h_str;
return Local<String>();
}
return scope.Escape(str.ToLocalChecked()); if (str.IsEmpty()) {
delete h_str;
return Local<String>();
} }
inline Isolate* isolate() const { return isolate_; } return scope.Escape(str.ToLocalChecked());
}
inline Isolate* isolate() const { return isolate_; }
private: private:
ExternString(Isolate* isolate, const TypeName* data, size_t length) ExternString(Isolate* isolate, const TypeName* data, size_t length)
: isolate_(isolate), data_(data), length_(length) { } : isolate_(isolate), data_(data), length_(length) { }
Isolate* isolate_; Isolate* isolate_;
const TypeName* data_; const TypeName* data_;
size_t length_; size_t length_;
}; };

162
src/util.h

@ -194,99 +194,99 @@ inline bool StringEqualNoCase(const char* a, const char* b);
// the stack is used, otherwise malloc(). // the stack is used, otherwise malloc().
template <typename T, size_t kStackStorageSize = 1024> template <typename T, size_t kStackStorageSize = 1024>
class MaybeStackBuffer { class MaybeStackBuffer {
public: public:
const T* out() const { const T* out() const {
return buf_; return buf_;
} }
T* out() { T* out() {
return buf_; return buf_;
} }
// operator* for compatibility with `v8::String::(Utf8)Value` // operator* for compatibility with `v8::String::(Utf8)Value`
T* operator*() { T* operator*() {
return buf_; return buf_;
} }
const T* operator*() const { const T* operator*() const {
return buf_; return buf_;
} }
size_t length() const { size_t length() const {
return length_; return length_;
} }
// Call to make sure enough space for `storage` entries is available. // Call to make sure enough space for `storage` entries is available.
// There can only be 1 call to AllocateSufficientStorage or Invalidate // There can only be 1 call to AllocateSufficientStorage or Invalidate
// per instance. // per instance.
void AllocateSufficientStorage(size_t storage) { void AllocateSufficientStorage(size_t storage) {
if (storage <= kStackStorageSize) { if (storage <= kStackStorageSize) {
buf_ = buf_st_; buf_ = buf_st_;
} else { } else {
// Guard against overflow. // Guard against overflow.
CHECK_LE(storage, sizeof(T) * storage); CHECK_LE(storage, sizeof(T) * storage);
buf_ = static_cast<T*>(malloc(sizeof(T) * storage)); buf_ = static_cast<T*>(malloc(sizeof(T) * storage));
CHECK_NE(buf_, nullptr); CHECK_NE(buf_, nullptr);
}
// Remember how much was allocated to check against that in SetLength().
length_ = storage;
}
void SetLength(size_t length) {
// length_ stores how much memory was allocated.
CHECK_LE(length, length_);
length_ = length;
}
void SetLengthAndZeroTerminate(size_t length) {
// length_ stores how much memory was allocated.
CHECK_LE(length + 1, length_);
SetLength(length);
// T() is 0 for integer types, nullptr for pointers, etc.
buf_[length] = T();
}
// Make derefencing this object return nullptr.
// Calling this is mutually exclusive with calling
// AllocateSufficientStorage.
void Invalidate() {
CHECK_EQ(buf_, buf_st_);
length_ = 0;
buf_ = nullptr;
}
MaybeStackBuffer() : length_(0), buf_(buf_st_) {
// Default to a zero-length, null-terminated buffer.
buf_[0] = T();
} }
~MaybeStackBuffer() { // Remember how much was allocated to check against that in SetLength().
if (buf_ != buf_st_) length_ = storage;
free(buf_); }
}
void SetLength(size_t length) {
// length_ stores how much memory was allocated.
CHECK_LE(length, length_);
length_ = length;
}
void SetLengthAndZeroTerminate(size_t length) {
// length_ stores how much memory was allocated.
CHECK_LE(length + 1, length_);
SetLength(length);
// T() is 0 for integer types, nullptr for pointers, etc.
buf_[length] = T();
}
// Make derefencing this object return nullptr.
// Calling this is mutually exclusive with calling
// AllocateSufficientStorage.
void Invalidate() {
CHECK_EQ(buf_, buf_st_);
length_ = 0;
buf_ = nullptr;
}
MaybeStackBuffer() : length_(0), buf_(buf_st_) {
// Default to a zero-length, null-terminated buffer.
buf_[0] = T();
}
~MaybeStackBuffer() {
if (buf_ != buf_st_)
free(buf_);
}
private: private:
size_t length_; size_t length_;
T* buf_; T* buf_;
T buf_st_[kStackStorageSize]; T buf_st_[kStackStorageSize];
}; };
class Utf8Value : public MaybeStackBuffer<char> { class Utf8Value : public MaybeStackBuffer<char> {
public: public:
explicit Utf8Value(v8::Isolate* isolate, v8::Local<v8::Value> value); explicit Utf8Value(v8::Isolate* isolate, v8::Local<v8::Value> value);
}; };
class TwoByteValue : public MaybeStackBuffer<uint16_t> { class TwoByteValue : public MaybeStackBuffer<uint16_t> {
public: public:
explicit TwoByteValue(v8::Isolate* isolate, v8::Local<v8::Value> value); explicit TwoByteValue(v8::Isolate* isolate, v8::Local<v8::Value> value);
}; };
class BufferValue : public MaybeStackBuffer<char> { class BufferValue : public MaybeStackBuffer<char> {
public: public:
explicit BufferValue(v8::Isolate* isolate, v8::Local<v8::Value> value); explicit BufferValue(v8::Isolate* isolate, v8::Local<v8::Value> value);
}; };
} // namespace node } // namespace node

Loading…
Cancel
Save