Commit 0b5473c1 authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

vbscript: Reimplement array_access function.

parent 8f0d12e2
...@@ -481,10 +481,8 @@ static void vbstack_to_dp(exec_ctx_t *ctx, unsigned arg_cnt, BOOL is_propput, DI ...@@ -481,10 +481,8 @@ static void vbstack_to_dp(exec_ctx_t *ctx, unsigned arg_cnt, BOOL is_propput, DI
static HRESULT array_access(exec_ctx_t *ctx, SAFEARRAY *array, DISPPARAMS *dp, VARIANT **ret) static HRESULT array_access(exec_ctx_t *ctx, SAFEARRAY *array, DISPPARAMS *dp, VARIANT **ret)
{ {
unsigned cell_off = 0, dim_size = 1, i; unsigned i, argc = arg_cnt(dp);
unsigned argc = arg_cnt(dp); LONG *indices;
VARIANT *data;
LONG idx;
HRESULT hres; HRESULT hres;
if(!array) { if(!array) {
...@@ -492,34 +490,35 @@ static HRESULT array_access(exec_ctx_t *ctx, SAFEARRAY *array, DISPPARAMS *dp, V ...@@ -492,34 +490,35 @@ static HRESULT array_access(exec_ctx_t *ctx, SAFEARRAY *array, DISPPARAMS *dp, V
return E_FAIL; return E_FAIL;
} }
hres = SafeArrayLock(array);
if(FAILED(hres))
return hres;
if(array->cDims != argc) { if(array->cDims != argc) {
FIXME("argc %d does not match cDims %d\n", dp->cArgs, array->cDims); FIXME("argc %d does not match cDims %d\n", dp->cArgs, array->cDims);
SafeArrayUnlock(array);
return E_FAIL; return E_FAIL;
} }
for(i=0; i < argc; i++) { indices = heap_alloc(sizeof(*indices) * argc);
hres = to_int(get_arg(dp, i), &idx); if(!indices) {
if(FAILED(hres)) SafeArrayUnlock(array);
return hres; return E_OUTOFMEMORY;
}
idx -= array->rgsabound[i].lLbound; for(i=0; i<argc; i++) {
if(idx >= array->rgsabound[i].cElements) { hres = to_int(get_arg(dp, i), indices+i);
FIXME("out of bound element %d in dim %d of size %d\n", idx, i+1, array->rgsabound[i].cElements); if(FAILED(hres)) {
return E_FAIL; heap_free(indices);
SafeArrayUnlock(array);
return hres;
} }
cell_off += idx*dim_size;
dim_size *= array->rgsabound[i].cElements;
} }
hres = SafeArrayAccessData(array, (void**)&data); hres = SafeArrayPtrOfIndex(array, indices, (void**)ret);
if(FAILED(hres)) SafeArrayUnlock(array);
return hres; heap_free(indices);
return hres;
*ret = data+cell_off;
SafeArrayUnaccessData(array);
return S_OK;
} }
static HRESULT do_icall(exec_ctx_t *ctx, VARIANT *res) static HRESULT do_icall(exec_ctx_t *ctx, VARIANT *res)
......
...@@ -1157,6 +1157,8 @@ arr3(3,2,1) = 1 ...@@ -1157,6 +1157,8 @@ arr3(3,2,1) = 1
arr3(1,2,3) = 2 arr3(1,2,3) = 2
Call ok(arr3(3,2,1) = 1, "arr3(3,2,1) = " & arr3(3,2,1)) Call ok(arr3(3,2,1) = 1, "arr3(3,2,1) = " & arr3(3,2,1))
Call ok(arr3(1,2,3) = 2, "arr3(1,2,3) = " & arr3(1,2,3)) Call ok(arr3(1,2,3) = 2, "arr3(1,2,3) = " & arr3(1,2,3))
arr2(4,3) = 1
Call ok(arr2(4,3) = 1, "arr2(4,3) = " & arr2(4,3))
x = arr3 x = arr3
Call ok(x(3,2,1) = 1, "x(3,2,1) = " & x(3,2,1)) Call ok(x(3,2,1) = 1, "x(3,2,1) = " & x(3,2,1))
......
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