Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap strdup to use compliant name on Windows #16372

Merged
merged 6 commits into from
Feb 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions fml/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
]

Expand All @@ -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",
]
}
}
Expand Down
15 changes: 15 additions & 0 deletions fml/platform/posix/posix_wrappers_posix.cc
Original file line number Diff line number Diff line change
@@ -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 <string.h>

namespace fml {

char* strdup(const char* str1) {
return ::strdup(str1);
}

} // namespace fml
15 changes: 15 additions & 0 deletions fml/platform/win/posix_wrappers_win.cc
Original file line number Diff line number Diff line change
@@ -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 <string.h>

namespace fml {

char* strdup(const char* str1) {
return _strdup(str1);
}

} // namespace fml
20 changes: 20 additions & 0 deletions fml/posix_wrappers.h
Original file line number Diff line number Diff line change
@@ -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_
15 changes: 8 additions & 7 deletions runtime/dart_isolate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <tuple>

#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"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -613,7 +614,7 @@ Dart_Isolate DartIsolate::DartCreateAndStartServiceIsolate(

std::shared_ptr<DartIsolate> 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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
13 changes: 7 additions & 6 deletions runtime/dart_service_isolate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <algorithm>

#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"
Expand All @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion runtime/service_protocol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <utility>
#include <vector>

#include "flutter/fml/posix_wrappers.h"
#include "flutter/fml/synchronization/waitable_event.h"
#include "rapidjson/stringbuffer.h"
#include "rapidjson/writer.h"
Expand Down Expand Up @@ -123,7 +124,7 @@ bool ServiceProtocol::HandleMessage(const char* method,
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
document.Accept(writer);
*json_object = strdup(buffer.GetString());
*json_object = fml::strdup(buffer.GetString());

#ifndef NDEBUG
FML_DLOG(INFO) << "Response: " << *json_object;
Expand Down
3 changes: 2 additions & 1 deletion shell/common/skia_event_tracer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <vector>

#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"
Expand Down Expand Up @@ -243,7 +244,7 @@ bool enableSkiaTracingCallback(const char* method,
const char** json_object) {
FlutterEventTracer* tracer = static_cast<FlutterEventTracer*>(user_data);
tracer->enable();
*json_object = strdup("{\"type\":\"Success\"}");
*json_object = fml::strdup("{\"type\":\"Success\"}");
return true;
}

Expand Down