Commit 3dea7bd7 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

vbscript: Store global static arrays together with global variables.

parent d8e8d163
...@@ -1496,6 +1496,7 @@ static HRESULT compile_func(compile_ctx_t *ctx, statement_t *stat, function_t *f ...@@ -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; V_VT(&new_var->v) = VT_EMPTY;
new_var->is_const = FALSE; new_var->is_const = FALSE;
new_var->array = NULL;
new_var->next = ctx->global_vars; new_var->next = ctx->global_vars;
ctx->global_vars = new_var; ctx->global_vars = new_var;
......
...@@ -223,6 +223,7 @@ static HRESULT add_dynamic_var(exec_ctx_t *ctx, const WCHAR *name, ...@@ -223,6 +223,7 @@ static HRESULT add_dynamic_var(exec_ctx_t *ctx, const WCHAR *name,
memcpy(str, name, size); memcpy(str, name, size);
new_var->name = str; new_var->name = str;
new_var->is_const = is_const; new_var->is_const = is_const;
new_var->array = NULL;
V_VT(&new_var->v) = VT_EMPTY; V_VT(&new_var->v) = VT_EMPTY;
if(ctx->func->type == FUNC_GLOBAL) { if(ctx->func->type == FUNC_GLOBAL) {
...@@ -1108,43 +1109,61 @@ static HRESULT interp_dim(exec_ctx_t *ctx) ...@@ -1108,43 +1109,61 @@ static HRESULT interp_dim(exec_ctx_t *ctx)
const BSTR ident = ctx->instr->arg1.bstr; const BSTR ident = ctx->instr->arg1.bstr;
const unsigned array_id = ctx->instr->arg2.uint; const unsigned array_id = ctx->instr->arg2.uint;
const array_desc_t *array_desc; const array_desc_t *array_desc;
ref_t ref; SAFEARRAY **array_ref;
VARIANT *v;
HRESULT hres; HRESULT hres;
TRACE("%s\n", debugstr_w(ident)); TRACE("%s\n", debugstr_w(ident));
assert(array_id < ctx->func->array_cnt); 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(ctx->func->type == FUNC_GLOBAL) {
if(FAILED(hres)) { dynamic_var_t *var;
FIXME("lookup %s failed: %08x\n", debugstr_w(ident), hres); for(var = ctx->script->global_vars; var; var = var->next) {
return hres; 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) { if(!ctx->arrays) {
FIXME("got ref.type = %d\n", ref.type); ctx->arrays = heap_alloc_zero(ctx->func->array_cnt * sizeof(SAFEARRAY*));
return E_FAIL; 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"); FIXME("Array already initialized\n");
return E_FAIL; return E_FAIL;
} }
array_desc = ctx->func->array_descs + array_id; array_desc = ctx->func->array_descs + array_id;
if(array_desc->dim_cnt) { if(array_desc->dim_cnt) {
ctx->arrays[array_id] = SafeArrayCreate(VT_VARIANT, array_desc->dim_cnt, array_desc->bounds); *array_ref = SafeArrayCreate(VT_VARIANT, array_desc->dim_cnt, array_desc->bounds);
if(!ctx->arrays[array_id]) if(!*array_ref)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
V_VT(ref.u.v) = VT_ARRAY|VT_BYREF|VT_VARIANT; V_VT(v) = VT_ARRAY|VT_BYREF|VT_VARIANT;
V_ARRAYREF(ref.u.v) = ctx->arrays+array_id; V_ARRAYREF(v) = array_ref;
return S_OK; return S_OK;
} }
...@@ -2201,6 +2220,8 @@ void release_dynamic_vars(dynamic_var_t *var) ...@@ -2201,6 +2220,8 @@ void release_dynamic_vars(dynamic_var_t *var)
{ {
while(var) { while(var) {
VariantClear(&var->v); VariantClear(&var->v);
if(var->array)
SafeArrayDestroy(var->array);
var = var->next; var = var->next;
} }
} }
......
...@@ -169,6 +169,7 @@ typedef struct _dynamic_var_t { ...@@ -169,6 +169,7 @@ typedef struct _dynamic_var_t {
VARIANT v; VARIANT v;
const WCHAR *name; const WCHAR *name;
BOOL is_const; BOOL is_const;
SAFEARRAY *array;
} dynamic_var_t; } dynamic_var_t;
struct _script_ctx_t { struct _script_ctx_t {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment