[PATCH v2 2/4] vbscript: Move the script context heap to the script dispatch object.

Gabriel Ivăncescu gabrielopcode at gmail.com
Mon Oct 21 06:40:28 CDT 2019


The heap stores dynamic global variables added during the execution
phase. We'll need to reference them in the TypeInfo, and so we have to
reference count the heap itself, and the simplest way is to use the script
dispatch object to store it.

Signed-off-by: Gabriel Ivăncescu <gabrielopcode at gmail.com>
---
 dlls/vbscript/interp.c   | 2 +-
 dlls/vbscript/vbdisp.c   | 2 ++
 dlls/vbscript/vbscript.c | 3 ---
 dlls/vbscript/vbscript.h | 3 +--
 4 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/dlls/vbscript/interp.c b/dlls/vbscript/interp.c
index 80588b5..69f2c8c 100644
--- a/dlls/vbscript/interp.c
+++ b/dlls/vbscript/interp.c
@@ -212,7 +212,7 @@ static HRESULT add_dynamic_var(exec_ctx_t *ctx, const WCHAR *name,
     WCHAR *str;
     unsigned size;
 
-    heap = ctx->func->type == FUNC_GLOBAL ? &ctx->script->heap : &ctx->heap;
+    heap = ctx->func->type == FUNC_GLOBAL ? &ctx->script->script_obj->heap : &ctx->heap;
 
     new_var = heap_pool_alloc(heap, sizeof(*new_var));
     if(!new_var)
diff --git a/dlls/vbscript/vbdisp.c b/dlls/vbscript/vbdisp.c
index fd51935..0f8fb55 100644
--- a/dlls/vbscript/vbdisp.c
+++ b/dlls/vbscript/vbdisp.c
@@ -620,6 +620,7 @@ static ULONG WINAPI ScriptDisp_Release(IDispatchEx *iface)
 
     if(!ref) {
         assert(!This->ctx);
+        heap_pool_free(&This->heap);
         heap_free(This->ident_map);
         heap_free(This);
     }
@@ -814,6 +815,7 @@ HRESULT create_script_disp(script_ctx_t *ctx, ScriptDisp **ret)
     script_disp->IDispatchEx_iface.lpVtbl = &ScriptDispVtbl;
     script_disp->ref = 1;
     script_disp->ctx = ctx;
+    heap_pool_init(&script_disp->heap);
 
     *ret = script_disp;
     return S_OK;
diff --git a/dlls/vbscript/vbscript.c b/dlls/vbscript/vbscript.c
index 56c53b4..da5c3dd 100644
--- a/dlls/vbscript/vbscript.c
+++ b/dlls/vbscript/vbscript.c
@@ -179,8 +179,6 @@ static void release_script(script_ctx_t *ctx)
     }
 
     detach_global_objects(ctx);
-    heap_pool_free(&ctx->heap);
-    heap_pool_init(&ctx->heap);
 }
 
 static void destroy_script(script_ctx_t *ctx)
@@ -955,7 +953,6 @@ HRESULT WINAPI VBScriptFactory_CreateInstance(IClassFactory *iface, IUnknown *pU
     }
 
     ctx->safeopt = INTERFACE_USES_DISPEX;
-    heap_pool_init(&ctx->heap);
     list_init(&ctx->objects);
     list_init(&ctx->code_list);
     list_init(&ctx->named_items);
diff --git a/dlls/vbscript/vbscript.h b/dlls/vbscript/vbscript.h
index 9d41632..9933329 100644
--- a/dlls/vbscript/vbscript.h
+++ b/dlls/vbscript/vbscript.h
@@ -130,6 +130,7 @@ typedef struct {
     unsigned ident_map_cnt;
 
     script_ctx_t *ctx;
+    heap_pool_t heap;
 } ScriptDisp;
 
 typedef struct _builtin_prop_t builtin_prop_t;
@@ -194,8 +195,6 @@ struct _script_ctx_t {
     class_desc_t *classes;
     class_desc_t *procs;
 
-    heap_pool_t heap;
-
     struct list objects;
     struct list code_list;
     struct list named_items;
-- 
2.21.0




More information about the wine-devel mailing list