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:
parent
8f1e633874
commit
ea7a3953fc
|
@ -1802,15 +1802,15 @@ static BOOL lookup_script_identifier(script_ctx_t *script, const WCHAR *identifi
|
|||
{
|
||||
class_desc_t *class;
|
||||
dynamic_var_t *var;
|
||||
function_t *func;
|
||||
unsigned i;
|
||||
|
||||
for(var = script->global_vars; var; var = var->next) {
|
||||
if(!wcsicmp(var->name, identifier))
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
for(func = script->global_funcs; func; func = func->next) {
|
||||
if(!wcsicmp(func->name, identifier))
|
||||
for(i = 0; i < script->global_funcs_cnt; i++) {
|
||||
if(!wcsicmp(script->global_funcs[i]->name, identifier))
|
||||
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)
|
||||
{
|
||||
function_t *new_func;
|
||||
function_t *new_func, *func_iter;
|
||||
function_decl_t *func_decl;
|
||||
class_decl_t *class_decl;
|
||||
compile_ctx_t ctx;
|
||||
vbscode_t *code;
|
||||
size_t cnt;
|
||||
HRESULT hres;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if(ctx.funcs) {
|
||||
for(new_func = ctx.funcs; new_func->next; new_func = new_func->next);
|
||||
|
||||
new_func->next = script->global_funcs;
|
||||
script->global_funcs = ctx.funcs;
|
||||
cnt = script->global_funcs_cnt;
|
||||
for(func_iter = ctx.funcs; func_iter; func_iter = func_iter->next)
|
||||
cnt++;
|
||||
if(cnt > script->global_funcs_size) {
|
||||
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) {
|
||||
class_desc_t *class = ctx.classes;
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
named_item_t *item;
|
||||
function_t *func;
|
||||
IDispatch *disp;
|
||||
unsigned i;
|
||||
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))
|
||||
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)) {
|
||||
ref->type = REF_FUNC;
|
||||
ref->u.f = func;
|
||||
|
|
|
@ -677,7 +677,7 @@ static HRESULT WINAPI ScriptDisp_GetDispID(IDispatchEx *iface, BSTR bstrName, DW
|
|||
ScriptDisp *This = ScriptDisp_from_IDispatchEx(iface);
|
||||
dynamic_var_t *var;
|
||||
ident_map_t *ident;
|
||||
function_t *func;
|
||||
unsigned i;
|
||||
|
||||
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)) {
|
||||
ident = add_ident(This, func->name);
|
||||
if(!ident)
|
||||
|
|
|
@ -138,6 +138,11 @@ static void release_script(script_ctx_t *ctx)
|
|||
release_dynamic_vars(ctx->global_vars);
|
||||
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)) {
|
||||
named_item_t *iter = LIST_ENTRY(list_head(&ctx->named_items), named_item_t, entry);
|
||||
|
||||
|
|
|
@ -187,8 +187,11 @@ struct _script_ctx_t {
|
|||
|
||||
EXCEPINFO ei;
|
||||
|
||||
function_t **global_funcs;
|
||||
size_t global_funcs_cnt;
|
||||
size_t global_funcs_size;
|
||||
|
||||
dynamic_var_t *global_vars;
|
||||
function_t *global_funcs;
|
||||
class_desc_t *classes;
|
||||
class_desc_t *procs;
|
||||
|
||||
|
|
Loading…
Reference in New Issue