Skip to content

Commit

Permalink
fix: update win32 macro
Browse files Browse the repository at this point in the history
  • Loading branch information
LeuisKen authored and andycall committed Nov 2, 2024
1 parent 5adb9f3 commit 7736dd7
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions bridge/bindings/qjs/qjs_engine_patch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <quickjs/list.h>
#include <cstring>

#if WIN32
#if defined(_WIN32)
#include <Windows.h>
#endif

Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
}
4 changes: 2 additions & 2 deletions bridge/bindings/qjs/script_value.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "qjs_engine_patch.h"
#include "qjs_event_target.h"

#if WIN32
#if defined(_WIN32)
#include <Windows.h>
#endif

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions bridge/core/dom/element_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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>");
Expand Down Expand Up @@ -168,4 +168,4 @@ TEST(Element, instanceofEventTarget) {

EXPECT_EQ(errorCalled, false);
EXPECT_EQ(logCalled, true);
}
}
6 changes: 3 additions & 3 deletions bridge/foundation/dart_readable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@
#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);
#endif
}

void dart_free(void* ptr) {
#if WIN32
#if defined(_WIN32)
return CoTaskMemFree(ptr);
#else
return free(ptr);
Expand Down
10 changes: 5 additions & 5 deletions bridge/foundation/native_string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "native_string.h"
#include <string>

#if WIN32
#if defined(_WIN32)
#include <Windows.h>
#endif

Expand All @@ -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)));
Expand All @@ -28,23 +28,23 @@ AutoFreeNativeString::~AutoFreeNativeString() {
}

void SharedNativeString::_free() const {
#if WIN32
#if defined(_WIN32)
CoTaskMemFree((LPVOID)string_);
#else
delete[] string_;
#endif
}

void* SharedNativeString::operator new(std::size_t size) {
#if WIN32
#if defined(_WIN32)
return CoTaskMemAlloc(size);
#else
return malloc(size);
#endif
}

void SharedNativeString::operator delete(void* memory) noexcept {
#if WIN32
#if defined(_WIN32)
return CoTaskMemFree(memory);
#else
return free(memory);
Expand Down

0 comments on commit 7736dd7

Please sign in to comment.