fix(plugins): make native loading lifecycle safe

This commit is contained in:
西风逍遥游 committed 2026-08-25 02:03:02 +08:00
1 parent 5350fd9a55
commit f044c73e35
8 files changed
+170 -31

No files matched your search

+24
View File
@@ -1,6 +1,7 @@
#include "zeroerr/assert.h"
#include "zeroerr/unittest.h"
#include "common/Runtime.h"
#include "plugins/Plugins.h"
#include <string>
@@ -38,3 +39,26 @@ TEST_CASE("plugins.unload.unknownPathIsNoop") {
Plugins plugins;
CHECK_EQ(plugins.unload("not-loaded"), false);
}
#if !defined(EVENGINE_ANDROID) && !defined(EVENGINE_IOS)
TEST_CASE("plugins.load.nativeLibraryAndInstantiateCppModule") {
eve::Runtime runtime(512, ssq::Libs::ALL);
runtime.initialize();
Plugins plugins;
const std::string library =
std::string(EVENGINE_TEST_BINARY_DIR) + "/native_test_plugin" +
EVENGINE_TEST_SHARED_LIBRARY_SUFFIX;
REQUIRE(plugins.load(library));
CHECK(plugins.isLoaded(library));
auto* module = eve::ModuleManager::requireInstance<eve::Module>("NativeTestPlugin");
REQUIRE(module != nullptr);
CHECK_EQ(module->getName(), std::string("NativeTestPlugin"));
// Native classes and VM closures still point into the library, so plugins
// deliberately remain resident for the rest of the process.
CHECK_EQ(plugins.unload(library), false);
CHECK(plugins.isLoaded(library));
}
#endif