Просмотр исходного кода

Add wasm_runtime_get_cur_local_obj_ref and change API names (#3117)

Add wasm_runtime_get_cur_local_obj_ref and change API:
```C
wasm_runtime_push_local_object_ref
wasm_runtime_pop_local_object_ref
wasm_runtime_pop_local_object_refs
```
to
```C
wasm_runtime_push_local_obj_ref
wasm_runtime_pop_local_obj_ref
wasm_runtime_pop_local_obj_refs
```

Signed-off-by: zhangliangyu3 <zhangliangyu3@xiaomi.com>
Liangyu Zhang 1 год назад
Родитель
Сommit
dcde45596d

+ 12 - 4
core/iwasm/common/gc/gc_common.c

@@ -866,8 +866,7 @@ wasm_obj_is_instance_of_ref_type(const WASMObjectRef obj,
 }
 
 void
-wasm_runtime_push_local_object_ref(WASMExecEnv *exec_env,
-                                   WASMLocalObjectRef *ref)
+wasm_runtime_push_local_obj_ref(WASMExecEnv *exec_env, WASMLocalObjectRef *ref)
 {
     ref->val = NULL;
     ref->prev = exec_env->cur_local_object_ref;
@@ -875,7 +874,7 @@ wasm_runtime_push_local_object_ref(WASMExecEnv *exec_env,
 }
 
 WASMLocalObjectRef *
-wasm_runtime_pop_local_object_ref(WASMExecEnv *exec_env)
+wasm_runtime_pop_local_obj_ref(WASMExecEnv *exec_env)
 {
     WASMLocalObjectRef *local_ref = exec_env->cur_local_object_ref;
     exec_env->cur_local_object_ref = exec_env->cur_local_object_ref->prev;
@@ -883,7 +882,7 @@ wasm_runtime_pop_local_object_ref(WASMExecEnv *exec_env)
 }
 
 void
-wasm_runtime_pop_local_object_refs(WASMExecEnv *exec_env, uint32 n)
+wasm_runtime_pop_local_obj_refs(WASMExecEnv *exec_env, uint32 n)
 {
     bh_assert(n > 0);
 
@@ -892,6 +891,15 @@ wasm_runtime_pop_local_object_refs(WASMExecEnv *exec_env, uint32 n)
     } while (--n > 0);
 }
 
+WASMLocalObjectRef *
+wasm_runtime_get_cur_local_obj_ref(WASMExecEnv *exec_env)
+{
+    WASMLocalObjectRef *local_ref = exec_env->cur_local_object_ref;
+
+    bh_assert(local_ref);
+    return local_ref;
+}
+
 void
 wasm_runtime_gc_prepare(WASMExecEnv *exec_env)
 {

+ 3 - 3
core/iwasm/common/gc/gc_object.c

@@ -428,19 +428,19 @@ wasm_externref_obj_new(WASMExecEnv *exec_env, const void *host_obj)
     anyref_obj->host_obj = host_obj;
 
     /* Lock anyref_obj in case it is reclaimed when allocating memory below */
-    wasm_runtime_push_local_object_ref(exec_env, &local_ref);
+    wasm_runtime_push_local_obj_ref(exec_env, &local_ref);
     local_ref.val = (WASMObjectRef)anyref_obj;
 
     if (!(externref_obj =
               gc_obj_malloc(heap_handle, sizeof(WASMExternrefObject)))) {
-        wasm_runtime_pop_local_object_ref(exec_env);
+        wasm_runtime_pop_local_obj_ref(exec_env);
         return NULL;
     }
 
     externref_obj->header = WASM_OBJ_EXTERNREF_OBJ_FLAG;
     externref_obj->internal_obj = (WASMObjectRef)anyref_obj;
 
-    wasm_runtime_pop_local_object_ref(exec_env);
+    wasm_runtime_pop_local_obj_ref(exec_env);
     return externref_obj;
 }
 

+ 4 - 4
core/iwasm/common/wasm_application.c

@@ -595,7 +595,7 @@ execute_func(WASMModuleInstanceCommon *module_inst, const char *name,
                                                  module_inst, NULL, 0))) {
                             goto fail;
                         }
-                        wasm_runtime_push_local_object_ref(exec_env, local_ref);
+                        wasm_runtime_push_local_obj_ref(exec_env, local_ref);
                         local_ref->val = (WASMObjectRef)gc_obj;
                         num_local_ref_pushed++;
                         PUT_REF_TO_ADDR(argv1 + p, gc_obj);
@@ -618,7 +618,7 @@ execute_func(WASMModuleInstanceCommon *module_inst, const char *name,
                                                  module_inst, NULL, 0))) {
                             goto fail;
                         }
-                        wasm_runtime_push_local_object_ref(exec_env, local_ref);
+                        wasm_runtime_push_local_obj_ref(exec_env, local_ref);
                         local_ref->val = (WASMObjectRef)gc_obj;
                         num_local_ref_pushed++;
                         PUT_REF_TO_ADDR(argv1 + p, gc_obj);
@@ -842,7 +842,7 @@ execute_func(WASMModuleInstanceCommon *module_inst, const char *name,
 
 #if WASM_ENABLE_GC != 0
     for (j = 0; j < num_local_ref_pushed; j++) {
-        local_ref = wasm_runtime_pop_local_object_ref(exec_env);
+        local_ref = wasm_runtime_pop_local_obj_ref(exec_env);
         wasm_runtime_free(local_ref);
     }
 #endif
@@ -856,7 +856,7 @@ fail:
 
 #if WASM_ENABLE_GC != 0
     for (j = 0; j < num_local_ref_pushed; j++) {
-        local_ref = wasm_runtime_pop_local_object_ref(exec_env);
+        local_ref = wasm_runtime_pop_local_obj_ref(exec_env);
         wasm_runtime_free(local_ref);
     }
 #endif

+ 15 - 4
core/iwasm/include/gc_export.h

@@ -890,8 +890,8 @@ wasm_obj_is_instance_of_ref_type(const wasm_obj_t obj,
  * @param local_obj_ref the local object ref to push
  */
 WASM_RUNTIME_API_EXTERN void
-wasm_runtime_push_local_object_ref(wasm_exec_env_t exec_env,
-                                   wasm_local_obj_ref_t *local_obj_ref);
+wasm_runtime_push_local_obj_ref(wasm_exec_env_t exec_env,
+                                wasm_local_obj_ref_t *local_obj_ref);
 
 /**
  * Pop a local object ref from stack
@@ -901,7 +901,7 @@ wasm_runtime_push_local_object_ref(wasm_exec_env_t exec_env,
  * @return the popped wasm_local_obj_ref_t
  */
 WASM_RUNTIME_API_EXTERN wasm_local_obj_ref_t *
-wasm_runtime_pop_local_object_ref(wasm_exec_env_t exec_env);
+wasm_runtime_pop_local_obj_ref(wasm_exec_env_t exec_env);
 
 /**
  * Pop n local object refs from stack
@@ -910,7 +910,18 @@ wasm_runtime_pop_local_object_ref(wasm_exec_env_t exec_env);
  * @param n number to pop
  */
 WASM_RUNTIME_API_EXTERN void
-wasm_runtime_pop_local_object_refs(wasm_exec_env_t exec_env, uint32_t n);
+wasm_runtime_pop_local_obj_refs(wasm_exec_env_t exec_env, uint32_t n);
+
+/**
+ * Get current local object ref from stack
+ *
+ * @param exec_env the execution environment
+ *
+ * @return the wasm_local_obj_ref_t obj from the top of the stack, not change
+ * the state of the stack
+ */
+WASM_RUNTIME_API_EXTERN wasm_local_obj_ref_t *
+wasm_runtime_get_cur_local_obj_ref(wasm_exec_env_t exec_env);
 
 /**
  * Set finalizer to the given object, if another finalizer is set to the same