Jacek Caban : vbscript: Store global static arrays together with global variables.

Alexandre Julliard julliard at winehq.org
Wed Nov 6 16:54:29 CST 2019


Module: wine
Branch: master
Commit: 3dea7bd7fc5114ae0d6b6bcaaa503cffcdb92eca
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=3dea7bd7fc5114ae0d6b6bcaaa503cffcdb92eca

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Wed Nov  6 17:33:26 2019 +0100

vbscript: Store global static arrays together with global variables.

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/vbscript/compile.c  |  1 +
 dlls/vbscript/interp.c   | 59 ++++++++++++++++++++++++++++++++----------------
 dlls/vbscript/vbscript.h |  1 +
 3 files changed, 42 insertions(+), 19 deletions(-)

diff --git a/dlls/vbscript/compile.c b/dlls/vbscript/compile.c
index e52b0814e0..4ccb164c4a 100644
--- a/dlls/vbscript/compile.c
+++ b/dlls/vbscript/compile.c
@@ -1496,6 +1496,7 @@ static HRESULT compile_func(compile_ctx_t *ctx, statement_t *stat, function_t *f
 
                 V_VT(&new_var->v) = VT_EMPTY;
                 new_var->is_const = FALSE;
+                new_var->array = NULL;
 
                 new_var->next = ctx->global_vars;
                 ctx->global_vars = new_var;
diff --git a/dlls/vbscript/interp.c b/dlls/vbscript/interp.c
index 89f9d359da..e4f982a025 100644
--- a/dlls/vbscript/interp.c
+++ b/dlls/vbscript/interp.c
@@ -223,6 +223,7 @@ static HRESULT add_dynamic_var(exec_ctx_t *ctx, const WCHAR *name,
     memcpy(str, name, size);
     new_var->name = str;
     new_var->is_const = is_const;
+    new_var->array = NULL;
     V_VT(&new_var->v) = VT_EMPTY;
 
     if(ctx->func->type == FUNC_GLOBAL) {
@@ -1108,43 +1109,61 @@ static HRESULT interp_dim(exec_ctx_t *ctx)
     const BSTR ident = ctx->instr->arg1.bstr;
     const unsigned array_id = ctx->instr->arg2.uint;
     const array_desc_t *array_desc;
-    ref_t ref;
+    SAFEARRAY **array_ref;
+    VARIANT *v;
     HRESULT hres;
 
     TRACE("%s\n", debugstr_w(ident));
 
     assert(array_id < ctx->func->array_cnt);
-    if(!ctx->arrays) {
-        ctx->arrays = heap_alloc_zero(ctx->func->array_cnt * sizeof(SAFEARRAY*));
-        if(!ctx->arrays)
-            return E_OUTOFMEMORY;
-    }
 
-    hres = lookup_identifier(ctx, ident, VBDISP_LET, &ref);
-    if(FAILED(hres)) {
-        FIXME("lookup %s failed: %08x\n", debugstr_w(ident), hres);
-        return hres;
-    }
+    if(ctx->func->type == FUNC_GLOBAL) {
+        dynamic_var_t *var;
+        for(var = ctx->script->global_vars; var; var = var->next) {
+            if(!wcsicmp(var->name, ident))
+                break;
+        }
+        assert(var != NULL);
+        v = &var->v;
+        array_ref = &var->array;
+    }else {
+        ref_t ref;
 
-    if(ref.type != REF_VAR) {
-        FIXME("got ref.type = %d\n", ref.type);
-        return E_FAIL;
+        if(!ctx->arrays) {
+            ctx->arrays = heap_alloc_zero(ctx->func->array_cnt * sizeof(SAFEARRAY*));
+            if(!ctx->arrays)
+                return E_OUTOFMEMORY;
+        }
+
+        hres = lookup_identifier(ctx, ident, VBDISP_LET, &ref);
+        if(FAILED(hres)) {
+            FIXME("lookup %s failed: %08x\n", debugstr_w(ident), hres);
+            return hres;
+        }
+
+        if(ref.type != REF_VAR) {
+            FIXME("got ref.type = %d\n", ref.type);
+            return E_FAIL;
+        }
+
+        v = ref.u.v;
+        array_ref = ctx->arrays + array_id;
     }
 
-    if(ctx->arrays[array_id]) {
+    if(*array_ref) {
         FIXME("Array already initialized\n");
         return E_FAIL;
     }
 
     array_desc = ctx->func->array_descs + array_id;
     if(array_desc->dim_cnt) {
-        ctx->arrays[array_id] = SafeArrayCreate(VT_VARIANT, array_desc->dim_cnt, array_desc->bounds);
-        if(!ctx->arrays[array_id])
+        *array_ref = SafeArrayCreate(VT_VARIANT, array_desc->dim_cnt, array_desc->bounds);
+        if(!*array_ref)
             return E_OUTOFMEMORY;
     }
 
-    V_VT(ref.u.v) = VT_ARRAY|VT_BYREF|VT_VARIANT;
-    V_ARRAYREF(ref.u.v) = ctx->arrays+array_id;
+    V_VT(v) = VT_ARRAY|VT_BYREF|VT_VARIANT;
+    V_ARRAYREF(v) = array_ref;
     return S_OK;
 }
 
@@ -2201,6 +2220,8 @@ void release_dynamic_vars(dynamic_var_t *var)
 {
     while(var) {
         VariantClear(&var->v);
+        if(var->array)
+            SafeArrayDestroy(var->array);
         var = var->next;
     }
 }
diff --git a/dlls/vbscript/vbscript.h b/dlls/vbscript/vbscript.h
index 0bd1fce156..ac5242d94f 100644
--- a/dlls/vbscript/vbscript.h
+++ b/dlls/vbscript/vbscript.h
@@ -169,6 +169,7 @@ typedef struct _dynamic_var_t {
     VARIANT v;
     const WCHAR *name;
     BOOL is_const;
+    SAFEARRAY *array;
 } dynamic_var_t;
 
 struct _script_ctx_t {




More information about the wine-cvs mailing list