mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Wrap strdup to use compliant name on Windows (#16372)
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
This commit is contained in:
parent
28e663726a
commit
9ad81dae16
@ -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
|
||||
|
||||
@ -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",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
15
fml/platform/posix/posix_wrappers_posix.cc
Normal file
15
fml/platform/posix/posix_wrappers_posix.cc
Normal file
@ -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
fml/platform/win/posix_wrappers_win.cc
Normal file
15
fml/platform/win/posix_wrappers_win.cc
Normal file
@ -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
fml/posix_wrappers.h
Normal file
20
fml/posix_wrappers.h
Normal file
@ -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_
|
||||
@ -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"
|
||||
@ -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<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;
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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"
|
||||
@ -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 {
|
||||
|
||||
@ -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"
|
||||
@ -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;
|
||||
|
||||
@ -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"
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user