From 915b4d2a89ceb46df68630de31a099a7a5c4160d Mon Sep 17 00:00:00 2001 From: "liang.he" Date: Wed, 15 Mar 2023 12:34:34 +0800 Subject: [PATCH] Fix few wasm-c-api python binding issues (#2029) How to python language binding test cases: ``` $ cd /language-bindings/python $ python -m pip install -e . $ cd wasm-c-api $ python -m unittest tests/test_basic.py $ python -m unittest tests/test_advanced.py ``` --- core/iwasm/common/wasm_c_api.c | 2 +- language-bindings/python/wasm-c-api/tests/test_basic.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/core/iwasm/common/wasm_c_api.c b/core/iwasm/common/wasm_c_api.c index 9f6ed1e5..15eb9f01 100644 --- a/core/iwasm/common/wasm_c_api.c +++ b/core/iwasm/common/wasm_c_api.c @@ -1905,7 +1905,7 @@ wasm_trap_new_internal(wasm_store_t *store, } /* fill in message */ - if (strlen(error_info) > 0) { + if (error_info && strlen(error_info) > 0) { if (!(trap->message = malloc_internal(sizeof(wasm_byte_vec_t)))) { goto failed; } diff --git a/language-bindings/python/wasm-c-api/tests/test_basic.py b/language-bindings/python/wasm-c-api/tests/test_basic.py index 632ad512..a2d3f285 100644 --- a/language-bindings/python/wasm-c-api/tests/test_basic.py +++ b/language-bindings/python/wasm-c-api/tests/test_basic.py @@ -1183,9 +1183,10 @@ class BasicTestSuite(unittest.TestCase): self._wasm_store, module, imports, create_null_pointer(wasm_trap_t) ) - wasm_instance_delete(instance) wasm_module_delete(module) + self.assertIsNullPointer(instance) + def test_wasm_instance_new_pos(self): binary = load_module_file(MODULE_BINARY) module = wasm_module_new(self._wasm_store, binary) @@ -1227,9 +1228,10 @@ class BasicTestSuite(unittest.TestCase): create_null_pointer(wasm_trap_t), ) - wasm_instance_delete(instance) wasm_module_delete(module) + self.assertIsNullPointer(instance) + # test those APIs in advanced: # wasm_instance_delete # wasm_instance_exports