From 7736dd749b28c5b29a6f43075e42ab6f0610c413 Mon Sep 17 00:00:00 2001 From: LeuisKen <leuisken@gmail.com> Date: Sat, 2 Nov 2024 17:17:30 +0100 Subject: [PATCH] fix: update win32 macro --- bridge/bindings/qjs/qjs_engine_patch.cc | 8 ++++---- bridge/bindings/qjs/script_value.cc | 4 ++-- bridge/core/dom/element_test.cc | 4 ++-- bridge/foundation/dart_readable.cc | 6 +++--- bridge/foundation/native_string.cc | 10 +++++----- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/bridge/bindings/qjs/qjs_engine_patch.cc b/bridge/bindings/qjs/qjs_engine_patch.cc index 7f30fa367c..6dbd8766ce 100644 --- a/bridge/bindings/qjs/qjs_engine_patch.cc +++ b/bridge/bindings/qjs/qjs_engine_patch.cc @@ -8,7 +8,7 @@ #include <quickjs/list.h> #include <cstring> -#if WIN32 +#if defined(_WIN32) #include <Windows.h> #endif @@ -254,7 +254,7 @@ uint16_t* JS_ToUnicode(JSContext* ctx, JSValueConst value, uint32_t* length) { if (!string->is_wide_char) { uint8_t* p = string->u.str8; -#if WIN32 +#if defined(_WIN32) int utf16_str_len = MultiByteToWideChar(CP_ACP, 0, reinterpret_cast<const char*>(p), -1, NULL, 0) - 1; if (utf16_str_len == -1) { return nullptr; @@ -278,7 +278,7 @@ uint16_t* JS_ToUnicode(JSContext* ctx, JSValueConst value, uint32_t* length) { #endif } else { *length = string->len; -#if WIN32 +#if defined(_WIN32) buffer = (uint16_t*)CoTaskMemAlloc(sizeof(uint16_t) * string->len); #else buffer = (uint16_t*)malloc(sizeof(uint16_t) * string->len); @@ -450,4 +450,4 @@ JSGCPhaseEnum JS_GetEnginePhase(JSRuntime* runtime) { webf::StringView JSAtomToStringView(JSRuntime* runtime, JSAtom atom) { JSString* string = runtime->atom_array[atom]; return webf::StringView(string->u.str8, string->len, string->is_wide_char); -} \ No newline at end of file +} diff --git a/bridge/bindings/qjs/script_value.cc b/bridge/bindings/qjs/script_value.cc index e5232aa093..1e4e0e0cc4 100644 --- a/bridge/bindings/qjs/script_value.cc +++ b/bridge/bindings/qjs/script_value.cc @@ -15,7 +15,7 @@ #include "qjs_engine_patch.h" #include "qjs_event_target.h" -#if WIN32 +#if defined(_WIN32) #include <Windows.h> #endif @@ -54,7 +54,7 @@ static JSValue FromNativeValue(ExecutingContext* context, } case NativeTag::TAG_UINT8_BYTES: { auto free_func = [](JSRuntime* rt, void* opaque, void* ptr) { -#if WIN32 +#if defined(_WIN32) return CoTaskMemFree(ptr); #else return free(ptr); diff --git a/bridge/core/dom/element_test.cc b/bridge/core/dom/element_test.cc index faf135fead..306cc30b5c 100644 --- a/bridge/core/dom/element_test.cc +++ b/bridge/core/dom/element_test.cc @@ -84,7 +84,7 @@ TEST(Element, outerHTML) { bool static logCalled = false; webf::WebFPage::consoleMessageHandler = [](void* ctx, const std::string& message, int logLevel) { logCalled = true; -#if WIN32 +#if defined(_WIN32) EXPECT_STREQ(message.c_str(), "<div attr-key=\"attr-value\" style=\"width: 100px;height: 100px;\"></div> <div " "attr-key=\"attr-value\" style=\"width: 100px;height: 100px;\"></div>"); @@ -168,4 +168,4 @@ TEST(Element, instanceofEventTarget) { EXPECT_EQ(errorCalled, false); EXPECT_EQ(logCalled, true); -} \ No newline at end of file +} diff --git a/bridge/foundation/dart_readable.cc b/bridge/foundation/dart_readable.cc index fe0ddc80c6..07f76e650a 100644 --- a/bridge/foundation/dart_readable.cc +++ b/bridge/foundation/dart_readable.cc @@ -6,14 +6,14 @@ #include <cstdlib> #include <memory> -#if WIN32 +#if defined(_WIN32) #include <Windows.h> #endif namespace webf { void* dart_malloc(std::size_t size) { -#if WIN32 +#if defined(_WIN32) return CoTaskMemAlloc(size); #else return malloc(size); @@ -21,7 +21,7 @@ void* dart_malloc(std::size_t size) { } void dart_free(void* ptr) { -#if WIN32 +#if defined(_WIN32) return CoTaskMemFree(ptr); #else return free(ptr); diff --git a/bridge/foundation/native_string.cc b/bridge/foundation/native_string.cc index 3f447349bb..d213d70472 100644 --- a/bridge/foundation/native_string.cc +++ b/bridge/foundation/native_string.cc @@ -5,7 +5,7 @@ #include "native_string.h" #include <string> -#if WIN32 +#if defined(_WIN32) #include <Windows.h> #endif @@ -14,7 +14,7 @@ namespace webf { SharedNativeString::SharedNativeString(const uint16_t* string, uint32_t length) : length_(length), string_(string) {} std::unique_ptr<SharedNativeString> SharedNativeString::FromTemporaryString(const uint16_t* string, uint32_t length) { -#if WIN32 +#if defined(_WIN32) const auto* new_str = static_cast<const uint16_t*>(CoTaskMemAlloc(length * sizeof(uint16_t))); #else const auto* new_str = static_cast<const uint16_t*>(malloc(length * sizeof(uint16_t))); @@ -28,7 +28,7 @@ AutoFreeNativeString::~AutoFreeNativeString() { } void SharedNativeString::_free() const { -#if WIN32 +#if defined(_WIN32) CoTaskMemFree((LPVOID)string_); #else delete[] string_; @@ -36,7 +36,7 @@ void SharedNativeString::_free() const { } void* SharedNativeString::operator new(std::size_t size) { -#if WIN32 +#if defined(_WIN32) return CoTaskMemAlloc(size); #else return malloc(size); @@ -44,7 +44,7 @@ void* SharedNativeString::operator new(std::size_t size) { } void SharedNativeString::operator delete(void* memory) noexcept { -#if WIN32 +#if defined(_WIN32) return CoTaskMemFree(memory); #else return free(memory);