From c4ef3e45d6067f666ea5846bfac64943d3923595 Mon Sep 17 00:00:00 2001 From: Keerecles Date: Tue, 10 Jun 2025 10:09:47 +0800 Subject: [PATCH 1/3] update compile config Signed-off-by: Keerecles Change-Id: I5286881ce86526964857ef9961c78c35ec155097 --- .../demo/localtest/build_config_template.json | 41 +++++++++++++------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/arkui-plugins/test/demo/localtest/build_config_template.json b/arkui-plugins/test/demo/localtest/build_config_template.json index 0df152f9d..64b8fdafb 100755 --- a/arkui-plugins/test/demo/localtest/build_config_template.json +++ b/arkui-plugins/test/demo/localtest/build_config_template.json @@ -1,5 +1,6 @@ { "plugins": { + "ui_syntax_plugin": "workspace/out/sdk/ohos-sdk/linux/ets/ets1.2/build-tools/ui-plugins/lib/ui-syntax-plugins/index", "ui_plugin": "workspace/out/sdk/ohos-sdk/linux/ets/ets1.2/build-tools/ui-plugins/lib/ui-plugins/index", "memo_plugin": "workspace/out/sdk/ohos-sdk/linux/ets/ets1.2/build-tools/ui-plugins/lib/memo-plugins/index" }, @@ -12,19 +13,35 @@ "./demo/localtest/entry/new.ets" ], - "packageName" : "entry", - "moduleType": "shared", - "hasMainModule": true, - - "buildType": "build", "buildMode": "Debug", + "projectRootPath": "./demo/localtest/", "moduleRootPath": "./demo/localtest/entry/", - "sourceRoots": ["./"], - - "loaderOutPath": "./dist", "cachePath": "./dist/cache", - + "loaderOutPath": "./dist", + "compileSdkVersion": 20, + "compatibleSdkVersion": 20, + "bundleName": "com.example.myapplication", + "useNormalizedOHMUrl": true, + "buildType": "build", + "packageName": "entry", "buildSdkPath": "workspace/out/sdk/ohos-sdk/linux/ets/ets1.2/", - - "dependentModuleList": [] -} \ No newline at end of file + "sourceRoots": [ + "./" + ], + "moduleType": "shared", + "moduleName": "entry", + "dependentModuleList": [], + "hasMainModule": true, + "buildLoaderJson": "", + "integratedHsp": false, + "allowEmptyBundleName": false, + "declgenV2OutPath": "", + "externalApiPaths": [ + ], + "level": { + "level": 20000, + "levelStr": "INFO", + "colour": "green" + }, + "isBuildConfigModified": false +} -- Gitee From fe19c0b3d1ca4696b2dc7812ce618c27ef2a8637 Mon Sep 17 00:00:00 2001 From: Keerecles Date: Thu, 12 Jun 2025 09:53:34 +0800 Subject: [PATCH 2/3] code clean: assert Signed-off-by: Keerecles Change-Id: I9b146e27c08f6a46d636f25802a1727203389506 --- .../interop/src/cpp/DeserializerBase.h | 3 +- .../koalaui/interop/src/cpp/SerializerBase.h | 11 +++-- .../koalaui/interop/src/cpp/interop-logging.h | 17 +++++-- .../interop/src/cpp/jsc/convertors-jsc.cc | 23 +++++----- .../interop/src/cpp/jsc/convertors-jsc.h | 44 ++++++++++--------- .../interop/src/cpp/wasm/convertors-wasm.h | 12 +++-- 6 files changed, 63 insertions(+), 47 deletions(-) diff --git a/koala-wrapper/koalaui/interop/src/cpp/DeserializerBase.h b/koala-wrapper/koalaui/interop/src/cpp/DeserializerBase.h index e09c40524..669d16f9f 100644 --- a/koala-wrapper/koalaui/interop/src/cpp/DeserializerBase.h +++ b/koala-wrapper/koalaui/interop/src/cpp/DeserializerBase.h @@ -16,7 +16,6 @@ #define _DESERIALIZER_BASE_H_ #include -#include #include #include #include @@ -343,7 +342,7 @@ public: { if (position + count > length) { fprintf(stderr, "Incorrect serialized data, check for %d, buffer %d position %d\n", count, length, position); - assert(false); + ASSERT(false); abort(); } } diff --git a/koala-wrapper/koalaui/interop/src/cpp/SerializerBase.h b/koala-wrapper/koalaui/interop/src/cpp/SerializerBase.h index f6cce0fae..f99efca14 100644 --- a/koala-wrapper/koalaui/interop/src/cpp/SerializerBase.h +++ b/koala-wrapper/koalaui/interop/src/cpp/SerializerBase.h @@ -21,13 +21,13 @@ #include #include #include -#include #include #include #include "callback-resource.h" #include "interop-types.h" #include "koala-types.h" +#include "interop-logging.h" #ifdef __arm__ #define KOALA_NO_UNALIGNED_ACCESS 1 @@ -55,7 +55,7 @@ T* allocArray(const std::array& ref) { std::size_t space = sizeof(buffer) - offset; void* ptr = buffer + offset; void* aligned_ptr = std::align(alignof(T), sizeof(T) * size, ptr, space); - assert(aligned_ptr != nullptr && "Insufficient space or alignment failed!"); + ASSERT(aligned_ptr != nullptr && "Insufficient space or alignment failed!"); offset = (char*)aligned_ptr + sizeof(T) * size - buffer; T* array = reinterpret_cast(aligned_ptr); for (size_t i = 0; i < size; ++i) { @@ -72,8 +72,8 @@ private: bool ownData; CallbackResourceHolder* resourceHolder; void resize(uint32_t newLength) { - assert(ownData); - assert(newLength > dataLength); + ASSERT(ownData); + ASSERT(newLength > dataLength); auto* newData = reinterpret_cast(malloc(newLength)); memcpy(newData, data, position); free(data); @@ -112,8 +112,7 @@ public: if (ownData) { resize(dataLength * 3 / 2 + 2); } else { - fprintf(stderr, "Buffer overrun: %d > %d\n", position + more, dataLength); - assert(false); + INTEROP_FATAL("Buffer overrun: %d > %d\n", position + more, dataLength); } } } diff --git a/koala-wrapper/koalaui/interop/src/cpp/interop-logging.h b/koala-wrapper/koalaui/interop/src/cpp/interop-logging.h index 4d1b7bc0f..493799010 100644 --- a/koala-wrapper/koalaui/interop/src/cpp/interop-logging.h +++ b/koala-wrapper/koalaui/interop/src/cpp/interop-logging.h @@ -15,8 +15,15 @@ #ifndef _INTEROP_LGGING_H #define _INTEROP_LGGING_H -#include -#include +#ifdef __cplusplus + #include + #include + #include +#else + #include + #include + #include +#endif #if defined(KOALA_OHOS) #include "oh_sk_log.h" @@ -37,6 +44,10 @@ #define INTEROP_API_EXPORT __attribute__((visibility("default"))) #endif +#ifndef ASSERT + #define ASSERT(expression) assert(expression) +#endif + // Grouped logs. Keep consistent with type in ServiceGroupLogger typedef struct GroupLogger { void (*startGroupedLog)(int kind); @@ -46,6 +57,6 @@ typedef struct GroupLogger { int (*needGroupedLog)(int kind); } GroupLogger; -const GroupLogger* GetDefaultLogger(); +extern "C" INTEROP_API_EXPORT const GroupLogger* GetDefaultLogger(); #endif // _INTEROP_LOGGING_H \ No newline at end of file diff --git a/koala-wrapper/koalaui/interop/src/cpp/jsc/convertors-jsc.cc b/koala-wrapper/koalaui/interop/src/cpp/jsc/convertors-jsc.cc index b1edbde65..1ae964f27 100644 --- a/koala-wrapper/koalaui/interop/src/cpp/jsc/convertors-jsc.cc +++ b/koala-wrapper/koalaui/interop/src/cpp/jsc/convertors-jsc.cc @@ -16,11 +16,12 @@ #include #include <_types/_uint32_t.h> #include <_types/_uint8_t.h> -#include #include #include "convertors-jsc.h" +#include "interop-logging.h" + // See https://github.com/BabylonJS/BabylonNative/blob/master/Dependencies/napi/napi-direct/source/js_native_api_javascriptcore.cc // for convertors logic. @@ -59,7 +60,7 @@ int32_t getInt32(JSContextRef context, JSValueRef value) { return 0; } if (JSValueIsUndefined(context, value)) { - assert(false); + ASSERT(false); return 0; } double result = JSValueToNumber(context, value, &exception); @@ -72,7 +73,7 @@ uint32_t getUInt32(JSContextRef context, JSValueRef value) { return 0; } if (JSValueIsUndefined(context, value)) { - assert(false); + ASSERT(false); return 0; } double result = JSValueToNumber(context, value, &exception); @@ -85,7 +86,7 @@ uint8_t getUInt8(JSContextRef context, JSValueRef value) { return 0; } if (JSValueIsUndefined(context, value)) { - assert(false); + ASSERT(false); return 0; } double result = JSValueToNumber(context, value, &exception); @@ -158,10 +159,10 @@ static uint64_t bigIntToU64(JSContextRef ctx, JSValueRef value) { JSStringRef strRef = JSValueToStringCopy(ctx, value, nullptr); size_t len = JSStringGetUTF8CString(strRef, buf, sizeof(buf)); JSStringRelease(strRef); - assert(len < sizeof(buf)); + ASSERT(len < sizeof(buf)); char* suf; uint64_t numValue = std::strtoull(buf, &suf, 10); - assert(*suf == '\0'); + ASSERT(*suf == '\0'); return numValue; } @@ -175,8 +176,8 @@ KNativePointerArray getPointerElements(JSContextRef context, JSValueRef value) { return nullptr; } - assert(JSValueIsObject(context, value)); - assert(JSValueGetTypedArrayType(context, value, nullptr) == kJSTypedArrayTypeBigUint64Array); + ASSERT(JSValueIsObject(context, value)); + ASSERT(JSValueGetTypedArrayType(context, value, nullptr) == kJSTypedArrayTypeBigUint64Array); JSObjectRef typedArray = JSValueToObject(context, value, nullptr); return reinterpret_cast(JSObjectGetTypedArrayBytesPtr(context, typedArray, nullptr)); @@ -188,7 +189,7 @@ KFloat getFloat(JSContextRef context, JSValueRef value) { return 0; } if (JSValueIsUndefined(context, value)) { - assert(false); + ASSERT(false); return 0; } double result = JSValueToNumber(context, value, &exception); @@ -201,7 +202,7 @@ KShort getShort(JSContextRef context, JSValueRef value) { return 0; } if (JSValueIsUndefined(context, value)) { - assert(false); + ASSERT(false); return 0; } double result = JSValueToNumber(context, value, &exception); @@ -214,7 +215,7 @@ KUShort getUShort(JSContextRef context, JSValueRef value) { return 0; } if (JSValueIsUndefined(context, value)) { - assert(false); + ASSERT(false); return 0; } double result = JSValueToNumber(context, value, &exception); diff --git a/koala-wrapper/koalaui/interop/src/cpp/jsc/convertors-jsc.h b/koala-wrapper/koalaui/interop/src/cpp/jsc/convertors-jsc.h index b100dff7d..860ccae7e 100644 --- a/koala-wrapper/koalaui/interop/src/cpp/jsc/convertors-jsc.h +++ b/koala-wrapper/koalaui/interop/src/cpp/jsc/convertors-jsc.h @@ -13,7 +13,8 @@ * limitations under the License. */ -#pragma once +#ifndef CONVERTORS_JSC_H +#define CONVERTORS_JSC_H #if defined(linux) #include // For IDE completion @@ -25,9 +26,8 @@ #include #include -#include - #include "koala-types.h" +#include "interop-logging.h" template inline ElemType* getTypedElements(JSContextRef context, const JSValueRef arguments) { @@ -35,7 +35,7 @@ inline ElemType* getTypedElements(JSContextRef context, const JSValueRef argumen return nullptr; } if (JSValueIsUndefined(context, arguments)) { - assert(false); + ASSERT(false); return nullptr; } JSValueRef exception {}; @@ -46,7 +46,7 @@ inline ElemType* getTypedElements(JSContextRef context, const JSValueRef argumen template inline ElemType* getTypedElements(JSContextRef context, size_t argumentCount, const JSValueRef arguments[], int index) { - assert(index < argumentCount); + ASSERT(index < argumentCount); return getTypedElements(context, arguments[index]); } @@ -74,85 +74,85 @@ inline Type getArgument(JSContextRef context, size_t argumentCount, const JSValu template <> inline int32_t getArgument(JSContextRef context, size_t argumentCount, const JSValueRef arguments[], int index) { - assert(index < argumentCount); + ASSERT(index < argumentCount); return getInt32(context, arguments[index]); } template <> inline uint32_t getArgument(JSContextRef context, size_t argumentCount, const JSValueRef arguments[], int index) { - assert(index < argumentCount); + ASSERT(index < argumentCount); return getUInt32(context, arguments[index]); } template <> inline uint8_t getArgument(JSContextRef context, size_t argumentCount, const JSValueRef arguments[], int index) { - assert(index < argumentCount); + ASSERT(index < argumentCount); return getUInt8(context, arguments[index]); } template <> inline KNativePointer getArgument(JSContextRef context, size_t argumentCount, const JSValueRef arguments[], int index) { - assert(index < argumentCount); + ASSERT(index < argumentCount); return getPointer(context, arguments[index]); } template <> inline KFloat getArgument(JSContextRef context, size_t argumentCount, const JSValueRef arguments[], int index) { - assert(index < argumentCount); + ASSERT(index < argumentCount); return getFloat(context, arguments[index]); } template <> inline KStringPtr getArgument(JSContextRef context, size_t argumentCount, const JSValueRef arguments[], int index) { - assert(index < argumentCount); + ASSERT(index < argumentCount); return getString(context, arguments[index]); } template <> inline KBoolean getArgument(JSContextRef context, size_t argumentCount, const JSValueRef arguments[], int index) { - assert(index < argumentCount); + ASSERT(index < argumentCount); return getBoolean(context, arguments[index]); } template <> inline KInt* getArgument(JSContextRef context, size_t argumentCount, const JSValueRef arguments[], int index) { - assert(index < argumentCount); + ASSERT(index < argumentCount); return getInt32Elements(context, arguments[index]); } template <> inline float* getArgument(JSContextRef context, size_t argumentCount, const JSValueRef arguments[], int index) { - assert(index < argumentCount); + ASSERT(index < argumentCount); return getFloat32Elements(context, arguments[index]); } template <> inline KByte* getArgument(JSContextRef context, size_t argumentCount, const JSValueRef arguments[], int index) { - assert(index < argumentCount); + ASSERT(index < argumentCount); return getByteElements(context, arguments[index]); } template <> inline KStringArray getArgument(JSContextRef context, size_t argumentCount, const JSValueRef arguments[], int index) { - assert(index < argumentCount); + ASSERT(index < argumentCount); return getKStringArray(context, arguments[index]); } template <> inline KUShort* getArgument(JSContextRef context, size_t argumentCount, const JSValueRef arguments[], int index) { - assert(index < argumentCount); + ASSERT(index < argumentCount); return getUShortElements(context, arguments[index]); } template <> inline KNativePointerArray getArgument(JSContextRef context, size_t argumentCount, const JSValueRef arguments[], int index) { - assert(index < argumentCount); + ASSERT(index < argumentCount); return getPointerElements(context, arguments[index]); } template <> inline KShort* getArgument(JSContextRef context, size_t argumentCount, const JSValueRef arguments[], int index) { - assert(index < argumentCount); + ASSERT(index < argumentCount); return getShortElements(context, arguments[index]); } @@ -711,12 +711,14 @@ void InitExports(JSGlobalContextRef globalContext); #define KOALA_INTEROP_THROW(vmContext, object, ...) \ do { \ - /* TODO: implement*/ assert(false); \ + /* TODO: implement*/ ASSERT(false); \ return __VA_ARGS__; \ } while (0) #define KOALA_INTEROP_THROW_STRING(vmContext, message, ...) \ do { \ - assert(false); /* TODO: implement*/ \ + ASSERT(false); /* TODO: implement*/ \ return __VA_ARGS__; \ } while (0) + +#endif // CONVERTORS_JSC_H \ No newline at end of file diff --git a/koala-wrapper/koalaui/interop/src/cpp/wasm/convertors-wasm.h b/koala-wrapper/koalaui/interop/src/cpp/wasm/convertors-wasm.h index eea97a98e..c0fffffa1 100644 --- a/koala-wrapper/koalaui/interop/src/cpp/wasm/convertors-wasm.h +++ b/koala-wrapper/koalaui/interop/src/cpp/wasm/convertors-wasm.h @@ -13,14 +13,16 @@ * limitations under the License. */ -#pragma once +#ifndef CONVERTORS_WASM_H +#define CONVERTORS_WASM_H #include "koala-types.h" -#include #include #define KOALA_INTEROP_EXPORT EMSCRIPTEN_KEEPALIVE extern "C" +#include "interop-logging.h" + template struct InteropTypeConverter { using InteropType = T; @@ -767,12 +769,14 @@ KOALA_INTEROP_EXPORT void name( \ #define KOALA_INTEROP_THROW(vmContext, object, ...) \ do { \ - assert(false); /* TODO: implement*/ \ + ASSERT(false); /* TODO: implement*/ \ return __VA_ARGS__; \ } while (0) #define KOALA_INTEROP_THROW_STRING(vmContext, message, ...) \ do { \ - assert(false); /* TODO: implement*/ \ + ASSERT(false); /* TODO: implement*/ \ return __VA_ARGS__; \ } while (0) + +#endif // CONVERTORS_WASM_H \ No newline at end of file -- Gitee From a3c63522269c1d13e02bd2db7fd3eb5b90aa6251 Mon Sep 17 00:00:00 2001 From: Keerecles Date: Thu, 12 Jun 2025 11:25:48 +0800 Subject: [PATCH 3/3] clean code: safe memcpy Signed-off-by: Keerecles Change-Id: I20a092605a2e41d579489f51a46e8070f33924be --- .../interop/src/cpp/DeserializerBase.h | 63 +++++++++++++++---- .../koalaui/interop/src/cpp/SerializerBase.h | 42 ++++++++++--- .../interop/src/cpp/ani/convertors-ani.cc | 21 ------- .../interop/src/cpp/ani/convertors-ani.h | 50 --------------- .../interop/src/cpp/callback-resource.cc | 22 +++++-- .../interop/src/cpp/cangjie/convertors-cj.h | 11 ++-- .../koalaui/interop/src/cpp/common-interop.cc | 23 +++++-- .../interop/src/cpp/ets/convertors-ets.cc | 2 - .../interop/src/cpp/ets/convertors-ets.h | 6 +- .../interop/src/cpp/interop-logging.cc | 13 ++-- .../koalaui/interop/src/cpp/interop-types.h | 6 +- .../interop/src/cpp/jni/convertors-jni.h | 26 +++++--- .../interop/src/cpp/jsc/convertors-jsc.cc | 6 +- .../interop/src/cpp/napi/convertors-napi.h | 14 +---- .../interop/src/cpp/napi/win-dynamic-node.cc | 11 +++- .../koalaui/interop/src/cpp/ohos/hilog/log.h | 9 ++- .../koalaui/interop/src/cpp/ohos/oh_sk_log.cc | 17 +++-- .../koalaui/interop/src/cpp/ohos/oh_sk_log.h | 5 +- .../koalaui/interop/src/cpp/profiler.h | 6 +- .../interop/src/cpp/types/koala-types.h | 8 ++- .../interop/src/cpp/types/signatures.cc | 34 +++++----- .../koalaui/interop/src/cpp/vmloader.cc | 1 - .../src/interop/java/CallbackRegistry.java | 12 ++-- 23 files changed, 239 insertions(+), 169 deletions(-) diff --git a/koala-wrapper/koalaui/interop/src/cpp/DeserializerBase.h b/koala-wrapper/koalaui/interop/src/cpp/DeserializerBase.h index 669d16f9f..4ff7a986c 100644 --- a/koala-wrapper/koalaui/interop/src/cpp/DeserializerBase.h +++ b/koala-wrapper/koalaui/interop/src/cpp/DeserializerBase.h @@ -23,6 +23,7 @@ #include "interop-types.h" #include "interop-logging.h" +#include "koala-types.h" void holdManagedCallbackResource(InteropInt32); void releaseManagedCallbackResource(InteropInt32); @@ -198,7 +199,11 @@ template <> inline void WriteToString(std::string *result, const InteropMaterialized *value) { char hex[20]; - std::snprintf(hex, sizeof(hex), "0x%llx", (long long)value->ptr); + #ifdef __STDC_LIB_EXT1__ + std::snprintf_s(hex, sizeof(hex), "0x%llx", (long long)value->ptr); + #else + std::snprintf(hex, sizeof(hex), "0x%llx", (long long)value->ptr); + #endif result->append("\""); result->append("Materialized "); result->append(hex); @@ -309,7 +314,11 @@ public: if (length > 0) { value = malloc(length * sizeof(E)); - memset(value, 0, length * sizeof(E)); + #ifdef __STDC_LIB_EXT1__ + memset_s(value, length * sizeof(E), 0, length * sizeof(E)); + #else + memset(value, 0, length * sizeof(E)); + #endif toClean.push_back(value); } array->length = length; @@ -324,11 +333,19 @@ public: if (length > 0) { keys = malloc(length * sizeof(K)); - memset(keys, 0, length * sizeof(K)); + #ifdef __STDC_LIB_EXT1__ + memset_s(keys, length * sizeof(K), 0, length * sizeof(K)); + #else + memset(keys, 0, length * sizeof(K)); + #endif toClean.push_back(keys); values = malloc(length * sizeof(V)); - memset(values, 0, length * sizeof(V)); + #ifdef __STDC_LIB_EXT1__ + memset_s(values, length * sizeof(V), 0, length * sizeof(V)); + #else + memset(values, 0, length * sizeof(V)); + #endif toClean.push_back(values); } map->size = length; @@ -397,7 +414,11 @@ public: check(4); #ifdef KOALA_NO_UNALIGNED_ACCESS InteropInt32 value; - memcpy(&value, data + position, 4); + #ifdef __STDC_LIB_EXT1__ + memcpy_s(&value, 4, data + position, 4); + #else + memcpy(&value, data + position, 4); + #endif #else auto value = *(InteropInt32 *)(data + position); #endif @@ -409,7 +430,11 @@ public: check(8); #ifdef KOALA_NO_UNALIGNED_ACCESS InteropInt64 value; - memcpy(&value, data + position, 4); + #ifdef __STDC_LIB_EXT1__ + memcpy_s(&value, 4, data + position, 4); + #else + memcpy(&value, data + position, 4); + #endif #else auto value = *(InteropInt64 *)(data + position); #endif @@ -421,7 +446,11 @@ public: check(8); #ifdef KOALA_NO_UNALIGNED_ACCESS InteropInt64 value; - memcpy(&value, data + position, 4); + #ifdef __STDC_LIB_EXT1__ + memcpy_s(&value, 4, data + position, 4); + #else + memcpy(&value, data + position, 4); + #endif #else auto value = *(InteropUInt64 *)(data + position); #endif @@ -433,7 +462,11 @@ public: check(4); #ifdef KOALA_NO_UNALIGNED_ACCESS InteropFloat32 value; - memcpy(&value, data + position, 4); + #ifdef __STDC_LIB_EXT1__ + memcpy_s(&value, 4, data + position, 4); + #else + memcpy(&value, data + position, 4); + #endif #else auto value = *(InteropFloat32 *)(data + position); #endif @@ -445,12 +478,16 @@ public: check(8); #ifdef KOALA_NO_UNALIGNED_ACCESS int64_t value = 0; - memcpy(&value, data + position, 8); + #ifdef __STDC_LIB_EXT1__ + memcpy_s(&value, 8, data + position, 8); + #else + memcpy(&value, data + position, 8); + #endif #else int64_t value = *(int64_t *)(data + position); #endif position += 8; - return reinterpret_cast(value); + return reinterpret_cast(static_cast(value)); } InteropNativePointer readPointerOrDefault(InteropNativePointer defaultValue) { @@ -578,7 +615,11 @@ inline void WriteToString(std::string *result, InteropFloat32 value) #if (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && (__MAC_OS_X_VERSION_MAX_ALLOWED < 130300L)) // to_chars() is not available on older macOS. char buf[20]; - snprintf(buf, sizeof buf, "%f", value); + #ifdef __STDC_LIB_EXT1__ + snprintf_s(buf, sizeof buf, "%f", value); + #else + snprintf(buf, sizeof buf, "%f", value); + #endif result->append(buf); #else std::string storage; diff --git a/koala-wrapper/koalaui/interop/src/cpp/SerializerBase.h b/koala-wrapper/koalaui/interop/src/cpp/SerializerBase.h index f99efca14..f28c46252 100644 --- a/koala-wrapper/koalaui/interop/src/cpp/SerializerBase.h +++ b/koala-wrapper/koalaui/interop/src/cpp/SerializerBase.h @@ -75,7 +75,11 @@ private: ASSERT(ownData); ASSERT(newLength > dataLength); auto* newData = reinterpret_cast(malloc(newLength)); - memcpy(newData, data, position); + #ifdef __STDC_LIB_EXT1__ + memcpy_s(newData, newLength, data, position); + #else + memcpy(newData, data, position); + #endif free(data); data = newData; } @@ -126,7 +130,11 @@ public: void writeInt32(InteropInt32 value) { check(4); #ifdef KOALA_NO_UNALIGNED_ACCESS - memcpy(data + position, &value, 4); + #ifdef __STDC_LIB_EXT1__ + memcpy_s(data + position, dataLength, &value, 4); + #else + memcpy(data + position, &value, 4); + #endif #else *((InteropInt32*)(data + position)) = value; #endif @@ -136,7 +144,11 @@ public: void writeInt64(InteropInt64 value) { check(8); #ifdef KOALA_NO_UNALIGNED_ACCESS - memcpy(data + position, &value, 8); + #ifdef __STDC_LIB_EXT1__ + memcpy_s(data + position, dataLength, &value, 8); + #else + memcpy(data + position, &value, 8); + #endif #else *((InteropInt64*)(data + position)) = value; #endif @@ -146,7 +158,11 @@ public: void writeUInt64(InteropUInt64 value) { check(8); #ifdef KOALA_NO_UNALIGNED_ACCESS - memcpy(data + position, &value, 8); + #ifdef __STDC_LIB_EXT1__ + memcpy_s(data + position, dataLength, &value, 8); + #else + memcpy(data + position, &value, 8); + #endif #else *((InteropUInt64*)(data + position)) = value; #endif @@ -156,7 +172,11 @@ public: void writeFloat32(InteropFloat32 value) { check(8); #ifdef KOALA_NO_UNALIGNED_ACCESS - memcpy(data + position, &value, 4); + #ifdef __STDC_LIB_EXT1__ + memcpy_s(data + position, dataLength, &value, 4); + #else + memcpy(data + position, &value, 4); + #endif #else *((InteropFloat32*)(data + position)) = value; #endif @@ -166,7 +186,11 @@ public: void writePointer(InteropNativePointer value) { check(8); #ifdef KOALA_NO_UNALIGNED_ACCESS - memcpy(data + position, &value, 8); + #ifdef __STDC_LIB_EXT1__ + memcpy_s(data + position, dataLength, &value64, 8); + #else + memcpy(data + position, &value, 8); + #endif #else *((int64_t*)(data + position)) = reinterpret_cast(value); #endif @@ -220,7 +244,11 @@ public: case 3: suffix = "%"; break; case 4: suffix = "lpx"; break; } - snprintf(buf, 64, "%.8f%s", value.value, suffix.c_str()); + #ifdef __STDC_LIB_EXT1__ + snprintf_s(buf, 64, "%.8f%s", value.value, suffix.c_str()); + #else + snprintf(buf, 64, "%.8f%s", value.value, suffix.c_str()); + #endif InteropString str = { buf, (InteropInt32) strlen(buf) }; writeString(str); break; diff --git a/koala-wrapper/koalaui/interop/src/cpp/ani/convertors-ani.cc b/koala-wrapper/koalaui/interop/src/cpp/ani/convertors-ani.cc index f41a2f5bf..cb9160ed0 100644 --- a/koala-wrapper/koalaui/interop/src/cpp/ani/convertors-ani.cc +++ b/koala-wrapper/koalaui/interop/src/cpp/ani/convertors-ani.cc @@ -40,7 +40,6 @@ static bool registerNatives(ani_env *env, const ani_class clazz, const std::vect ani_boolean isError = false; env->ExistUnhandledError(&isError); if (isError) { - //env->ErrorDescribe(); env->ResetError(); } } @@ -73,26 +72,6 @@ bool registerAllModules(ani_env *env) { return true; } -#if 0 -extern "C" ETS_EXPORT ets_int ETS_CALL EtsNapiOnLoad(ets_env *env) { - if (!registerAllModules(env)) { - LOGE("Failed to register ets modules"); - return ETS_ERR; - } - auto interopClasspath = AniExports::getInstance()->getClasspath("InteropNativeModule"); - auto interopClass = env->FindClass(interopClasspath.c_str()); - if (interopClass == nullptr) { - LOGE("Can not find InteropNativeModule classpath to set callback dispatcher"); - return ETS_ERR; - } - if (!setKoalaEtsNapiCallbackDispatcher(env, interopClass, callCallbackFromNative, callCallbackFromNativeSig)) { - LOGE("Failed to set koala ets callback dispatcher"); - return ETS_ERR; - } - return ETS_NAPI_VERSION_1_0; -} -#endif - AniExports* AniExports::getInstance() { static AniExports *instance = nullptr; if (instance == nullptr) { diff --git a/koala-wrapper/koalaui/interop/src/cpp/ani/convertors-ani.h b/koala-wrapper/koalaui/interop/src/cpp/ani/convertors-ani.h index 3be74d311..c3b678273 100644 --- a/koala-wrapper/koalaui/interop/src/cpp/ani/convertors-ani.h +++ b/koala-wrapper/koalaui/interop/src/cpp/ani/convertors-ani.h @@ -16,7 +16,6 @@ #ifndef KOALA_ANI #define KOALA_ANI -#include #include #include #include @@ -1319,60 +1318,11 @@ bool setKoalaEtsNapiCallbackDispatcher( ); void getKoalaEtsNapiCallbackDispatcher(ani_class* clazz, ani_method* method); -#if 0 -#define KOALA_INTEROP_CALL_VOID(venv, id, length, args) \ -{ \ - ani_class clazz = nullptr; \ - ani_method method = nullptr; \ - getKoalaEtsNapiCallbackDispatcher(&clazz, &method); \ - ani_env* ani_env = reinterpret_cast(vmContext); \ - ani_env->PushLocalFrame(1); \ - ani_fixedarray_byte args_ets = ani_env->NewByteArray(length); \ - ani_env->SetByteArrayRegion(args_ets, 0, length, reinterpret_cast(args)); \ - ani_env->CallStaticIntMethod(clazz, method, id, args_ets, length); \ - ani_env->GetByteArrayRegion(args_ets, 0, length, reinterpret_cast(args)); \ - ani_env->PopLocalFrame(nullptr); \ -} - -#define KOALA_INTEROP_CALL_INT(venv, id, length, args) \ -{ \ - ani_class clazz = nullptr; \ - ani_method method = nullptr; \ - getKoalaEtsNapiCallbackDispatcher(&clazz, &method); \ - ani_env* ani_env = reinterpret_cast(venv); \ - ani_env->PushLocalFrame(1); \ - ani_fixedarray_byte args_ets = ani_env->NewByteArray(length); \ - ani_env->SetByteArrayRegion(args_ets, 0, length, reinterpret_cast(args)); \ - int32_t rv = ani_env->CallStaticIntMethod(clazz, method, id, args_ets, length); \ - ani_env->GetByteArrayRegion(args_ets, 0, length, reinterpret_cast(args)); \ - ani_env->PopLocalFrame(nullptr); \ - return rv; \ -} - -#define KOALA_INTEROP_CALL_VOID_INTS32(venv, id, argc, args) KOALA_INTEROP_CALL_VOID(venv, id, (argc) * sizeof(int32_t), args) -#define KOALA_INTEROP_CALL_INT_INTS32(venv, id, argc, args) KOALA_INTEROP_CALL_INT(venv, id, (argc) * sizeof(int32_t), args) - -#define KOALA_INTEROP_THROW(vmContext, object, ...) \ - do { \ - ani_env* env = reinterpret_cast(vmContext); \ - env->ThrowError(object); \ - return __VA_ARGS__; \ - } while (0) - -#define KOALA_INTEROP_THROW_STRING(vmContext, message, ...) \ - do { \ - ani_env* env = reinterpret_cast(vmContext); \ - const static ani_class errorClass = env->FindClass("std/core/Error"); \ - env->ThrowErrorNew(errorClass, message); \ - } while (0) -#else - #define KOALA_INTEROP_CALL_VOID(venv, id, length, args) #define KOALA_INTEROP_CALL_INT(venv, id, length, args) { return 0; } #define KOALA_INTEROP_CALL_VOID_INTS32(venv, id, argc, args) { return; } #define KOALA_INTEROP_CALL_INT_INTS32(venv, id, argc, args) { return 0; } #define KOALA_INTEROP_THROW(vmContext, object, ...) { return __VA_ARGS__; } #define KOALA_INTEROP_THROW_STRING(vmContext, message, ...) { return __VA_ARGS__; } -#endif #endif // KOALA_ETS_NAPI diff --git a/koala-wrapper/koalaui/interop/src/cpp/callback-resource.cc b/koala-wrapper/koalaui/interop/src/cpp/callback-resource.cc index d7851e405..f10eacf58 100644 --- a/koala-wrapper/koalaui/interop/src/cpp/callback-resource.cc +++ b/koala-wrapper/koalaui/interop/src/cpp/callback-resource.cc @@ -41,7 +41,8 @@ void releaseManagedCallbackResource(InteropInt32 resourceId) { callbackResourceSubqueue.push_back(resourceId); } -KInt impl_CheckCallbackEvent(KByte* result, KInt size) { +KInt impl_CheckCallbackEvent(KByte* buffer, KInt size) { + KByte* result = (KByte*)buffer; if (needReleaseFront) { switch (callbackEventsQueue.front()) @@ -64,16 +65,29 @@ KInt impl_CheckCallbackEvent(KByte* result, KInt size) { return 0; } const CallbackEventKind frontEventKind = callbackEventsQueue.front(); - memcpy(result, &frontEventKind, 4); + #ifdef __STDC_LIB_EXT1__ + memcpy_s(result, size, &frontEventKind, 4); + #else + memcpy(result, &frontEventKind, 4); + #endif + switch (frontEventKind) { case Event_CallCallback: - memcpy(result + 4, callbackCallSubqueue.front().buffer, sizeof(CallbackBuffer::buffer)); + #ifdef __STDC_LIB_EXT1__ + memcpy_s(result + 4, size, callbackCallSubqueue.front().buffer, sizeof(CallbackBuffer::buffer)); + #else + memcpy(result + 4, callbackCallSubqueue.front().buffer, sizeof(CallbackBuffer::buffer)); + #endif break; case Event_HoldManagedResource: case Event_ReleaseManagedResource: { const InteropInt32 resourceId = callbackResourceSubqueue.front(); - memcpy(result + 4, &resourceId, 4); + #ifdef __STDC_LIB_EXT1__ + memcpy_s(result + 4, size, &frontEventKind, 4); + #else + memcpy(result + 4, &resourceId, 4); + #endif break; } default: diff --git a/koala-wrapper/koalaui/interop/src/cpp/cangjie/convertors-cj.h b/koala-wrapper/koalaui/interop/src/cpp/cangjie/convertors-cj.h index 17949006b..e3fbc8a20 100644 --- a/koala-wrapper/koalaui/interop/src/cpp/cangjie/convertors-cj.h +++ b/koala-wrapper/koalaui/interop/src/cpp/cangjie/convertors-cj.h @@ -13,15 +13,16 @@ * limitations under the License. */ -#pragma once +#ifndef CONVERTORS_CJ_H +#define CONVERTORS_CJ_H #include -#include #include #include #include #include "koala-types.h" +#include "interop-logging.h" #define KOALA_INTEROP_EXPORT extern "C" @@ -864,12 +865,14 @@ KOALA_INTEROP_EXPORT void name(InteropTypeConverter::InteropType _p0, \ #define KOALA_INTEROP_THROW(vmContext, object, ...) \ do { \ - /* TODO: implement*/ assert(false); \ + /* TODO: implement*/ ASSERT(false); \ return __VA_ARGS__; \ } while (0) #define KOALA_INTEROP_THROW_STRING(vmContext, message, ...) \ do { \ - /* TODO: implement*/ assert(false); \ + /* TODO: implement*/ ASSERT(false); \ return __VA_ARGS__; \ } while (0) + +#endif // CONVERTORS_CJ_H \ No newline at end of file diff --git a/koala-wrapper/koalaui/interop/src/cpp/common-interop.cc b/koala-wrapper/koalaui/interop/src/cpp/common-interop.cc index ec6572c6d..5d4d5b43e 100644 --- a/koala-wrapper/koalaui/interop/src/cpp/common-interop.cc +++ b/koala-wrapper/koalaui/interop/src/cpp/common-interop.cc @@ -127,7 +127,13 @@ KOALA_INTEROP_1(StringLength, KInt, KNativePointer) void impl_StringData(KNativePointer ptr, KByte* bytes, KUInt size) { string* s = reinterpret_cast(ptr); - if (s) memcpy(bytes, s->c_str(), size); + if (s) { + #ifdef __STDC_LIB_EXT1__ + memcpy_s(bytes, size, s->c_str(), size); + #else + memcpy(bytes, s->c_str(), size); + #endif + } } KOALA_INTEROP_V3(StringData, KNativePointer, KByte*, KUInt) @@ -149,7 +155,11 @@ KOALA_INTEROP_1(StringMake, KNativePointer, KStringPtr) // For slow runtimes w/o fast encoders. KInt impl_ManagedStringWrite(const KStringPtr& string, KByte* buffer, KInt offset) { - memcpy(buffer + offset, string.c_str(), string.length() + 1); + #ifdef __STDC_LIB_EXT1__ + memcpy_s(buffer + offset, string.length() + 1, string.c_str(), string.length() + 1); + #else + memcpy(buffer + offset, string.c_str(), string.length() + 1); + #endif return string.length() + 1; } KOALA_INTEROP_3(ManagedStringWrite, KInt, KStringPtr, KByte*, KInt) @@ -373,8 +383,7 @@ KInt impl_CallForeignVM(KNativePointer foreignContextRaw, KInt function, KByte* KOALA_INTEROP_4(CallForeignVM, KInt, KNativePointer, KInt, KByte*, KInt) -#define __QUOTE(x) #x -#define QUOTE(x) __QUOTE(x) +#define QUOTE(x) #x void impl_NativeLog(const KStringPtr& str) { #ifdef KOALA_OHOS @@ -461,7 +470,11 @@ KOALA_INTEROP_CTX_1(StdStringToString, KStringPtr, KNativePointer) #if defined(KOALA_JNI) || defined(KOALA_NAPI) || defined(KOALA_CJ) KInteropReturnBuffer impl_RawReturnData(KVMContext vmContext, KInt v1, KInt v2) { void* data = new int8_t[v1]; - memset(data, v2, v1); + #ifdef __STDC_LIB_EXT1__ + memset_s(data, v1, v2, v1); + #else + memset(data, v2, v1); + #endif KInteropReturnBuffer buffer = { v1, data, [](KNativePointer ptr, KInt) { delete[] (int8_t*)ptr; }}; return buffer; } diff --git a/koala-wrapper/koalaui/interop/src/cpp/ets/convertors-ets.cc b/koala-wrapper/koalaui/interop/src/cpp/ets/convertors-ets.cc index 450804338..103c8c7de 100644 --- a/koala-wrapper/koalaui/interop/src/cpp/ets/convertors-ets.cc +++ b/koala-wrapper/koalaui/interop/src/cpp/ets/convertors-ets.cc @@ -38,7 +38,6 @@ static bool registerNatives(ets_env *env, const ets_class clazz, const std::vect if (registerByOne) { result &= env->RegisterNatives(clazz, &method, 1) >= 0; if (env->ErrorCheck()) { - //env->ErrorDescribe(); env->ErrorClear(); } } @@ -131,7 +130,6 @@ void EtsExports::setClasspath(const char* module, const char *classpath) { static std::map g_defaultClasspaths = { {"InteropNativeModule", "@koalaui/interop/InteropNativeModule/InteropNativeModule"}, - // todo leave just InteropNativeModule, define others via KOALA_ETS_INTEROP_MODULE_CLASSPATH {"TestNativeModule", "@koalaui/arkts-arkui/generated/arkts/TestNativeModule/TestNativeModule"}, {"ArkUINativeModule", "@koalaui/arkts-arkui/generated/arkts/ArkUINativeModule/ArkUINativeModule"}, {"ArkUIGeneratedNativeModule", "@koalaui/arkts-arkui/generated/arkts/ArkUIGeneratedNativeModule/ArkUIGeneratedNativeModule"}, diff --git a/koala-wrapper/koalaui/interop/src/cpp/ets/convertors-ets.h b/koala-wrapper/koalaui/interop/src/cpp/ets/convertors-ets.h index c03b5af27..b81fc1c81 100644 --- a/koala-wrapper/koalaui/interop/src/cpp/ets/convertors-ets.h +++ b/koala-wrapper/koalaui/interop/src/cpp/ets/convertors-ets.h @@ -13,11 +13,11 @@ * limitations under the License. */ -#pragma once +#ifndef CONVERTORS_ETS_H +#define CONVERTORS_ETS_H #ifdef KOALA_ETS_NAPI -#include #include #include #include @@ -1347,3 +1347,5 @@ void getKoalaEtsNapiCallbackDispatcher(ets_class* clazz, ets_method* method); } while (0) #endif // KOALA_ETS_NAPI + +#endif // CONVERTORS_ETS_H \ No newline at end of file diff --git a/koala-wrapper/koalaui/interop/src/cpp/interop-logging.cc b/koala-wrapper/koalaui/interop/src/cpp/interop-logging.cc index 073878547..b99493ff6 100644 --- a/koala-wrapper/koalaui/interop/src/cpp/interop-logging.cc +++ b/koala-wrapper/koalaui/interop/src/cpp/interop-logging.cc @@ -14,6 +14,7 @@ */ #include #include +#include #include "interop-logging.h" @@ -27,7 +28,7 @@ struct Log { std::vector groupedLogs; void startGroupedLog(int index) { - if (index >= (int)groupedLogs.size()) { + if (index >= static_cast(groupedLogs.size())) { groupedLogs.resize(index + 1); for (int i = 0; i <= index; i++) { if (!groupedLogs[i]) groupedLogs[i] = new Log(); @@ -38,27 +39,27 @@ void startGroupedLog(int index) { } void stopGroupedLog(int index) { - if (index < (int)groupedLogs.size()) { + if (index < static_cast(groupedLogs.size())) { groupedLogs[index]->isActive = false; } } void appendGroupedLog(int index, const char* str) { - if (index < (int)groupedLogs.size()) { + if (index < static_cast(groupedLogs.size())) { groupedLogs[index]->log.append(str); } } const char* getGroupedLog(int index) { - if (index < (int)groupedLogs.size()) { - auto result = groupedLogs[index]->log.c_str(); + if (index < static_cast(groupedLogs.size())) { + const char* result = groupedLogs[index]->log.c_str(); return result; } return ""; } int needGroupedLog(int index) { - if (index < (int)groupedLogs.size()) { + if (index < static_cast(groupedLogs.size())) { return groupedLogs[index]->isActive; } return 0; diff --git a/koala-wrapper/koalaui/interop/src/cpp/interop-types.h b/koala-wrapper/koalaui/interop/src/cpp/interop-types.h index 4c5c26187..1daaaa80a 100644 --- a/koala-wrapper/koalaui/interop/src/cpp/interop-types.h +++ b/koala-wrapper/koalaui/interop/src/cpp/interop-types.h @@ -16,7 +16,11 @@ #ifndef _INTEROP_TYPES_H_ #define _INTEROP_TYPES_H_ -#include +#ifdef __cplusplus + #include +#else + #include +#endif #define INTEROP_FATAL(msg, ...) do { fprintf(stderr, msg "\n", ##__VA_ARGS__); abort(); } while (0) diff --git a/koala-wrapper/koalaui/interop/src/cpp/jni/convertors-jni.h b/koala-wrapper/koalaui/interop/src/cpp/jni/convertors-jni.h index 2ebefafe7..063a86a56 100644 --- a/koala-wrapper/koalaui/interop/src/cpp/jni/convertors-jni.h +++ b/koala-wrapper/koalaui/interop/src/cpp/jni/convertors-jni.h @@ -13,12 +13,12 @@ * limitations under the License. */ -#pragma once +#ifndef CONVERTORS_JNI_H +#define CONVERTORS_JNI_H #ifdef KOALA_JNI #include -#include #include #include @@ -145,9 +145,14 @@ struct SlowInteropTypeConverter { return result; } static InteropType convertTo(JNIEnv* env, KInteropBuffer value) { - jarray result = env->NewByteArray(value.length); + int bufferLength = value.length; + jarray result = env->NewByteArray(bufferLength); void* data = env->GetPrimitiveArrayCritical(result, nullptr); - memcpy(data, value.data, value.length); + #ifdef __STDC_LIB_EXT1__ + memcpy_s(data, bufferLength, value.data, bufferLength); + #else + memcpy(data, value.data, bufferLength); + #endif env->ReleasePrimitiveArrayCritical(result, data, 0); return result; } @@ -161,11 +166,16 @@ struct SlowInteropTypeConverter { using InteropType = jarray; static inline KInteropReturnBuffer convertFrom(JNIEnv* env, InteropType value) = delete; static InteropType convertTo(JNIEnv* env, KInteropReturnBuffer value) { - jarray result = env->NewByteArray(value.length); + int bufferLength = value.length; + jarray result = env->NewByteArray(bufferLength); void* data = env->GetPrimitiveArrayCritical(result, nullptr); - memcpy(data, value.data, value.length); + #ifdef __STDC_LIB_EXT1__ + memcpy_s(data, bufferLength, value.data, bufferLength); + #else + memcpy(data, value.data, bufferLength); + #endif env->ReleasePrimitiveArrayCritical(result, data, 0); - value.dispose(value.data, value.length); + value.dispose(value.data, bufferLength); return result; } static inline void release(JNIEnv* env, InteropType value, const KInteropReturnBuffer& converted) = delete; @@ -1463,3 +1473,5 @@ void getKoalaJniCallbackDispatcher(jclass* clazz, jmethodID* method); } while (0) #endif // KOALA_JNI_CALL + +#endif // CONVERTORS_JNI_H \ No newline at end of file diff --git a/koala-wrapper/koalaui/interop/src/cpp/jsc/convertors-jsc.cc b/koala-wrapper/koalaui/interop/src/cpp/jsc/convertors-jsc.cc index 1ae964f27..246a1fd1c 100644 --- a/koala-wrapper/koalaui/interop/src/cpp/jsc/convertors-jsc.cc +++ b/koala-wrapper/koalaui/interop/src/cpp/jsc/convertors-jsc.cc @@ -146,7 +146,11 @@ static JSValueRef u64ToBigInt(JSContextRef context, uint64_t value) { bigint = JSObjectCallAsFunction(context, bigIntFromParts, nullptr, 2, parts, nullptr); #else char buffer[128] = {0}; - std::snprintf(buffer, sizeof(buffer) - 1, "%zun", (size_t) value); + #ifdef __STDC_LIB_EXT1__ + std::snprintf_s(buffer, sizeof(buffer) - 1, "%zun", static_cast(value)); + #else + std::snprintf(buffer, sizeof(buffer) - 1, "%zun", static_cast(value)); + #endif JSStringRef script = JSStringCreateWithUTF8CString(buffer); bigint = JSEvaluateScript(context, script, nullptr, nullptr, 0, nullptr); JSStringRelease(script); diff --git a/koala-wrapper/koalaui/interop/src/cpp/napi/convertors-napi.h b/koala-wrapper/koalaui/interop/src/cpp/napi/convertors-napi.h index 720d423f1..2446ec3a8 100644 --- a/koala-wrapper/koalaui/interop/src/cpp/napi/convertors-napi.h +++ b/koala-wrapper/koalaui/interop/src/cpp/napi/convertors-napi.h @@ -31,7 +31,6 @@ #include "koala-types.h" #include "interop-types.h" -// TODO: switch to more generic convertors eventually. template struct InteropTypeConverter { using InteropType = T; @@ -88,9 +87,6 @@ struct InteropTypeConverter { (void*)copy, &result ); - if (status != napi_ok) { - // do smth here - } return result; }; static void release(napi_env env, InteropType value, KInteropBuffer converted) {} @@ -241,7 +237,6 @@ public: } private: napi_env _env; - // napi_callback_info _info; std::vector args; }; @@ -513,11 +508,6 @@ inline KNativePointerArray getArgument(const CallbackInfo& return getPointerElements(info, index); } -// template <> -// inline napi_value getArgument(const CallbackInfo& info, int index) { -// return getObject(info, index); -// } - template <> inline uint8_t* getArgument(const CallbackInfo& info, int index) { return getUInt8Elements(info, index); @@ -573,7 +563,6 @@ napi_value makeUInt64(napi_env env, uint32_t value); napi_value makeFloat32(napi_env env, float value); napi_value makePointer(napi_env env, void* value); napi_value makeVoid(napi_env env); -// napi_value makeObject(napi_env env, napi_value object); inline napi_value makeVoid(const CallbackInfo& info) { return makeVoid(info.Env()); @@ -656,8 +645,7 @@ public: const std::vector>& getMethods(const std::string& module); }; -#define __QUOTE(x) #x -#define QUOTE(x) __QUOTE(x) +#define QUOTE(x) #x #ifdef _MSC_VER #define MAKE_NODE_EXPORT(module, name) \ diff --git a/koala-wrapper/koalaui/interop/src/cpp/napi/win-dynamic-node.cc b/koala-wrapper/koalaui/interop/src/cpp/napi/win-dynamic-node.cc index 6ec8fcc34..ac0355338 100644 --- a/koala-wrapper/koalaui/interop/src/cpp/napi/win-dynamic-node.cc +++ b/koala-wrapper/koalaui/interop/src/cpp/napi/win-dynamic-node.cc @@ -12,8 +12,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include -#include + +#ifdef __cplusplus + #include + #include +#else + #include + #include +#endif + #include #include "node_api.h" diff --git a/koala-wrapper/koalaui/interop/src/cpp/ohos/hilog/log.h b/koala-wrapper/koalaui/interop/src/cpp/ohos/hilog/log.h index 7452137c2..174564bce 100644 --- a/koala-wrapper/koalaui/interop/src/cpp/ohos/hilog/log.h +++ b/koala-wrapper/koalaui/interop/src/cpp/ohos/hilog/log.h @@ -58,8 +58,13 @@ * * @since 8 */ -#include -#include + +#ifdef __cplusplus + #include +#else + #include + #include +#endif #ifdef __cplusplus extern "C" { diff --git a/koala-wrapper/koalaui/interop/src/cpp/ohos/oh_sk_log.cc b/koala-wrapper/koalaui/interop/src/cpp/ohos/oh_sk_log.cc index 6aa01fe5e..0d30f1b58 100644 --- a/koala-wrapper/koalaui/interop/src/cpp/ohos/oh_sk_log.cc +++ b/koala-wrapper/koalaui/interop/src/cpp/ohos/oh_sk_log.cc @@ -24,9 +24,13 @@ static const char* KOALAUI_OHOS_LOG_ROOT = "/data/storage/el2/base/files/logs"; -#define APPLY_LOG_FILE_PATTERN(buf, t, ms, pid) \ - sprintf(buf, "%s/%d_%d_%d_%ld.pid%d.log", \ - KOALAUI_OHOS_LOG_ROOT, t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, ms.tv_sec, pid) +#define APPLY_LOG_FILE_PATTERN(buf, bufLen, t, ms, pid) \ + #ifdef __STDC_LIB_EXT1__ \ + sprintf_s(buf, bufLen, "%s/%d_%d_%d_%lld.pid%d.log", \ + #else \ + sprintf(buf, "%s/%d_%d_%d_%lld.pid%d.log", \ + #endif \ + KOALAUI_OHOS_LOG_ROOT, (t).tm_year + 1900, (t).tm_mon + 1, (t).tm_mday, (ms).tv_sec, pid) const char* oh_sk_log_type_str(oh_sk_log_type type) { switch (type) { @@ -46,15 +50,16 @@ void oh_sk_file_log(oh_sk_log_type type, const char* msg, ...) { static char* path = nullptr; if (!path) { - path = new char[strlen(KOALAUI_OHOS_LOG_ROOT) + 100]; - APPLY_LOG_FILE_PATTERN(path, lt, ms, getpid()); + size_t len = strlen(KOALAUI_OHOS_LOG_ROOT) + 100; + path = new char[len]; + APPLY_LOG_FILE_PATTERN(path, len, lt, ms, getpid()); mkdir(KOALAUI_OHOS_LOG_ROOT, 0777); } std::unique_ptr file(fopen(path, "a"), fclose); if (!file) return; - fprintf(file.get(), "%02d-%02d %02d:%02d:%02d.%03ld %s koala: ", + fprintf(file.get(), "%02d-%02d %02d:%02d:%02d.%03lld %s koala: ", lt.tm_mon + 1, lt.tm_mday, lt.tm_hour, lt.tm_min, lt.tm_sec, ms.tv_usec / 1000, oh_sk_log_type_str(type)); diff --git a/koala-wrapper/koalaui/interop/src/cpp/ohos/oh_sk_log.h b/koala-wrapper/koalaui/interop/src/cpp/ohos/oh_sk_log.h index 961e2c0f1..6544a2e2e 100644 --- a/koala-wrapper/koalaui/interop/src/cpp/ohos/oh_sk_log.h +++ b/koala-wrapper/koalaui/interop/src/cpp/ohos/oh_sk_log.h @@ -13,7 +13,8 @@ * limitations under the License. */ -#pragma once +#ifndef OH_SK_LOG_H +#define OH_SK_LOG_H #include @@ -55,3 +56,5 @@ const char* oh_sk_log_type_str(oh_sk_log_type type); #define OH_SK_LOG_FATAL_A(msg, ...) OH_LOG_Print(LOG_APP, LOG_FATAL, 0xFF00, "Koala", msg, ##__VA_ARGS__) #endif + +#endif // OH_SK_LOG_H \ No newline at end of file diff --git a/koala-wrapper/koalaui/interop/src/cpp/profiler.h b/koala-wrapper/koalaui/interop/src/cpp/profiler.h index a3b9da38c..cdfe518d9 100644 --- a/koala-wrapper/koalaui/interop/src/cpp/profiler.h +++ b/koala-wrapper/koalaui/interop/src/cpp/profiler.h @@ -68,7 +68,11 @@ class InteropProfiler { auto ns = a.second.time; auto count = a.second.count; char buffer[1024]; - snprintf(buffer, sizeof buffer, "for %s[%lld]: %.01f%% (%lld)\n", a.first.c_str(), (long long)count, (double)ns / total * 100.0, (long long)ns); + #ifdef __STDC_LIB_EXT1__ + snprintf_s(buffer, sizeof buffer, "for %s[%lld]: %.01f%% (%lld)\n", a.first.c_str(), (long long)count, (double)ns / total * 100.0, (long long)ns); + #else + snprintf(buffer, sizeof buffer, "for %s[%lld]: %.01f%% (%lld)\n", a.first.c_str(), (long long)count, (double)ns / total * 100.0, (long long)ns); + #endif result += buffer; }); return result; diff --git a/koala-wrapper/koalaui/interop/src/cpp/types/koala-types.h b/koala-wrapper/koalaui/interop/src/cpp/types/koala-types.h index 2c5e88754..f5d684146 100644 --- a/koala-wrapper/koalaui/interop/src/cpp/types/koala-types.h +++ b/koala-wrapper/koalaui/interop/src/cpp/types/koala-types.h @@ -66,7 +66,11 @@ struct KStringPtrImpl { if (data) { if (_owned) { _value = reinterpret_cast(malloc(len + 1)); - memcpy(_value, data, len); + #ifdef __STDC_LIB_EXT1__ + memcpy_s(_value, len, data, len); + #else + memcpy(_value, data, len); + #endif _value[len] = 0; } else { _value = const_cast(data); @@ -100,7 +104,7 @@ struct KInteropNumber { // TODO: boundary check if (value == std::floor(value)) { result.tag = 102; // ARK_TAG_INT32 - result.i32 = (int)value; + result.i32 = static_cast(value); } else { result.tag = 103; // ARK_TAG_FLOAT32 result.f32 = (float)value; diff --git a/koala-wrapper/koalaui/interop/src/cpp/types/signatures.cc b/koala-wrapper/koalaui/interop/src/cpp/types/signatures.cc index 7f556adaf..6c4d12e62 100644 --- a/koala-wrapper/koalaui/interop/src/cpp/types/signatures.cc +++ b/koala-wrapper/koalaui/interop/src/cpp/types/signatures.cc @@ -13,8 +13,14 @@ * limitations under the License. */ -#include "stdio.h" -#include +#ifdef __cplusplus + #include + #include +#else + #include + #include +#endif + #include #include "signatures.h" @@ -22,15 +28,15 @@ // For types with the same name on ets and jni #define KOALA_INTEROP_TYPEDEF(func, lang, CPP_TYPE, SIG_TYPE, CODE_TYPE) \ - if (std::strcmp(func, "sigType") == 0) if (type == CPP_TYPE) return SIG_TYPE; \ - if (std::strcmp(func, "codeType") == 0) if (type == CPP_TYPE) return CODE_TYPE; + if (std::strcmp(func, "sigType") == 0) if (type == (CPP_TYPE)) return SIG_TYPE; \ + if (std::strcmp(func, "codeType") == 0) if (type == (CPP_TYPE)) return CODE_TYPE; // For types with distinct names on ets and jni #define KOALA_INTEROP_TYPEDEF_LS(func, lang, CPP_TYPE, ETS_SIG_TYPE, ETS_CODE_TYPE, JNI_SIG_TYPE, JNI_CODE_TYPE) \ - if (std::strcmp(func, "sigType") == 0 && std::strcmp(lang, "ets") == 0) if (type == CPP_TYPE) return ETS_SIG_TYPE; \ - if (std::strcmp(func, "codeType") == 0 && std::strcmp(lang, "ets") == 0) if (type == CPP_TYPE) return ETS_CODE_TYPE; \ - if (std::strcmp(func, "sigType") == 0 && std::strcmp(lang, "jni") == 0) if (type == CPP_TYPE) return JNI_SIG_TYPE; \ - if (std::strcmp(func, "codeType") == 0 && std::strcmp(lang, "jni") == 0) if (type == CPP_TYPE) return JNI_CODE_TYPE; + if (std::strcmp(func, "sigType") == 0 && std::strcmp(lang, "ets") == 0) if (type == (CPP_TYPE)) return ETS_SIG_TYPE; \ + if (std::strcmp(func, "codeType") == 0 && std::strcmp(lang, "ets") == 0) if (type == (CPP_TYPE)) return ETS_CODE_TYPE; \ + if (std::strcmp(func, "sigType") == 0 && std::strcmp(lang, "jni") == 0) if (type == (CPP_TYPE)) return JNI_SIG_TYPE; \ + if (std::strcmp(func, "codeType") == 0 && std::strcmp(lang, "jni") == 0) if (type == (CPP_TYPE)) return JNI_CODE_TYPE; #define KOALA_INTEROP_TYPEDEFS(func, lang) \ KOALA_INTEROP_TYPEDEF(func, lang, "void", "V", "void") \ @@ -107,7 +113,7 @@ std::string convertType(const char* name, const char* koalaType) { #if KOALA_USE_PANDA_VM - for (int i = 1; i < (int)tokens.size(); i++) + for (int i = 1; i < static_cast(tokens.size()); i++) { result.append(sigType(tokens[i])); } @@ -117,7 +123,7 @@ std::string convertType(const char* name, const char* koalaType) { #elif KOALA_USE_JAVA_VM result.append("("); - for (int i = 1; i < (int)tokens.size(); i++) + for (int i = 1; i < static_cast(tokens.size()); i++) { result.append(sigType(tokens[i])); } @@ -129,24 +135,24 @@ std::string convertType(const char* name, const char* koalaType) { #ifdef KOALA_BUILD_FOR_SIGNATURES #ifdef KOALA_USE_PANDA_VM std::string params; - for (int i = 1; i < (int)tokens.size(); i++) + for (int i = 1; i < static_cast(tokens.size()); i++) { params.append("arg"); params.append(std::to_string(i)); params.append(": "); params.append(codeType(tokens[i])); - if (i < (int)(tokens.size() - 1)) + if (i < static_cast(tokens.size() - 1)) params.append(", "); } fprintf(stderr, " static native %s(%s): %s;\n", name, params.c_str(), codeType(tokens[0]).c_str()); #elif KOALA_USE_JAVA_VM std::string params; - for (int i = 1; i < (int)tokens.size(); i++) + for (int i = 1; i < static_cast(tokens.size()); i++) { params.append(codeType(tokens[i])); params.append(" arg"); params.append(std::to_string(i)); - if (i < (int)(tokens.size() - 1)) + if (i < static_cast(tokens.size() - 1)) params.append(", "); } fprintf(stderr, " public static native %s %s(%s);\n", codeType(tokens[0]).c_str(), name, params.c_str()); diff --git a/koala-wrapper/koalaui/interop/src/cpp/vmloader.cc b/koala-wrapper/koalaui/interop/src/cpp/vmloader.cc index 995d2623c..c2f5a08f9 100644 --- a/koala-wrapper/koalaui/interop/src/cpp/vmloader.cc +++ b/koala-wrapper/koalaui/interop/src/cpp/vmloader.cc @@ -259,7 +259,6 @@ extern "C" DLL_EXPORT KInt LoadVirtualMachine(KInt vmKind, const char* appClassP etsVMOptions.push_back({EtsOptionType::ETS_NO_JIT, nullptr}); etsVMOptions.push_back({EtsOptionType::ETS_MOBILE_LOG, (void*)ArkMobileLog}); etsVMOptions.push_back({EtsOptionType::ETS_AOT, nullptr}); - // etsVMOptions.push_back({EtsOptionType::ETS_LOG_LEVEL, "info"}); pandaVMArgs.nOptions = etsVMOptions.size(); pandaVMArgs.options = etsVMOptions.data(); g_vmEntry.vmKind = PANDA_VM_KIND; diff --git a/koala-wrapper/koalaui/interop/src/interop/java/CallbackRegistry.java b/koala-wrapper/koalaui/interop/src/interop/java/CallbackRegistry.java index 59dceae85..b246d133b 100644 --- a/koala-wrapper/koalaui/interop/src/interop/java/CallbackRegistry.java +++ b/koala-wrapper/koalaui/interop/src/interop/java/CallbackRegistry.java @@ -40,15 +40,15 @@ class CallbackRegistry { } public static Integer wrap(CallbackType callback) { - Integer id = CallbackRegistry.id++; - CallbackRegistry.callbacks.put(id, new CallbackRecord(callback, true)); - return id; + Integer tmpId = CallbackRegistry.id++; + CallbackRegistry.callbacks.put(tmpId, new CallbackRecord(callback, true)); + return tmpId; } public static Integer wrap(CallbackType callback, boolean autoDisposable) { - Integer id = CallbackRegistry.id++; - CallbackRegistry.callbacks.put(id, new CallbackRecord(callback, autoDisposable)); - return id; + Integer tmpId = CallbackRegistry.id++; + CallbackRegistry.callbacks.put(tmpId, new CallbackRecord(callback, autoDisposable)); + return tmpId; } public static int call(Integer id, byte[] args, int length) { -- Gitee