diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 8f70d14333d2f..4d6a80080708d 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 diff --git a/fml/BUILD.gn b/fml/BUILD.gn index 04ce5527fef7d..b47dcd77e9279 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", ] @@ -213,6 +215,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..a161ad03e04aa --- /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 b8082c2ff4032..aeb0b0d5d8ab0 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; } @@ -722,7 +723,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; } @@ -799,14 +800,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; } @@ -819,7 +820,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 d1722c265232d..218c3bb6035d9 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; }