Skip to content

Commit

Permalink
src: squelch unused function warnings in util.h
Browse files Browse the repository at this point in the history
Fixes: #9083

PR-URL: #9115
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
  • Loading branch information
solebox authored and jasnell committed Nov 18, 2016
1 parent 976fe25 commit 35d48d3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
16 changes: 11 additions & 5 deletions src/util-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,39 +357,45 @@ T* UncheckedRealloc(T* pointer, size_t n) {

// As per spec realloc behaves like malloc if passed nullptr.
template <typename T>
T* UncheckedMalloc(size_t n) {
inline T* UncheckedMalloc(size_t n) {
if (n == 0) n = 1;
return UncheckedRealloc<T>(nullptr, n);
}

template <typename T>
T* UncheckedCalloc(size_t n) {
inline T* UncheckedCalloc(size_t n) {
if (n == 0) n = 1;
MultiplyWithOverflowCheck(sizeof(T), n);
return static_cast<T*>(calloc(n, sizeof(T)));
}

template <typename T>
T* Realloc(T* pointer, size_t n) {
inline T* Realloc(T* pointer, size_t n) {
T* ret = UncheckedRealloc(pointer, n);
if (n > 0) CHECK_NE(ret, nullptr);
return ret;
}

template <typename T>
T* Malloc(size_t n) {
inline T* Malloc(size_t n) {
T* ret = UncheckedMalloc<T>(n);
if (n > 0) CHECK_NE(ret, nullptr);
return ret;
}

template <typename T>
T* Calloc(size_t n) {
inline T* Calloc(size_t n) {
T* ret = UncheckedCalloc<T>(n);
if (n > 0) CHECK_NE(ret, nullptr);
return ret;
}

// Shortcuts for char*.
inline char* Malloc(size_t n) { return Malloc<char>(n); }
inline char* Calloc(size_t n) { return Calloc<char>(n); }
inline char* UncheckedMalloc(size_t n) { return UncheckedMalloc<char>(n); }
inline char* UncheckedCalloc(size_t n) { return UncheckedCalloc<char>(n); }

} // namespace node

#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
Expand Down
9 changes: 4 additions & 5 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@ inline T* Malloc(size_t n);
template <typename T>
inline T* Calloc(size_t n);

// Shortcuts for char*.
inline char* Malloc(size_t n) { return Malloc<char>(n); }
inline char* Calloc(size_t n) { return Calloc<char>(n); }
inline char* UncheckedMalloc(size_t n) { return UncheckedMalloc<char>(n); }
inline char* UncheckedCalloc(size_t n) { return UncheckedCalloc<char>(n); }
inline char* Malloc(size_t n);
inline char* Calloc(size_t n);
inline char* UncheckedMalloc(size_t n);
inline char* UncheckedCalloc(size_t n);

// Used by the allocation functions when allocation fails.
// Thin wrapper around v8::Isolate::LowMemoryNotification() that checks
Expand Down

0 comments on commit 35d48d3

Please sign in to comment.