From 07a84969197bccbb5f64e098b4522b6a9f572a59 Mon Sep 17 00:00:00 2001 From: Ben Konyi Date: Tue, 2 Oct 2018 00:33:37 +0000 Subject: [PATCH] [VM] Allow for Dart_SetVMFlags to be called again after Dart_Cleanup Change-Id: Icf07258cfb05a987e0a439277a59825c06f993b2 Reviewed-on: https://dart-review.googlesource.com/77486 Auto-Submit: Ben Konyi Reviewed-by: Zach Anderson Commit-Queue: Ben Konyi --- runtime/bin/run_vm_tests.cc | 2 ++ runtime/vm/dart.cc | 1 + runtime/vm/dart_api_impl_test.cc | 1 + runtime/vm/flags.cc | 5 +++++ runtime/vm/flags.h | 2 ++ runtime/vm/unit_test.cc | 2 ++ runtime/vm/unit_test.h | 2 ++ 7 files changed, 15 insertions(+) diff --git a/runtime/bin/run_vm_tests.cc b/runtime/bin/run_vm_tests.cc index 92af3dcaeb1..c90c210d4d2 100644 --- a/runtime/bin/run_vm_tests.cc +++ b/runtime/bin/run_vm_tests.cc @@ -281,6 +281,8 @@ static int Main(int argc, const char** argv) { TesterState::vm_snapshot_data = dart::bin::vm_snapshot_data; TesterState::create_callback = CreateIsolateAndSetup; TesterState::cleanup_callback = CleanupIsolate; + TesterState::argv = dart_argv; + TesterState::argc = dart_argc; error = Dart::Init( dart::bin::vm_snapshot_data, dart::bin::vm_snapshot_instructions, diff --git a/runtime/vm/dart.cc b/runtime/vm/dart.cc index db4282eeaa8..df9a255d4c1 100644 --- a/runtime/vm/dart.cc +++ b/runtime/vm/dart.cc @@ -531,6 +531,7 @@ const char* Dart::Cleanup() { OS::PrintErr("[+%" Pd64 "ms] SHUTDOWN: Done\n", UptimeMillis()); } MallocHooks::Cleanup(); + Flags::Cleanup(); return NULL; } diff --git a/runtime/vm/dart_api_impl_test.cc b/runtime/vm/dart_api_impl_test.cc index 64653eed3c5..c5a7f5f32d1 100644 --- a/runtime/vm/dart_api_impl_test.cc +++ b/runtime/vm/dart_api_impl_test.cc @@ -29,6 +29,7 @@ DECLARE_FLAG(bool, use_dart_frontend); #ifndef PRODUCT UNIT_TEST_CASE(DartAPI_DartInitializeAfterCleanup) { + EXPECT(Dart_SetVMFlags(TesterState::argc, TesterState::argv) == NULL); Dart_InitializeParams params; memset(¶ms, 0, sizeof(Dart_InitializeParams)); params.version = DART_INITIALIZE_PARAMS_CURRENT_VERSION; diff --git a/runtime/vm/flags.cc b/runtime/vm/flags.cc index 7b454b30f81..3cd342208a7 100644 --- a/runtime/vm/flags.cc +++ b/runtime/vm/flags.cc @@ -177,6 +177,11 @@ bool Flags::IsSet(const char* name) { (flag->bool_ptr_ != NULL) && (*flag->bool_ptr_ == true); } +void Flags::Cleanup() { + ASSERT(initialized_); + initialized_ = false; +} + void Flags::AddFlag(Flag* flag) { ASSERT(!initialized_); if (num_flags_ == capacity_) { diff --git a/runtime/vm/flags.h b/runtime/vm/flags.h index e72b33fc153..d230f5d5a89 100644 --- a/runtime/vm/flags.h +++ b/runtime/vm/flags.h @@ -71,6 +71,8 @@ class Flags { static bool Initialized() { return initialized_; } + static void Cleanup(); + #ifndef PRODUCT static void PrintJSON(JSONStream* js); #endif // !PRODUCT diff --git a/runtime/vm/unit_test.cc b/runtime/vm/unit_test.cc index 19cc6b52614..c56e77045ac 100644 --- a/runtime/vm/unit_test.cc +++ b/runtime/vm/unit_test.cc @@ -41,6 +41,8 @@ const uint8_t* TesterState::vm_snapshot_data = NULL; Dart_IsolateCreateCallback TesterState::create_callback = NULL; Dart_IsolateShutdownCallback TesterState::shutdown_callback = NULL; Dart_IsolateCleanupCallback TesterState::cleanup_callback = NULL; +const char** TesterState::argv = NULL; +int TesterState::argc = 0; DEFINE_FLAG(bool, use_dart_frontend, diff --git a/runtime/vm/unit_test.h b/runtime/vm/unit_test.h index e5b6740fbd9..a77dc9deb10 100644 --- a/runtime/vm/unit_test.h +++ b/runtime/vm/unit_test.h @@ -281,6 +281,8 @@ class TesterState : public AllStatic { static Dart_IsolateCreateCallback create_callback; static Dart_IsolateShutdownCallback shutdown_callback; static Dart_IsolateCleanupCallback cleanup_callback; + static const char** argv; + static int argc; }; class KernelBufferList {