diff --git a/interop/src/cpp/common-interop.cc b/interop/src/cpp/common-interop.cc index 8b99dd78d9604b1576ae0b17de096902321cb707..5b5e2ca587f996a7d1b4d15bfdf71e660dfb9c82 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 c7ac999311aee43d882beb81a5d51010be3bc0dc..ab5a6fc956ba1964722c3767f36376f7976bf25b 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) {