From 4ed4544ce0826287547fcbfaac8a030282644420 Mon Sep 17 00:00:00 2001 From: kolegovilya Date: Wed, 18 Dec 2024 17:38:21 +0300 Subject: [PATCH] stubs --- interop/src/cpp/common-interop.cc | 19 +++++++++++++++++++ interop/src/cpp/ets/convertors-ets.h | 15 +++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/interop/src/cpp/common-interop.cc b/interop/src/cpp/common-interop.cc index 8b99dd78d..5b5e2ca58 100644 --- a/interop/src/cpp/common-interop.cc +++ b/interop/src/cpp/common-interop.cc @@ -109,6 +109,25 @@ void getKoalaEtsNapiCallbackDispatcher(ets_class* clazz, ets_method* method) { } #endif +#ifdef KOALA_USE_PANDA_VM +// TODO: +// Function with memory leak +// Very sorry :( +// Stub until +// + NewDirectByteBuffer +// + GetDirectBufferAddress +// + GetDirectBufferCapacity +// are available +// +// Do NOT use it! +KNativePointer impl_GetNativeBufferPointer(KVMContext vmContext, KInteropBuffer buffer) { + KByte* result = new KByte[buffer.length]; + memcpy(result, (KByte*)buffer.data, buffer.length); + return result; +} +KOALA_INTEROP_CTX_1(GetNativeBufferPointer, KNativePointer, KInteropBuffer) +#endif + #ifdef KOALA_JNI #include "jni.h" static struct { diff --git a/interop/src/cpp/ets/convertors-ets.h b/interop/src/cpp/ets/convertors-ets.h index c7ac99931..ab5a6fc95 100644 --- a/interop/src/cpp/ets/convertors-ets.h +++ b/interop/src/cpp/ets/convertors-ets.h @@ -102,6 +102,21 @@ struct InteropTypeConverter { } }; +template<> +struct InteropTypeConverter { + using InteropType = ets_byteArray; + static KInteropBuffer convertFrom(EtsEnv* env, InteropType value) { + return KInteropBuffer { + (int32_t)env->GetArrayLength(value), + (void*)env->PinByteArray(value) + }; + } + static InteropType convertTo(EtsEnv* env, KInteropBuffer value) = delete; + static void release(EtsEnv* env, InteropType value, KInteropBuffer converted) { + if (value) env->UnpinByteArray((ets_byteArray)value); + } +}; + template <> struct InteropTypeConverter { using InteropType = ets_double; static KInteropNumber convertFrom(EtsEnv *env, InteropType value) { -- Gitee