[VM] : Cleanup the file modified and service stream callbacks in
Dart_Cleanup so that the Flutter engine can restart the VM.
Change-Id: I3ecb13859ac5731b00af3c7dfa4aa47caa929d2e
Reviewed-on: https://dart-review.googlesource.com/c/81203
Commit-Queue: Siva Annamalai <asiva@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
diff --git a/runtime/include/dart_tools_api.h b/runtime/include/dart_tools_api.h
index 4ee47ef..5452c25 100644
--- a/runtime/include/dart_tools_api.h
+++ b/runtime/include/dart_tools_api.h
@@ -5,7 +5,7 @@
#ifndef RUNTIME_INCLUDE_DART_TOOLS_API_H_
#define RUNTIME_INCLUDE_DART_TOOLS_API_H_
-#include "dart_api.h"
+#include "include/dart_api.h"
/** \mainpage Dart Tools Embedding API Reference
*
@@ -217,7 +217,7 @@
* \return Success if the callbacks were added. Otherwise, returns an
* error handle.
*/
-DART_EXPORT Dart_Handle Dart_SetServiceStreamCallbacks(
+DART_EXPORT char* Dart_SetServiceStreamCallbacks(
Dart_ServiceStreamListenCallback listen_callback,
Dart_ServiceStreamCancelCallback cancel_callback);
@@ -266,8 +266,8 @@
*/
typedef bool (*Dart_FileModifiedCallback)(const char* url, int64_t since);
-DART_EXPORT Dart_Handle
-Dart_SetFileModifiedCallback(Dart_FileModifiedCallback file_modified_callback);
+DART_EXPORT char* Dart_SetFileModifiedCallback(
+ Dart_FileModifiedCallback file_modified_callback);
/**
* Returns true if isolate is currently reloading.
diff --git a/runtime/vm/dart.cc b/runtime/vm/dart.cc
index 09a81f4..b51ffe3 100644
--- a/runtime/vm/dart.cc
+++ b/runtime/vm/dart.cc
@@ -17,6 +17,7 @@
#include "vm/heap/heap.h"
#include "vm/heap/pointer_block.h"
#include "vm/isolate.h"
+#include "vm/isolate_reload.h"
#include "vm/kernel_isolate.h"
#include "vm/malloc_hooks.h"
#include "vm/message_handler.h"
@@ -540,6 +541,10 @@
}
MallocHooks::Cleanup();
Flags::Cleanup();
+#if !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)
+ IsolateReloadContext::SetFileModifiedCallback(NULL);
+ Service::SetEmbedderStreamCallbacks(NULL, NULL);
+#endif // !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)
return NULL;
}
diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc
index b2055ad..a658ab7 100644
--- a/runtime/vm/dart_api_impl.cc
+++ b/runtime/vm/dart_api_impl.cc
@@ -5702,10 +5702,10 @@
return;
}
-DART_EXPORT Dart_Handle Dart_SetServiceStreamCallbacks(
+DART_EXPORT char* Dart_SetServiceStreamCallbacks(
Dart_ServiceStreamListenCallback listen_callback,
Dart_ServiceStreamCancelCallback cancel_callback) {
- return Api::Success();
+ return NULL;
}
DART_EXPORT Dart_Handle Dart_ServiceSendDataEvent(const char* stream_id,
@@ -5715,9 +5715,9 @@
return Api::Success();
}
-DART_EXPORT Dart_Handle
-Dart_SetFileModifiedCallback(Dart_FileModifiedCallback file_mod_callback) {
- return Api::Success();
+DART_EXPORT char* Dart_SetFileModifiedCallback(
+ Dart_FileModifiedCallback file_mod_callback) {
+ return NULL;
}
DART_EXPORT bool Dart_IsReloading() {
@@ -5774,42 +5774,42 @@
}
}
-DART_EXPORT Dart_Handle Dart_SetServiceStreamCallbacks(
+DART_EXPORT char* Dart_SetServiceStreamCallbacks(
Dart_ServiceStreamListenCallback listen_callback,
Dart_ServiceStreamCancelCallback cancel_callback) {
if (!FLAG_support_service) {
- return Api::Success();
+ return NULL;
}
if (listen_callback != NULL) {
if (Service::stream_listen_callback() != NULL) {
- return Api::NewError(
- "%s permits only one listen callback to be registered, please "
- "remove the existing callback and then add this callback",
- CURRENT_FUNC);
+ return strdup(
+ "Dart_SetServiceStreamCallbacks "
+ "permits only one listen callback to be registered, please "
+ "remove the existing callback and then add this callback");
}
} else {
if (Service::stream_listen_callback() == NULL) {
- return Api::NewError(
- "%s expects 'listen_callback' to be present in the callback set.",
- CURRENT_FUNC);
+ return strdup(
+ "Dart_SetServiceStreamCallbacks "
+ "expects 'listen_callback' to be present in the callback set.");
}
}
if (cancel_callback != NULL) {
if (Service::stream_cancel_callback() != NULL) {
- return Api::NewError(
- "%s permits only one cancel callback to be registered, please "
- "remove the existing callback and then add this callback",
- CURRENT_FUNC);
+ return strdup(
+ "Dart_SetServiceStreamCallbacks "
+ "permits only one cancel callback to be registered, please "
+ "remove the existing callback and then add this callback");
}
} else {
if (Service::stream_cancel_callback() == NULL) {
- return Api::NewError(
- "%s expects 'cancel_callback' to be present in the callback set.",
- CURRENT_FUNC);
+ return strdup(
+ "Dart_SetServiceStreamCallbacks "
+ "expects 'cancel_callback' to be present in the callback set.");
}
}
Service::SetEmbedderStreamCallbacks(listen_callback, cancel_callback);
- return Api::Success();
+ return NULL;
}
DART_EXPORT Dart_Handle Dart_ServiceSendDataEvent(const char* stream_id,
@@ -5835,29 +5835,29 @@
return Api::Success();
}
-DART_EXPORT Dart_Handle
-Dart_SetFileModifiedCallback(Dart_FileModifiedCallback file_modified_callback) {
+DART_EXPORT char* Dart_SetFileModifiedCallback(
+ Dart_FileModifiedCallback file_modified_callback) {
if (!FLAG_support_service) {
- return Api::Success();
+ return NULL;
}
#if !defined(DART_PRECOMPILED_RUNTIME)
if (file_modified_callback != NULL) {
if (IsolateReloadContext::file_modified_callback() != NULL) {
- return Api::NewError(
- "%s permits only one callback to be registered, please "
- "remove the existing callback and then add this callback",
- CURRENT_FUNC);
+ return strdup(
+ "Dart_SetFileModifiedCallback permits only one callback to be"
+ " registered, please remove the existing callback and then add"
+ " this callback");
}
} else {
if (IsolateReloadContext::file_modified_callback() == NULL) {
- return Api::NewError(
- "%s expects 'file_modified_callback' to be set before it is cleared.",
- CURRENT_FUNC);
+ return strdup(
+ "Dart_SetFileModifiedCallback expects 'file_modified_callback' to"
+ " be set before it is cleared.");
}
}
IsolateReloadContext::SetFileModifiedCallback(file_modified_callback);
#endif // !defined(DART_PRECOMPILED_RUNTIME)
- return Api::Success();
+ return NULL;
}
DART_EXPORT bool Dart_IsReloading() {