From 7420ce8b7e850ecb5c11a3c5cf87bda5e98e7e4f Mon Sep 17 00:00:00 2001 From: solebox Date: Sun, 16 Oct 2016 14:03:38 +0300 Subject: [PATCH] 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 Reviewed-By: James M Snell Reviewed-By: Ben Noordhuis --- src/util-inl.h | 16 +++++++++++----- src/util.h | 9 ++++----- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/util-inl.h b/src/util-inl.h index 5ffe5b857f5381..82ab6632773854 100644 --- a/src/util-inl.h +++ b/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. template -T* UncheckedMalloc(size_t n) { +inline T* UncheckedMalloc(size_t n) { if (n == 0) n = 1; return UncheckedRealloc(nullptr, n); } template -T* UncheckedCalloc(size_t n) { +inline T* UncheckedCalloc(size_t n) { if (n == 0) n = 1; MultiplyWithOverflowCheck(sizeof(T), n); return static_cast(calloc(n, sizeof(T))); } template -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 -T* Malloc(size_t n) { +inline T* Malloc(size_t n) { T* ret = UncheckedMalloc(n); if (n > 0) CHECK_NE(ret, nullptr); return ret; } template -T* Calloc(size_t n) { +inline T* Calloc(size_t n) { T* ret = UncheckedCalloc(n); if (n > 0) CHECK_NE(ret, nullptr); return ret; } +// Shortcuts for char*. +inline char* Malloc(size_t n) { return Malloc(n); } +inline char* Calloc(size_t n) { return Calloc(n); } +inline char* UncheckedMalloc(size_t n) { return UncheckedMalloc(n); } +inline char* UncheckedCalloc(size_t n) { return UncheckedCalloc(n); } + } // namespace node #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS diff --git a/src/util.h b/src/util.h index d1c5ac0285beb0..b32f2b8a71ca0f 100644 --- a/src/util.h +++ b/src/util.h @@ -38,11 +38,10 @@ inline T* Malloc(size_t n); template inline T* Calloc(size_t n); -// Shortcuts for char*. -inline char* Malloc(size_t n) { return Malloc(n); } -inline char* Calloc(size_t n) { return Calloc(n); } -inline char* UncheckedMalloc(size_t n) { return UncheckedMalloc(n); } -inline char* UncheckedCalloc(size_t n) { return UncheckedCalloc(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