[PATCH 2/9] vbscript: Store the DISPID for functions and variables.

Gabriel Ivăncescu gabrielopcode at gmail.com
Tue Oct 15 09:54:53 CDT 2019


Signed-off-by: Gabriel Ivăncescu <gabrielopcode at gmail.com>
---

This will be needed for next patch to build the TypeInfo properly, as the
DISPIDs have to match with MEMBERIDs.

 dlls/vbscript/compile.c  |  2 ++
 dlls/vbscript/interp.c   |  1 +
 dlls/vbscript/vbdisp.c   | 38 ++++++++++++++++++++++++++++----------
 dlls/vbscript/vbscript.h |  2 ++
 4 files changed, 33 insertions(+), 10 deletions(-)

diff --git a/dlls/vbscript/compile.c b/dlls/vbscript/compile.c
index b2be38d..06d293e 100644
--- a/dlls/vbscript/compile.c
+++ b/dlls/vbscript/compile.c
@@ -1424,6 +1424,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->dispid   = 0;
 
                 new_var->next = ctx->global_vars;
                 ctx->global_vars = new_var;
@@ -1497,6 +1498,7 @@ static HRESULT create_function(compile_ctx_t *ctx, function_decl_t *decl, functi
     if(!func->name)
         return E_OUTOFMEMORY;
 
+    func->dispid = 0;
     func->vars = NULL;
     func->var_cnt = 0;
     func->array_cnt = 0;
diff --git a/dlls/vbscript/interp.c b/dlls/vbscript/interp.c
index 8649164..0fe0fb9 100644
--- a/dlls/vbscript/interp.c
+++ b/dlls/vbscript/interp.c
@@ -233,6 +233,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->dispid = 0;
     V_VT(&new_var->v) = VT_EMPTY;
 
     if(ctx->func->type == FUNC_GLOBAL) {
diff --git a/dlls/vbscript/vbdisp.c b/dlls/vbscript/vbdisp.c
index f3385ae..c0535f1 100644
--- a/dlls/vbscript/vbdisp.c
+++ b/dlls/vbscript/vbdisp.c
@@ -700,6 +700,30 @@ static ident_map_t *add_ident(ScriptDisp *This, const WCHAR *name)
     return ret;
 }
 
+static ident_map_t *add_var_ident(ScriptDisp *This, dynamic_var_t *var)
+{
+    ident_map_t *ident = add_ident(This, var->name);
+    if (ident)
+    {
+        ident->is_var = TRUE;
+        ident->u.var = var;
+        var->dispid = ident_to_id(This, ident);
+    }
+    return ident;
+}
+
+static ident_map_t *add_func_ident(ScriptDisp *This, function_t *func)
+{
+    ident_map_t *ident = add_ident(This, func->name);
+    if (ident)
+    {
+        ident->is_var = FALSE;
+        ident->u.func = func;
+        func->dispid = ident_to_id(This, ident);
+    }
+    return ident;
+}
+
 typedef struct {
     ITypeInfo ITypeInfo_iface;
     LONG ref;
@@ -1090,26 +1114,20 @@ static HRESULT WINAPI ScriptDisp_GetDispID(IDispatchEx *iface, BSTR bstrName, DW
 
     for(var = This->ctx->global_vars; var; var = var->next) {
         if(!wcsicmp(var->name, bstrName)) {
-            ident = add_ident(This, var->name);
-            if(!ident)
+            if(!add_var_ident(This, var))
                 return E_OUTOFMEMORY;
 
-            ident->is_var = TRUE;
-            ident->u.var = var;
-            *pid = ident_to_id(This, ident);
+            *pid = var->dispid;
             return S_OK;
         }
     }
 
     for(func = This->ctx->global_funcs; func; func = func->next) {
         if(!wcsicmp(func->name, bstrName)) {
-            ident = add_ident(This, func->name);
-            if(!ident)
+            if(!add_func_ident(This, func))
                 return E_OUTOFMEMORY;
 
-            ident->is_var = FALSE;
-            ident->u.func = func;
-            *pid =  ident_to_id(This, ident);
+            *pid = func->dispid;
             return S_OK;
         }
     }
diff --git a/dlls/vbscript/vbscript.h b/dlls/vbscript/vbscript.h
index 1d9353a..654e827 100644
--- a/dlls/vbscript/vbscript.h
+++ b/dlls/vbscript/vbscript.h
@@ -174,6 +174,7 @@ typedef struct _dynamic_var_t {
     VARIANT v;
     const WCHAR *name;
     BOOL is_const;
+    DISPID dispid;
 } dynamic_var_t;
 
 struct _script_ctx_t {
@@ -322,6 +323,7 @@ typedef struct {
 } var_desc_t;
 
 struct _function_t {
+    DISPID dispid;
     function_type_t type;
     const WCHAR *name;
     BOOL is_public;
-- 
2.21.0




More information about the wine-devel mailing list