Browse Source

src: squelch unused function warnings in util.h

Fixes: https://github.com/nodejs/node/issues/9083

PR-URL: https://github.com/nodejs/node/pull/9115
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
v7.x
solebox 8 years ago
committed by Anna Henningsen
parent
commit
7420ce8b7e
No known key found for this signature in database GPG Key ID: D8B9F5AEAE84E4CF
  1. 16
      src/util-inl.h
  2. 9
      src/util.h

16
src/util-inl.h

@ -357,39 +357,45 @@ T* UncheckedRealloc(T* pointer, size_t n) {
// As per spec realloc behaves like malloc if passed nullptr. // As per spec realloc behaves like malloc if passed nullptr.
template <typename T> template <typename T>
T* UncheckedMalloc(size_t n) { inline T* UncheckedMalloc(size_t n) {
if (n == 0) n = 1; if (n == 0) n = 1;
return UncheckedRealloc<T>(nullptr, n); return UncheckedRealloc<T>(nullptr, n);
} }
template <typename T> template <typename T>
T* UncheckedCalloc(size_t n) { inline T* UncheckedCalloc(size_t n) {
if (n == 0) n = 1; if (n == 0) n = 1;
MultiplyWithOverflowCheck(sizeof(T), n); MultiplyWithOverflowCheck(sizeof(T), n);
return static_cast<T*>(calloc(n, sizeof(T))); return static_cast<T*>(calloc(n, sizeof(T)));
} }
template <typename T> template <typename T>
T* Realloc(T* pointer, size_t n) { inline T* Realloc(T* pointer, size_t n) {
T* ret = UncheckedRealloc(pointer, n); T* ret = UncheckedRealloc(pointer, n);
if (n > 0) CHECK_NE(ret, nullptr); if (n > 0) CHECK_NE(ret, nullptr);
return ret; return ret;
} }
template <typename T> template <typename T>
T* Malloc(size_t n) { inline T* Malloc(size_t n) {
T* ret = UncheckedMalloc<T>(n); T* ret = UncheckedMalloc<T>(n);
if (n > 0) CHECK_NE(ret, nullptr); if (n > 0) CHECK_NE(ret, nullptr);
return ret; return ret;
} }
template <typename T> template <typename T>
T* Calloc(size_t n) { inline T* Calloc(size_t n) {
T* ret = UncheckedCalloc<T>(n); T* ret = UncheckedCalloc<T>(n);
if (n > 0) CHECK_NE(ret, nullptr); if (n > 0) CHECK_NE(ret, nullptr);
return ret; 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 } // namespace node
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

9
src/util.h

@ -38,11 +38,10 @@ inline T* Malloc(size_t n);
template <typename T> template <typename T>
inline T* Calloc(size_t n); inline T* Calloc(size_t n);
// Shortcuts for char*. inline char* Malloc(size_t n);
inline char* Malloc(size_t n) { return Malloc<char>(n); } inline char* Calloc(size_t n);
inline char* Calloc(size_t n) { return Calloc<char>(n); } inline char* UncheckedMalloc(size_t n);
inline char* UncheckedMalloc(size_t n) { return UncheckedMalloc<char>(n); } inline char* UncheckedCalloc(size_t n);
inline char* UncheckedCalloc(size_t n) { return UncheckedCalloc<char>(n); }
// Used by the allocation functions when allocation fails. // Used by the allocation functions when allocation fails.
// Thin wrapper around v8::Isolate::LowMemoryNotification() that checks // Thin wrapper around v8::Isolate::LowMemoryNotification() that checks

Loading…
Cancel
Save