From a730c6c381cd287313497bce939bdcfbff1a36a4 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 4 Feb 2020 13:52:33 -0800 Subject: [PATCH 1/3] Wrap strdup to use compliant name on Windows A number of POSIX methods were renamed on Windows to match standards requirements, giving deprecation warnings when calling strdup on Windows. This adds a wrapper, to allow calling _strdup on Windows instead. Part of #16256 --- fml/BUILD.gn | 3 +++ fml/platform/posix/posix_wrappers_posix.cc | 15 +++++++++++++++ fml/platform/win/posix_wrappers_win.cc | 15 +++++++++++++++ fml/posix_wrappers.h | 20 ++++++++++++++++++++ runtime/dart_isolate.cc | 15 ++++++++------- runtime/dart_service_isolate.cc | 13 +++++++------ runtime/service_protocol.cc | 3 ++- shell/common/skia_event_tracer_impl.cc | 3 ++- 8 files changed, 72 insertions(+), 15 deletions(-) create mode 100644 fml/platform/posix/posix_wrappers_posix.cc create mode 100644 fml/platform/win/posix_wrappers_win.cc create mode 100644 fml/posix_wrappers.h diff --git a/fml/BUILD.gn b/fml/BUILD.gn index ef0e996daea6d..2e257b49f611f 100644 --- a/fml/BUILD.gn +++ b/fml/BUILD.gn @@ -56,6 +56,7 @@ source_set("fml") { "native_library.h", "paths.cc", "paths.h", + "posix_wrappers.h", "size.h", "synchronization/atomic_object.h", "synchronization/count_down_latch.cc", @@ -200,6 +201,7 @@ source_set("fml") { "platform/win/message_loop_win.h", "platform/win/native_library_win.cc", "platform/win/paths_win.cc", + "platform/win/posix_wrappers_win.cc", "platform/win/wstring_conversion.h", ] } else { @@ -208,6 +210,7 @@ source_set("fml") { "platform/posix/mapping_posix.cc", "platform/posix/native_library_posix.cc", "platform/posix/paths_posix.cc", + "platform/posix/posix_wrappers_posix.cc", ] } } diff --git a/fml/platform/posix/posix_wrappers_posix.cc b/fml/platform/posix/posix_wrappers_posix.cc new file mode 100644 index 0000000000000..60d1bcea398f1 --- /dev/null +++ b/fml/platform/posix/posix_wrappers_posix.cc @@ -0,0 +1,15 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "flutter/fml/posix_wrappers.h" + +#include + +namespace fml { + +char* strdup(const char* str1) { + return strdup(str1); +} + +} // namespace fml diff --git a/fml/platform/win/posix_wrappers_win.cc b/fml/platform/win/posix_wrappers_win.cc new file mode 100644 index 0000000000000..ac674ddffe761 --- /dev/null +++ b/fml/platform/win/posix_wrappers_win.cc @@ -0,0 +1,15 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "flutter/fml/posix_wrappers.h" + +#include + +namespace fml { + +char* strdup(const char* str1) { + return _strdup(str1); +} + +} // namespace fml diff --git a/fml/posix_wrappers.h b/fml/posix_wrappers.h new file mode 100644 index 0000000000000..14f09f1fd5142 --- /dev/null +++ b/fml/posix_wrappers.h @@ -0,0 +1,20 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FLUTTER_FML_POSIX_WRAPPERS_H_ +#define FLUTTER_FML_POSIX_WRAPPERS_H_ + +#include "flutter/fml/build_config.h" + +// Provides wrappers for POSIX functions that have been renamed on Windows. +// See +// https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4996?view=vs-2019#posix-function-names +// for context. +namespace fml { + +char* strdup(const char* str1); + +} // namespace fml + +#endif // FLUTTER_FML_POSIX_WRAPPERS_H_ diff --git a/runtime/dart_isolate.cc b/runtime/dart_isolate.cc index 64297625424a5..71fb6620fef33 100644 --- a/runtime/dart_isolate.cc +++ b/runtime/dart_isolate.cc @@ -8,6 +8,7 @@ #include #include "flutter/fml/paths.h" +#include "flutter/fml/posix_wrappers.h" #include "flutter/fml/trace_event.h" #include "flutter/lib/io/dart_io.h" #include "flutter/lib/ui/dart_runtime_hooks.h" @@ -577,7 +578,7 @@ Dart_Isolate DartIsolate::DartCreateAndStartServiceIsolate( auto vm_data = DartVMRef::GetVMData(); if (!vm_data) { - *error = strdup( + *error = fml::strdup( "Could not access VM data to initialize isolates. This may be because " "the VM has initialized shutdown on another thread already."); return nullptr; @@ -613,7 +614,7 @@ Dart_Isolate DartIsolate::DartCreateAndStartServiceIsolate( std::shared_ptr service_isolate = weak_service_isolate.lock(); if (!service_isolate) { - *error = strdup("Could not create the service isolate."); + *error = fml::strdup("Could not create the service isolate."); FML_DLOG(ERROR) << *error; return nullptr; } @@ -720,7 +721,7 @@ bool DartIsolate::DartIsolateInitializeCallback(void** child_callback_data, TRACE_EVENT0("flutter", "DartIsolate::DartIsolateInitializeCallback"); Dart_Isolate isolate = Dart_CurrentIsolate(); if (isolate == nullptr) { - *error = strdup("Isolate should be available in initialize callback."); + *error = fml::strdup("Isolate should be available in initialize callback."); FML_DLOG(ERROR) << *error; return false; } @@ -797,14 +798,14 @@ bool DartIsolate::InitializeIsolate( char** error) { TRACE_EVENT0("flutter", "DartIsolate::InitializeIsolate"); if (!embedder_isolate->Initialize(isolate)) { - *error = strdup("Embedder could not initialize the Dart isolate."); + *error = fml::strdup("Embedder could not initialize the Dart isolate."); FML_DLOG(ERROR) << *error; return false; } if (!embedder_isolate->LoadLibraries()) { - *error = - strdup("Embedder could not load libraries in the new Dart isolate."); + *error = fml::strdup( + "Embedder could not load libraries in the new Dart isolate."); FML_DLOG(ERROR) << *error; return false; } @@ -817,7 +818,7 @@ bool DartIsolate::InitializeIsolate( embedder_isolate->GetIsolateGroupData().GetChildIsolatePreparer(); FML_DCHECK(child_isolate_preparer); if (!child_isolate_preparer(embedder_isolate.get())) { - *error = strdup("Could not prepare the child isolate to run."); + *error = fml::strdup("Could not prepare the child isolate to run."); FML_DLOG(ERROR) << *error; return false; } diff --git a/runtime/dart_service_isolate.cc b/runtime/dart_service_isolate.cc index d13666be8fdf2..639e440b55cf7 100644 --- a/runtime/dart_service_isolate.cc +++ b/runtime/dart_service_isolate.cc @@ -8,6 +8,7 @@ #include #include "flutter/fml/logging.h" +#include "flutter/fml/posix_wrappers.h" #include "flutter/runtime/embedder_resources.h" #include "third_party/dart/runtime/include/dart_api.h" #include "third_party/tonic/converter/dart_converter.h" @@ -19,12 +20,12 @@ return handle; \ } -#define SHUTDOWN_ON_ERROR(handle) \ - if (Dart_IsError(handle)) { \ - *error = strdup(Dart_GetError(handle)); \ - Dart_ExitScope(); \ - Dart_ShutdownIsolate(); \ - return false; \ +#define SHUTDOWN_ON_ERROR(handle) \ + if (Dart_IsError(handle)) { \ + *error = fml::strdup(Dart_GetError(handle)); \ + Dart_ExitScope(); \ + Dart_ShutdownIsolate(); \ + return false; \ } namespace flutter { diff --git a/runtime/service_protocol.cc b/runtime/service_protocol.cc index 3c4c457868bec..3e199273599e2 100644 --- a/runtime/service_protocol.cc +++ b/runtime/service_protocol.cc @@ -13,6 +13,7 @@ #include #include +#include "flutter/fml/posix_wrappers.h" #include "flutter/fml/synchronization/waitable_event.h" #include "rapidjson/stringbuffer.h" #include "rapidjson/writer.h" @@ -123,7 +124,7 @@ bool ServiceProtocol::HandleMessage(const char* method, rapidjson::StringBuffer buffer; rapidjson::Writer writer(buffer); document.Accept(writer); - *json_object = strdup(buffer.GetString()); + *json_object = fml::strdup(buffer.GetString()); #ifndef NDEBUG FML_DLOG(INFO) << "Response: " << *json_object; diff --git a/shell/common/skia_event_tracer_impl.cc b/shell/common/skia_event_tracer_impl.cc index 58149695fb39a..0a445b4cd7631 100644 --- a/shell/common/skia_event_tracer_impl.cc +++ b/shell/common/skia_event_tracer_impl.cc @@ -8,6 +8,7 @@ #include #include "flutter/fml/logging.h" +#include "flutter/fml/posix_wrappers.h" #include "flutter/fml/trace_event.h" #include "third_party/dart/runtime/include/dart_tools_api.h" #include "third_party/skia/include/utils/SkEventTracer.h" @@ -243,7 +244,7 @@ bool enableSkiaTracingCallback(const char* method, const char** json_object) { FlutterEventTracer* tracer = static_cast(user_data); tracer->enable(); - *json_object = strdup("{\"type\":\"Success\"}"); + *json_object = fml::strdup("{\"type\":\"Success\"}"); return true; } From 21dcb5c92d22590f2d7045bc81a58b36cc4a2aa1 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 4 Feb 2020 14:28:16 -0800 Subject: [PATCH 2/3] Add missing qualification on posix strdup --- fml/platform/posix/posix_wrappers_posix.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fml/platform/posix/posix_wrappers_posix.cc b/fml/platform/posix/posix_wrappers_posix.cc index 60d1bcea398f1..a161ad03e04aa 100644 --- a/fml/platform/posix/posix_wrappers_posix.cc +++ b/fml/platform/posix/posix_wrappers_posix.cc @@ -9,7 +9,7 @@ namespace fml { char* strdup(const char* str1) { - return strdup(str1); + return ::strdup(str1); } } // namespace fml From 68b780cb7818ea5d7cef48e9a4b99fa14cc2cf2e Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 4 Feb 2020 16:44:30 -0800 Subject: [PATCH 3/3] License update --- ci/licenses_golden/licenses_flutter | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 47b45071df786..ab64380ddf439 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -201,6 +201,7 @@ FILE: ../../../flutter/fml/platform/posix/file_posix.cc FILE: ../../../flutter/fml/platform/posix/mapping_posix.cc FILE: ../../../flutter/fml/platform/posix/native_library_posix.cc FILE: ../../../flutter/fml/platform/posix/paths_posix.cc +FILE: ../../../flutter/fml/platform/posix/posix_wrappers_posix.cc FILE: ../../../flutter/fml/platform/posix/shared_mutex_posix.cc FILE: ../../../flutter/fml/platform/posix/shared_mutex_posix.h FILE: ../../../flutter/fml/platform/win/errors_win.cc @@ -211,7 +212,9 @@ FILE: ../../../flutter/fml/platform/win/message_loop_win.cc FILE: ../../../flutter/fml/platform/win/message_loop_win.h FILE: ../../../flutter/fml/platform/win/native_library_win.cc FILE: ../../../flutter/fml/platform/win/paths_win.cc +FILE: ../../../flutter/fml/platform/win/posix_wrappers_win.cc FILE: ../../../flutter/fml/platform/win/wstring_conversion.h +FILE: ../../../flutter/fml/posix_wrappers.h FILE: ../../../flutter/fml/size.h FILE: ../../../flutter/fml/status.h FILE: ../../../flutter/fml/synchronization/atomic_object.h