From d550978ca103c4bd917de130f963f84e50c32360 Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Wed, 29 Jan 2025 14:02:29 +0300 Subject: [PATCH] Enable object finalization Signed-off-by: Nikolay Igotti --- incremental/compat/src/arkts/finalization.ts | 13 ++++--------- interop/src/cpp/vmloader.cc | 7 ++++--- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/incremental/compat/src/arkts/finalization.ts b/incremental/compat/src/arkts/finalization.ts index ff4293d03..021bc1d43 100644 --- a/incremental/compat/src/arkts/finalization.ts +++ b/incremental/compat/src/arkts/finalization.ts @@ -15,22 +15,17 @@ */ export interface Thunk { - // TODO uncomment and use as soon as the FinalizationRegistry is in the sdk - // clean(): void + clean(): void } -/* -const registry = new FinalizationQueue((thunk: Thunk) => { +const registry = new FinalizationRegistry((thunk: Thunk) => { thunk.clean() }) -*/ export function finalizerRegister(target: Object, thunk: Object) { - console.log("finalizerRegister") - // registry.register(target, thunk) + registry.register(target, thunk as Thunk) } export function finalizerUnregister(target: Object) { - console.log("finalizerUnregister") - // registry.unregister(target) + registry.unregister(target) } diff --git a/interop/src/cpp/vmloader.cc b/interop/src/cpp/vmloader.cc index 56cdac2b5..5a13ab166 100644 --- a/interop/src/cpp/vmloader.cc +++ b/interop/src/cpp/vmloader.cc @@ -527,8 +527,8 @@ void traverseDir(std::string root, std::vector& paths, int depth) { #if defined(KOALA_OHOS) suffix += ".so"; #endif - DIR* d = opendir(root.c_str()); - if (!d) { + DIR* directory = opendir(root.c_str()); + if (!directory) { LOGE("Cannot open dir %" LOG_PUBLIC "s\n", root.c_str()); return; } @@ -536,7 +536,7 @@ void traverseDir(std::string root, std::vector& paths, int depth) { struct stat statbuf; LOGI("Searching for *%" LOG_PUBLIC "s in %" LOG_PUBLIC "s\n", suffix.c_str(), root.c_str()); - while ((ent = readdir(d)) != nullptr) { + while ((ent = readdir(directory)) != nullptr) { std::string filename = std::string(ent->d_name); if (filename == "." || filename == "..") { continue; @@ -551,5 +551,6 @@ void traverseDir(std::string root, std::vector& paths, int depth) { traverseDir(filepath, paths, depth + 1); } } + closedir(directory); #endif } -- Gitee