From d45047149545351e12c57914f9d1978982953ffa Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 14 Dec 2018 22:46:14 +0100 Subject: [PATCH 1/2] src: mark some global state as const Mark some global variables as `const` or `constexpr`. --- src/env.cc | 2 +- src/env.h | 2 +- src/node_file.cc | 4 ++-- src/node_http_parser_llhttp.cc | 2 +- src/node_http_parser_traditional.cc | 2 +- src/node_internals.h | 4 ++-- src/node_postmortem_metadata.cc | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/env.cc b/src/env.cc index 023e69665d94ed..ed6717d684421b 100644 --- a/src/env.cc +++ b/src/env.cc @@ -65,7 +65,7 @@ class TraceEventScope { }; int const Environment::kNodeContextTag = 0x6e6f64; -void* Environment::kNodeContextTagPtr = const_cast( +void* const Environment::kNodeContextTagPtr = const_cast( static_cast(&Environment::kNodeContextTag)); IsolateData::IsolateData(Isolate* isolate, diff --git a/src/env.h b/src/env.h index b46f45a0d2c21a..7eb8a557e6e29c 100644 --- a/src/env.h +++ b/src/env.h @@ -972,7 +972,7 @@ class Environment { uint64_t thread_id_ = 0; std::unordered_set sub_worker_contexts_; - static void* kNodeContextTagPtr; + static void* const kNodeContextTagPtr; static int const kNodeContextTag; #if HAVE_INSPECTOR diff --git a/src/node_file.cc b/src/node_file.cc index 49d316729485b6..d34a4b3ee136e8 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -81,9 +81,9 @@ using v8::Value; #endif #ifdef __POSIX__ -const char* kPathSeparator = "/"; +constexpr char kPathSeparator = '/'; #else -const char* kPathSeparator = "\\/"; +constexpr char kPathSeparator = '\\/'; #endif #define GET_OFFSET(a) ((a)->IsNumber() ? (a).As()->Value() : -1) diff --git a/src/node_http_parser_llhttp.cc b/src/node_http_parser_llhttp.cc index 7b9999d13c7cce..8728fa2b677403 100644 --- a/src/node_http_parser_llhttp.cc +++ b/src/node_http_parser_llhttp.cc @@ -4,7 +4,7 @@ namespace node { -const char* llhttp_version = +const char* const llhttp_version = NODE_STRINGIFY(LLHTTP_VERSION_MAJOR) "." NODE_STRINGIFY(LLHTTP_VERSION_MINOR) diff --git a/src/node_http_parser_traditional.cc b/src/node_http_parser_traditional.cc index 2bff20c1656020..2ea452239a0a1d 100644 --- a/src/node_http_parser_traditional.cc +++ b/src/node_http_parser_traditional.cc @@ -6,7 +6,7 @@ namespace node { -const char* http_parser_version = +const char* const http_parser_version = NODE_STRINGIFY(HTTP_PARSER_VERSION_MAJOR) "." NODE_STRINGIFY(HTTP_PARSER_VERSION_MINOR) diff --git a/src/node_internals.h b/src/node_internals.h index 1d43d4b1419b9c..9c0b8ac3a7b906 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -697,8 +697,8 @@ static inline const char* errno_string(int errorno) { extern double prog_start_time; -extern const char* llhttp_version; -extern const char* http_parser_version; +extern const char* const llhttp_version; +extern const char* const http_parser_version; void Abort(const v8::FunctionCallbackInfo& args); void Chdir(const v8::FunctionCallbackInfo& args); diff --git a/src/node_postmortem_metadata.cc b/src/node_postmortem_metadata.cc index 93bf5a4dd7d8f4..527bfb623e65de 100644 --- a/src/node_postmortem_metadata.cc +++ b/src/node_postmortem_metadata.cc @@ -60,6 +60,6 @@ int GenDebugSymbols() { return 1; } -int debug_symbols_generated = GenDebugSymbols(); +const int debug_symbols_generated = GenDebugSymbols(); } // namespace node From 9084190d2b271d39015fd39f8d51597db37ab742 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 15 Dec 2018 18:35:19 +0100 Subject: [PATCH 2/2] fixup! src: mark some global state as const --- src/node_file.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node_file.cc b/src/node_file.cc index d34a4b3ee136e8..b66c0fe6d20915 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -83,7 +83,7 @@ using v8::Value; #ifdef __POSIX__ constexpr char kPathSeparator = '/'; #else -constexpr char kPathSeparator = '\\/'; +const char* const kPathSeparator = "\\/"; #endif #define GET_OFFSET(a) ((a)->IsNumber() ? (a).As()->Value() : -1)