From dbbd71cd75e6ab07b88b01ff290c31f0282b3b77 Mon Sep 17 00:00:00 2001 From: Ben Konyi Date: Wed, 10 Mar 2021 00:42:37 +0000 Subject: [PATCH] [ VM ] Remove requirement for presence of current isolate for Dart_ServiceSendDataEvent Fixes https://github.com/dart-lang/sdk/issues/44720 Fixed: 44720 TEST=Existing dart:io tests Change-Id: I003a339a91dca84dafc39c44ba804ecf3f6f84ae Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/190303 Commit-Queue: Ben Konyi Reviewed-by: Ryan Macnak --- runtime/bin/builtin_natives.cc | 8 ++++++-- runtime/bin/file_support.cc | 14 ++++++++------ runtime/include/dart_tools_api.h | 12 ++++++------ runtime/vm/dart_api_impl.cc | 30 +++++++++++++++++------------- runtime/vm/service.cc | 5 ++--- runtime/vm/service.h | 3 +-- 6 files changed, 40 insertions(+), 32 deletions(-) diff --git a/runtime/bin/builtin_natives.cc b/runtime/bin/builtin_natives.cc index 0c27be95e9b..14762ed7e63 100644 --- a/runtime/bin/builtin_natives.cc +++ b/runtime/bin/builtin_natives.cc @@ -99,8 +99,12 @@ void FUNCTION_NAME(Builtin_PrintString)(Dart_NativeArguments args) { if (ShouldCaptureStdout()) { // For now we report print output on the Stdout stream. uint8_t newline[] = {'\n'}; - Dart_ServiceSendDataEvent("Stdout", "WriteEvent", chars, length); - Dart_ServiceSendDataEvent("Stdout", "WriteEvent", newline, sizeof(newline)); + const char* res = + Dart_ServiceSendDataEvent("Stdout", "WriteEvent", chars, length); + ASSERT(res == nullptr); + res = Dart_ServiceSendDataEvent("Stdout", "WriteEvent", newline, + sizeof(newline)); + ASSERT(res == nullptr); } } diff --git a/runtime/bin/file_support.cc b/runtime/bin/file_support.cc index 722e3214099..f70253f1458 100644 --- a/runtime/bin/file_support.cc +++ b/runtime/bin/file_support.cc @@ -71,15 +71,17 @@ bool File::WriteFully(const void* buffer, int64_t num_bytes) { } if (capture_stdout || capture_stderr) { intptr_t fd = GetFD(); + const char* result = nullptr; if ((fd == STDOUT_FILENO) && capture_stdout) { - Dart_ServiceSendDataEvent("Stdout", "WriteEvent", - reinterpret_cast(buffer), - num_bytes); + result = Dart_ServiceSendDataEvent( + "Stdout", "WriteEvent", reinterpret_cast(buffer), + num_bytes); } else if ((fd == STDERR_FILENO) && capture_stderr) { - Dart_ServiceSendDataEvent("Stderr", "WriteEvent", - reinterpret_cast(buffer), - num_bytes); + result = Dart_ServiceSendDataEvent( + "Stderr", "WriteEvent", reinterpret_cast(buffer), + num_bytes); } + ASSERT(result == nullptr); } return true; } diff --git a/runtime/include/dart_tools_api.h b/runtime/include/dart_tools_api.h index a106d42efad..3ed741be957 100644 --- a/runtime/include/dart_tools_api.h +++ b/runtime/include/dart_tools_api.h @@ -260,13 +260,13 @@ DART_EXPORT void Dart_SetNativeServiceStreamCallback( * * \param bytes_length The length of the byte array. * - * \return Success if the arguments are well formed. Otherwise, returns an - * error handle. + * \return NULL if the arguments are well formed. Otherwise, returns an + * error string. The caller is responsible for freeing the error message. */ -DART_EXPORT Dart_Handle Dart_ServiceSendDataEvent(const char* stream_id, - const char* event_kind, - const uint8_t* bytes, - intptr_t bytes_length); +DART_EXPORT char* Dart_ServiceSendDataEvent(const char* stream_id, + const char* event_kind, + const uint8_t* bytes, + intptr_t bytes_length); /** * Usage statistics for a space/generation at a particular moment in time. diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc index 580d5e93443..8fcc8b9151d 100644 --- a/runtime/vm/dart_api_impl.cc +++ b/runtime/vm/dart_api_impl.cc @@ -6278,29 +6278,33 @@ DART_EXPORT void Dart_SetNativeServiceStreamCallback( #endif } -DART_EXPORT Dart_Handle Dart_ServiceSendDataEvent(const char* stream_id, - const char* event_kind, - const uint8_t* bytes, - intptr_t bytes_length) { +DART_EXPORT char* Dart_ServiceSendDataEvent(const char* stream_id, + const char* event_kind, + const uint8_t* bytes, + intptr_t bytes_length) { #if !defined(PRODUCT) - DARTSCOPE(Thread::Current()); - Isolate* I = T->isolate(); if (stream_id == NULL) { - RETURN_NULL_ERROR(stream_id); + return Utils::StrDup( + "Dart_ServiceSendDataEvent expects argument 'stream_id' to be " + "non-null."); } if (event_kind == NULL) { - RETURN_NULL_ERROR(event_kind); + return Utils::StrDup( + "Dart_ServiceSendDataEvent expects argument 'event_kind' to be " + "non-null."); } if (bytes == NULL) { - RETURN_NULL_ERROR(bytes); + return Utils::StrDup( + "Dart_ServiceSendDataEvent expects argument 'bytes' to be non-null."); } if (bytes_length < 0) { - return Api::NewError("%s expects argument 'bytes_length' to be >= 0.", - CURRENT_FUNC); + return Utils::StrDup( + "Dart_ServiceSendDataEvent expects argument 'bytes_length' to be >= " + "0."); } - Service::SendEmbedderEvent(I, stream_id, event_kind, bytes, bytes_length); + Service::SendEmbedderEvent(stream_id, event_kind, bytes, bytes_length); #endif - return Api::Success(); + return nullptr; } DART_EXPORT void Dart_SetGCEventCallback(Dart_GCEventCallback callback) { diff --git a/runtime/vm/service.cc b/runtime/vm/service.cc index ee7a7ec88e3..e56f4eae094 100644 --- a/runtime/vm/service.cc +++ b/runtime/vm/service.cc @@ -4309,12 +4309,11 @@ void Service::SendInspectEvent(Isolate* isolate, const Object& inspectee) { Service::HandleEvent(&event); } -void Service::SendEmbedderEvent(Isolate* isolate, - const char* stream_id, +void Service::SendEmbedderEvent(const char* stream_id, const char* event_kind, const uint8_t* bytes, intptr_t bytes_len) { - ServiceEvent event(isolate, ServiceEvent::kEmbedder); + ServiceEvent event(ServiceEvent::kEmbedder); event.set_embedder_kind(event_kind); event.set_embedder_stream_id(stream_id); event.set_bytes(bytes, bytes_len); diff --git a/runtime/vm/service.h b/runtime/vm/service.h index 00a3f321004..99c7e208ac1 100644 --- a/runtime/vm/service.h +++ b/runtime/vm/service.h @@ -125,8 +125,7 @@ class Service : public AllStatic { static void SendEchoEvent(Isolate* isolate, const char* text); static void SendInspectEvent(Isolate* isolate, const Object& inspectee); - static void SendEmbedderEvent(Isolate* isolate, - const char* stream_id, + static void SendEmbedderEvent(const char* stream_id, const char* event_kind, const uint8_t* bytes, intptr_t bytes_len);