| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b8919b1 commit 57cc4e3
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1795,6 +1795,31 @@ NO_RETURN void Abort() { | |||
| 1795 | 1795 | } | |
| 1796 | 1796 | ||
| 1797 | 1797 | ||
| 1798 | + NO_RETURN void Assert(const char* const (*args)[4]) { | ||
| 1799 | + auto filename = (*args)[0]; | ||
| 1800 | + auto linenum = (*args)[1]; | ||
| 1801 | + auto message = (*args)[2]; | ||
| 1802 | + auto function = (*args)[3]; | ||
| 1803 | + | ||
| 1804 | + char exepath[256]; | ||
| 1805 | + size_t exepath_size = sizeof(exepath); | ||
| 1806 | + if (uv_exepath(exepath, &exepath_size)) | ||
| 1807 | + snprintf(exepath, sizeof(exepath), "node"); | ||
| 1808 | + | ||
| 1809 | + char pid[12] = {0}; | ||
| 1810 | + #ifndef _WIN32 | ||
| 1811 | + snprintf(pid, sizeof(pid), "[%u]", getpid()); | ||
| 1812 | + #endif | ||
| 1813 | + | ||
| 1814 | + fprintf(stderr, "%s%s: %s:%s:%s%s Assertion `%s' failed.\n", | ||
| 1815 | + exepath, pid, filename, linenum, | ||
| 1816 | + function, *function ? ":" : "", message); | ||
| 1817 | + fflush(stderr); | ||
| 1818 | + | ||
| 1819 | + Abort(); | ||
| 1820 | + } | ||
| 1821 | + | ||
| 1822 | + | ||
| 1798 | 1823 | static void Abort(const FunctionCallbackInfo<Value>& args) { | |
| 1799 | 1824 | Abort(); | |
| 1800 | 1825 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,7 +25,10 @@ namespace node { | |||
| 25 | 25 | #define NO_RETURN | |
| 26 | 26 | #endif | |
| 27 | 27 | ||
| 28 | + // The slightly odd function signature for Assert() is to ease | ||
| 29 | + // instruction cache pressure in calls from ASSERT and CHECK. | ||
| 28 | 30 | NO_RETURN void Abort(); | |
| 31 | + NO_RETURN void Assert(const char* const (*args)[4]); | ||
| 29 | 32 | void DumpBacktrace(FILE* fp); | |
| 30 | 33 | ||
| 31 | 34 | #ifdef __APPLE__ | |
@@ -52,15 +55,40 @@ template <typename T> using remove_reference = std::remove_reference<T>; | |||
| 52 | 55 | ||
| 53 | 56 | #define ABORT() node::Abort() | |
| 54 | 57 | ||
| 55 | - #if defined(NDEBUG) | ||
| 56 | - # define ASSERT(expression) | ||
| 57 | - # define CHECK(expression) \ | ||
| 58 | + #ifdef __GNUC__ | ||
| 59 | + #define LIKELY(expr) __builtin_expect(!!(expr), 1) | ||
| 60 | + #define UNLIKELY(expr) __builtin_expect(!!(expr), 0) | ||
| 61 | + #define PRETTY_FUNCTION_NAME __PRETTY_FUNCTION__ | ||
| 62 | + #else | ||
| 63 | + #define LIKELY(expr) expr | ||
| 64 | + #define UNLIKELY(expr) expr | ||
| 65 | + #define PRETTY_FUNCTION_NAME "" | ||
| 66 | + #endif | ||
| 67 | + | ||
| 68 | + #define STRINGIFY_(x) #x | ||
| 69 | + #define STRINGIFY(x) STRINGIFY_(x) | ||
| 70 | + | ||
| 71 | + #define CHECK(expr) \ | ||
| 58 | 72 | do { \ | |
| 59 | - if (!(expression)) ABORT(); \ | ||
| 73 | + if (UNLIKELY(!(expr))) { \ | ||
| 74 | + static const char* const args[] = { __FILE__, STRINGIFY(__LINE__), \ | ||
| 75 | + #expr, PRETTY_FUNCTION_NAME }; \ | ||
| 76 | + node::Assert(&args); \ | ||
| 77 | + } \ | ||
| 60 | 78 | } while (0) | |
| 79 | + | ||
| 80 | + // FIXME(bnoordhuis) cctests don't link in node::Abort() and node::Assert(). | ||
| 81 | + #ifdef GTEST_DONT_DEFINE_ASSERT_EQ | ||
| 82 | + #undef ABORT | ||
| 83 | + #undef CHECK | ||
| 84 | + #define ABORT ABORT_NO_BACKTRACE | ||
| 85 | + #define CHECK assert | ||
| 86 | + #endif | ||
| 87 | + | ||
| 88 | + #ifdef NDEBUG | ||
| 89 | + #define ASSERT(expr) | ||
| 61 | 90 | #else | |
| 62 | - # define ASSERT(expression) assert(expression) | ||
| 63 | - # define CHECK(expression) assert(expression) | ||
| 91 | + #define ASSERT(expr) CHECK(expr) | ||
| 64 | 92 | #endif | |
| 65 | 93 | ||
| 66 | 94 | #define ASSERT_EQ(a, b) ASSERT((a) == (b)) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments