diff --git a/core/include_internal/ten_runtime/addon_loader/addon_loader.h b/core/include_internal/ten_runtime/addon_loader/addon_loader.h index 398fca9723..ac98c425b5 100644 --- a/core/include_internal/ten_runtime/addon_loader/addon_loader.h +++ b/core/include_internal/ten_runtime/addon_loader/addon_loader.h @@ -50,10 +50,6 @@ TEN_RUNTIME_API ten_addon_loader_t *ten_addon_loader_create( TEN_RUNTIME_API void ten_addon_loader_destroy(ten_addon_loader_t *self); -TEN_RUNTIME_PRIVATE_API void ten_addon_loader_init(ten_addon_loader_t *self); - -TEN_RUNTIME_PRIVATE_API void ten_addon_loader_deinit(ten_addon_loader_t *self); - TEN_RUNTIME_PRIVATE_API void ten_addon_loader_load_addon( ten_addon_loader_t *self, TEN_ADDON_TYPE addon_type, const char *addon_name); diff --git a/core/src/ten_runtime/addon/addon.c b/core/src/ten_runtime/addon/addon.c index 09864790e5..53373dbd01 100644 --- a/core/src/ten_runtime/addon/addon.c +++ b/core/src/ten_runtime/addon/addon.c @@ -301,14 +301,21 @@ ten_addon_t *ten_addon_unregister(ten_addon_store_t *store, return ten_addon_store_del(store, addon_name); } -static void ten_addon_unregister_all(void) { +static void ten_addon_unregister_all_except_addon_loader_addon(void) { ten_addon_unregister_all_extension(); ten_addon_unregister_all_extension_group(); ten_addon_unregister_all_protocol(); } void ten_unregister_all_addons_and_cleanup(void) { - ten_addon_unregister_all(); + // Since Python addons (e.g., Python extension addons) require access to the + // Python VM when performing `addon_t` deinitialization, and the Python addon + // loader will destroy the Python VM during its own destruction, the Python + // addon loader must only be unloaded after all other non-addon-loader types + // of addons have been fully unloaded. Only then can the addon loader itself + // be unloaded. + + ten_addon_unregister_all_except_addon_loader_addon(); // Destroy all addon loaders' singleton to avoid memory leak. ten_addon_loader_addons_destroy_singleton_instance(); diff --git a/core/src/ten_runtime/addon/addon_autoload.c b/core/src/ten_runtime/addon/addon_autoload.c index 0f6d44540a..d99f7a97ce 100644 --- a/core/src/ten_runtime/addon/addon_autoload.c +++ b/core/src/ten_runtime/addon/addon_autoload.c @@ -410,7 +410,7 @@ bool ten_addon_try_load_specific_addon_using_all_addon_loaders( TEN_ASSERT(addon_loader, "Should not happen."); if (addon_loader) { - addon_loader->on_load_addon(addon_loader, addon_type, addon_name); + ten_addon_loader_load_addon(addon_loader, addon_type, addon_name); } } diff --git a/core/src/ten_runtime/addon_loader/addon_loader.c b/core/src/ten_runtime/addon_loader/addon_loader.c index 64bcfbcb6a..99432b86eb 100644 --- a/core/src/ten_runtime/addon_loader/addon_loader.c +++ b/core/src/ten_runtime/addon_loader/addon_loader.c @@ -57,7 +57,7 @@ void ten_addon_loader_destroy(ten_addon_loader_t *self) { TEN_FREE(self); } -void ten_addon_loader_init(ten_addon_loader_t *self) { +static void ten_addon_loader_init(ten_addon_loader_t *self) { TEN_ASSERT(self && ten_addon_loader_check_integrity(self), "Invalid argument."); @@ -66,7 +66,7 @@ void ten_addon_loader_init(ten_addon_loader_t *self) { } } -void ten_addon_loader_deinit(ten_addon_loader_t *self) { +static void ten_addon_loader_deinit(ten_addon_loader_t *self) { TEN_ASSERT(self && ten_addon_loader_check_integrity(self), "Invalid argument.");