vbscript: Store global functions in an array.

Based on patch by Gabriel Ivăncescu.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2019-11-04 17:37:24 +01:00 committed by Alexandre Julliard
parent 8f1e633874
commit ea7a3953fc
5 changed files with 34 additions and 14 deletions

View File

@ -1802,15 +1802,15 @@ static BOOL lookup_script_identifier(script_ctx_t *script, const WCHAR *identifi
{ {
class_desc_t *class; class_desc_t *class;
dynamic_var_t *var; dynamic_var_t *var;
function_t *func; unsigned i;
for(var = script->global_vars; var; var = var->next) { for(var = script->global_vars; var; var = var->next) {
if(!wcsicmp(var->name, identifier)) if(!wcsicmp(var->name, identifier))
return TRUE; return TRUE;
} }
for(func = script->global_funcs; func; func = func->next) { for(i = 0; i < script->global_funcs_cnt; i++) {
if(!wcsicmp(func->name, identifier)) if(!wcsicmp(script->global_funcs[i]->name, identifier))
return TRUE; return TRUE;
} }
@ -1914,11 +1914,12 @@ static void release_compiler(compile_ctx_t *ctx)
HRESULT compile_script(script_ctx_t *script, const WCHAR *src, const WCHAR *delimiter, DWORD flags, vbscode_t **ret) HRESULT compile_script(script_ctx_t *script, const WCHAR *src, const WCHAR *delimiter, DWORD flags, vbscode_t **ret)
{ {
function_t *new_func; function_t *new_func, *func_iter;
function_decl_t *func_decl; function_decl_t *func_decl;
class_decl_t *class_decl; class_decl_t *class_decl;
compile_ctx_t ctx; compile_ctx_t ctx;
vbscode_t *code; vbscode_t *code;
size_t cnt;
HRESULT hres; HRESULT hres;
if (!src) src = L""; if (!src) src = L"";
@ -1982,12 +1983,22 @@ HRESULT compile_script(script_ctx_t *script, const WCHAR *src, const WCHAR *deli
script->global_vars = ctx.global_vars; script->global_vars = ctx.global_vars;
} }
if(ctx.funcs) { cnt = script->global_funcs_cnt;
for(new_func = ctx.funcs; new_func->next; new_func = new_func->next); for(func_iter = ctx.funcs; func_iter; func_iter = func_iter->next)
cnt++;
new_func->next = script->global_funcs; if(cnt > script->global_funcs_size) {
script->global_funcs = ctx.funcs; function_t **new_funcs;
if(script->global_funcs)
new_funcs = heap_realloc(script->global_funcs, cnt * sizeof(*new_funcs));
else
new_funcs = heap_alloc(cnt * sizeof(*new_funcs));
if(!new_funcs)
return compile_error(script, E_OUTOFMEMORY);
script->global_funcs = new_funcs;
script->global_funcs_size = cnt;
} }
for(func_iter = ctx.funcs; func_iter; func_iter = func_iter->next)
script->global_funcs[script->global_funcs_cnt++] = func_iter;
if(ctx.classes) { if(ctx.classes) {
class_desc_t *class = ctx.classes; class_desc_t *class = ctx.classes;

View File

@ -98,7 +98,6 @@ static BOOL lookup_dynamic_vars(dynamic_var_t *var, const WCHAR *name, ref_t *re
static HRESULT lookup_identifier(exec_ctx_t *ctx, BSTR name, vbdisp_invoke_type_t invoke_type, ref_t *ref) static HRESULT lookup_identifier(exec_ctx_t *ctx, BSTR name, vbdisp_invoke_type_t invoke_type, ref_t *ref)
{ {
named_item_t *item; named_item_t *item;
function_t *func;
IDispatch *disp; IDispatch *disp;
unsigned i; unsigned i;
DISPID id; DISPID id;
@ -164,7 +163,8 @@ static HRESULT lookup_identifier(exec_ctx_t *ctx, BSTR name, vbdisp_invoke_type_
if(ctx->func->type != FUNC_GLOBAL && lookup_dynamic_vars(ctx->script->global_vars, name, ref)) if(ctx->func->type != FUNC_GLOBAL && lookup_dynamic_vars(ctx->script->global_vars, name, ref))
return S_OK; return S_OK;
for(func = ctx->script->global_funcs; func; func = func->next) { for(i = 0; i < ctx->script->global_funcs_cnt; i++) {
function_t *func = ctx->script->global_funcs[i];
if(!wcsicmp(func->name, name)) { if(!wcsicmp(func->name, name)) {
ref->type = REF_FUNC; ref->type = REF_FUNC;
ref->u.f = func; ref->u.f = func;

View File

@ -677,7 +677,7 @@ static HRESULT WINAPI ScriptDisp_GetDispID(IDispatchEx *iface, BSTR bstrName, DW
ScriptDisp *This = ScriptDisp_from_IDispatchEx(iface); ScriptDisp *This = ScriptDisp_from_IDispatchEx(iface);
dynamic_var_t *var; dynamic_var_t *var;
ident_map_t *ident; ident_map_t *ident;
function_t *func; unsigned i;
TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(bstrName), grfdex, pid); TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(bstrName), grfdex, pid);
@ -704,7 +704,8 @@ static HRESULT WINAPI ScriptDisp_GetDispID(IDispatchEx *iface, BSTR bstrName, DW
} }
} }
for(func = This->ctx->global_funcs; func; func = func->next) { for(i = 0; i < This->ctx->global_funcs_cnt; i++) {
function_t *func = This->ctx->global_funcs[i];
if(!wcsicmp(func->name, bstrName)) { if(!wcsicmp(func->name, bstrName)) {
ident = add_ident(This, func->name); ident = add_ident(This, func->name);
if(!ident) if(!ident)

View File

@ -138,6 +138,11 @@ static void release_script(script_ctx_t *ctx)
release_dynamic_vars(ctx->global_vars); release_dynamic_vars(ctx->global_vars);
ctx->global_vars = NULL; ctx->global_vars = NULL;
heap_free(ctx->global_funcs);
ctx->global_funcs = NULL;
ctx->global_funcs_cnt = 0;
ctx->global_funcs_size = 0;
while(!list_empty(&ctx->named_items)) { while(!list_empty(&ctx->named_items)) {
named_item_t *iter = LIST_ENTRY(list_head(&ctx->named_items), named_item_t, entry); named_item_t *iter = LIST_ENTRY(list_head(&ctx->named_items), named_item_t, entry);

View File

@ -187,8 +187,11 @@ struct _script_ctx_t {
EXCEPINFO ei; EXCEPINFO ei;
function_t **global_funcs;
size_t global_funcs_cnt;
size_t global_funcs_size;
dynamic_var_t *global_vars; dynamic_var_t *global_vars;
function_t *global_funcs;
class_desc_t *classes; class_desc_t *classes;
class_desc_t *procs; class_desc_t *procs;