Commit 393f740b authored by Jason Millard's avatar Jason Millard Committed by Alexandre Julliard

vbscript: Add support for redim byref.

parent 1429d211
......@@ -1283,6 +1283,7 @@ static HRESULT interp_redim(exec_ctx_t *ctx)
{
BSTR identifier = ctx->instr->arg1.bstr;
const unsigned dim_cnt = ctx->instr->arg2.uint;
VARIANT *v;
SAFEARRAYBOUND *bounds;
SAFEARRAY *array;
ref_t ref;
......@@ -1312,9 +1313,16 @@ static HRESULT interp_redim(exec_ctx_t *ctx)
/* FIXME: We should check if we're not modifying an existing static array here */
VariantClear(ref.u.v);
V_VT(ref.u.v) = VT_ARRAY|VT_VARIANT;
V_ARRAY(ref.u.v) = array;
v = ref.u.v;
if(V_VT(v) == (VT_VARIANT|VT_BYREF)) {
v = V_VARIANTREF(v);
}
VariantClear(v);
V_VT(v) = VT_ARRAY|VT_VARIANT;
V_ARRAY(v) = array;
return S_OK;
}
......@@ -1323,6 +1331,7 @@ static HRESULT interp_redim_preserve(exec_ctx_t *ctx)
BSTR identifier = ctx->instr->arg1.bstr;
const unsigned dim_cnt = ctx->instr->arg2.uint;
unsigned i;
VARIANT *v;
SAFEARRAYBOUND *bounds;
SAFEARRAY *array;
ref_t ref;
......@@ -1341,12 +1350,18 @@ static HRESULT interp_redim_preserve(exec_ctx_t *ctx)
return E_FAIL;
}
if(!(V_VT(ref.u.v) & VT_ARRAY)) {
FIXME("ReDim Preserve not valid on type %d\n", V_VT(ref.u.v));
v = ref.u.v;
if(V_VT(v) == (VT_VARIANT|VT_BYREF)) {
v = V_VARIANTREF(v);
}
if(!(V_VT(v) & VT_ARRAY)) {
FIXME("ReDim Preserve not valid on type %d\n", V_VT(v));
return E_FAIL;
}
array = V_ARRAY(ref.u.v);
array = V_ARRAY(v);
hres = array_bounds_from_stack(ctx, dim_cnt, &bounds);
if(FAILED(hres))
......@@ -1355,9 +1370,9 @@ static HRESULT interp_redim_preserve(exec_ctx_t *ctx)
if(array == NULL || array->cDims == 0) {
/* can initially allocate the array */
array = SafeArrayCreate(VT_VARIANT, dim_cnt, bounds);
VariantClear(ref.u.v);
V_VT(ref.u.v) = VT_ARRAY|VT_VARIANT;
V_ARRAY(ref.u.v) = array;
VariantClear(v);
V_VT(v) = VT_ARRAY|VT_VARIANT;
V_ARRAY(v) = array;
return S_OK;
} else if(array->cDims != dim_cnt) {
/* can't otherwise change the number of dimensions */
......
......@@ -1562,6 +1562,28 @@ sub TestReDimList
end sub
call TestReDimList
dim rx(4)
sub TestReDimByRef(byref x)
ok ubound(x) = 4, "ubound(x) = " & ubound(x)
redim x(6)
ok ubound(x) = 6, "ubound(x) = " & ubound(x)
end sub
call TestReDimByRef(rx)
ok ubound(rx) = 6, "ubound(rx) = " & ubound(rx)
redim rx(5)
rx(3)=2
sub TestReDimPreserveByRef(byref x)
ok ubound(x) = 5, "ubound(x) = " & ubound(x)
ok x(3) = 2, "x(3) = " & x(3)
redim preserve x(7)
ok ubound(x) = 7, "ubound(x) = " & ubound(x)
ok x(3) = 2, "x(3) = " & x(3)
end sub
call TestReDimPreserveByRef(rx)
ok ubound(rx) = 7, "ubound(rx) = " & ubound(rx)
ok rx(3) = 2, "rx(3) = " & rx(3)
Class ArrClass
Dim classarr(3)
Dim classnoarr()
......
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