25 #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 36 #include <type_traits> 48 inline T* UncheckedRealloc(T* pointer,
size_t n);
50 inline T* UncheckedMalloc(
size_t n);
52 inline T* UncheckedCalloc(
size_t n);
57 inline T* Realloc(T* pointer,
size_t n);
59 inline T* Malloc(
size_t n);
61 inline T* Calloc(
size_t n);
63 inline char* Malloc(
size_t n);
64 inline char* Calloc(
size_t n);
65 inline char* UncheckedMalloc(
size_t n);
66 inline char* UncheckedCalloc(
size_t n);
74 #define NO_RETURN __attribute__((noreturn)) 81 NO_RETURN
void Abort();
82 NO_RETURN
void Assert(
const char*
const (*args)[4]);
85 template <
typename T>
using remove_reference = std::remove_reference<T>;
87 #define FIXED_ONE_BYTE_STRING(isolate, string) \ 88 (node::OneByteString((isolate), (string), sizeof(string) - 1)) 90 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ 91 void operator=(const TypeName&) = delete; \ 92 void operator=(TypeName&&) = delete; \ 93 TypeName(const TypeName&) = delete; \ 94 TypeName(TypeName&&) = delete 98 #define ABORT_NO_BACKTRACE() raise(SIGABRT) 100 #define ABORT_NO_BACKTRACE() abort() 103 #define ABORT() node::Abort() 106 #define LIKELY(expr) __builtin_expect(!!(expr), 1) 107 #define UNLIKELY(expr) __builtin_expect(!!(expr), 0) 108 #define PRETTY_FUNCTION_NAME __PRETTY_FUNCTION__ 110 #define LIKELY(expr) expr 111 #define UNLIKELY(expr) expr 112 #define PRETTY_FUNCTION_NAME "" 115 #define STRINGIFY_(x) #x 116 #define STRINGIFY(x) STRINGIFY_(x) 118 #define CHECK(expr) \ 120 if (UNLIKELY(!(expr))) { \ 121 static const char* const args[] = { __FILE__, STRINGIFY(__LINE__), \ 122 #expr, PRETTY_FUNCTION_NAME }; \ 123 node::Assert(&args); \ 127 #define CHECK_EQ(a, b) CHECK((a) == (b)) 128 #define CHECK_GE(a, b) CHECK((a) >= (b)) 129 #define CHECK_GT(a, b) CHECK((a) > (b)) 130 #define CHECK_LE(a, b) CHECK((a) <= (b)) 131 #define CHECK_LT(a, b) CHECK((a) < (b)) 132 #define CHECK_NE(a, b) CHECK((a) != (b)) 134 #define UNREACHABLE() ABORT() 136 #define ASSIGN_OR_RETURN_UNWRAP(ptr, obj, ...) \ 139 Unwrap<typename node::remove_reference<decltype(**ptr)>::type>(obj); \ 140 if (*ptr == nullptr) \ 141 return __VA_ARGS__; \ 145 template <
typename T>
149 template <
typename T, ListNode<T> (T::*M)>
152 template <
typename T>
157 inline void Remove();
158 inline bool IsEmpty()
const;
161 template <
typename U, ListNode<U> (U::*M)>
friend class ListHead;
164 DISALLOW_COPY_AND_ASSIGN(ListNode);
167 template <
typename T, ListNode<T> (T::*M)>
172 inline T* operator*()
const;
173 inline const Iterator& operator++();
174 inline bool operator!=(
const Iterator& that)
const;
177 friend class ListHead;
178 inline explicit Iterator(ListNode<T>*
node);
182 inline ListHead() =
default;
184 inline void MoveBack(ListHead* that);
185 inline void PushBack(T* element);
186 inline void PushFront(T* element);
187 inline bool IsEmpty()
const;
188 inline T* PopFront();
189 inline Iterator begin()
const;
190 inline Iterator end()
const;
194 DISALLOW_COPY_AND_ASSIGN(ListHead);
198 template <
typename Inner,
typename Outer>
199 class ContainerOfHelper {
201 inline ContainerOfHelper(Inner Outer::*field, Inner* pointer);
202 template <
typename TypeName>
203 inline operator TypeName*()
const;
205 Outer*
const pointer_;
210 template <
typename Inner,
typename Outer>
211 inline ContainerOfHelper<Inner, Outer> ContainerOf(Inner Outer::*field,
217 template <
class TypeName>
218 inline v8::Local<TypeName> PersistentToLocal(
219 v8::Isolate* isolate,
220 const v8::Persistent<TypeName>& persistent);
227 template <
class TypeName>
228 inline v8::Local<TypeName> StrongPersistentToLocal(
229 const v8::Persistent<TypeName>& persistent);
231 template <
class TypeName>
232 inline v8::Local<TypeName> WeakPersistentToLocal(
233 v8::Isolate* isolate,
234 const v8::Persistent<TypeName>& persistent);
237 inline v8::Local<v8::String> OneByteString(v8::Isolate* isolate,
242 inline v8::Local<v8::String> OneByteString(v8::Isolate* isolate,
243 const signed char*
data,
246 inline v8::Local<v8::String> OneByteString(v8::Isolate* isolate,
247 const unsigned char*
data,
250 inline void Wrap(v8::Local<v8::Object>
object,
void* pointer);
252 inline void ClearWrap(v8::Local<v8::Object>
object);
254 template <
typename TypeName>
255 inline TypeName* Unwrap(v8::Local<v8::Object>
object);
259 inline void SwapBytes16(
char*
data,
size_t nbytes);
260 inline void SwapBytes32(
char*
data,
size_t nbytes);
261 inline void SwapBytes64(
char*
data,
size_t nbytes);
264 inline char ToLower(
char c);
267 inline bool StringEqualNoCase(
const char*
a,
const char* b);
270 inline bool StringEqualNoCaseN(
const char*
a,
const char* b,
size_t length);
274 template <
typename T,
size_t kStackStorageSize = 1024>
275 class MaybeStackBuffer {
277 const T* out()
const {
290 const T* operator*()
const {
294 T& operator[](
size_t index) {
295 CHECK_LT(index, length());
299 const T& operator[](
size_t index)
const {
300 CHECK_LT(index, length());
304 size_t length()
const {
310 size_t capacity()
const {
311 return IsAllocated() ? capacity_ :
312 IsInvalidated() ? 0 : kStackStorageSize;
319 void AllocateSufficientStorage(
size_t storage) {
320 CHECK(!IsInvalidated());
321 if (storage > capacity()) {
322 bool was_allocated = IsAllocated();
323 T* allocated_ptr = was_allocated ? buf_ :
nullptr;
324 buf_ = Realloc(allocated_ptr, storage);
326 if (!was_allocated && length_ > 0)
327 memcpy(buf_, buf_st_, length_ *
sizeof(buf_[0]));
333 void SetLength(
size_t length) {
335 CHECK_LE(length, capacity());
339 void SetLengthAndZeroTerminate(
size_t length) {
341 CHECK_LE(length + 1, capacity());
353 CHECK(!IsAllocated());
359 bool IsAllocated()
const {
360 return !IsInvalidated() && buf_ != buf_st_;
364 bool IsInvalidated()
const {
365 return buf_ ==
nullptr;
371 CHECK(IsAllocated());
377 MaybeStackBuffer() : length_(0), capacity_(0), buf_(buf_st_) {
382 explicit MaybeStackBuffer(
size_t storage) : MaybeStackBuffer() {
383 AllocateSufficientStorage(storage);
386 ~MaybeStackBuffer() {
396 T buf_st_[kStackStorageSize];
399 class Utf8Value :
public MaybeStackBuffer<char> {
401 explicit Utf8Value(v8::Isolate* isolate, v8::Local<v8::Value> value);
404 class TwoByteValue :
public MaybeStackBuffer<uint16_t> {
406 explicit TwoByteValue(v8::Isolate* isolate, v8::Local<v8::Value> value);
409 class BufferValue :
public MaybeStackBuffer<char> {
411 explicit BufferValue(v8::Isolate* isolate, v8::Local<v8::Value> value);
414 #define THROW_AND_RETURN_UNLESS_BUFFER(env, obj) \ 416 if (!Buffer::HasInstance(obj)) \ 417 return env->ThrowTypeError("argument should be a Buffer"); \ 420 #define SPREAD_BUFFER_ARG(val, name) \ 421 CHECK((val)->IsArrayBufferView()); \ 422 v8::Local<v8::ArrayBufferView> name = (val).As<v8::ArrayBufferView>(); \ 423 v8::ArrayBuffer::Contents name##_c = name->Buffer()->GetContents(); \ 424 const size_t name##_offset = name->ByteOffset(); \ 425 const size_t name##_length = name->ByteLength(); \ 426 char* const name##_data = \ 427 static_cast<char*>(name##_c.Data()) + name##_offset; \ 428 if (name##_length > 0) \ 429 CHECK_NE(name##_data, nullptr); 434 #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 436 #endif // SRC_UTIL_H_ union node::cares_wrap::@8::CaresAsyncData::@0 data
NO_RETURN void Assert(const char *const (*args)[4])
void DumpBacktrace(FILE *fp)
void LowMemoryNotification()