Module: wine Branch: master Commit: 393f740bb70b90171511e067520a674fc63de19d URL: https://gitlab.winehq.org/wine/wine/-/commit/393f740bb70b90171511e067520a674...
Author: Jason Millard jsm174@gmail.com Date: Tue Nov 22 08:41:24 2022 -0500
vbscript: Add support for redim byref.
---
dlls/vbscript/interp.c | 33 ++++++++++++++++++++++++--------- dlls/vbscript/tests/lang.vbs | 22 ++++++++++++++++++++++ 2 files changed, 46 insertions(+), 9 deletions(-)
diff --git a/dlls/vbscript/interp.c b/dlls/vbscript/interp.c index 77875ee7f44..2d33982839e 100644 --- a/dlls/vbscript/interp.c +++ b/dlls/vbscript/interp.c @@ -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 */ diff --git a/dlls/vbscript/tests/lang.vbs b/dlls/vbscript/tests/lang.vbs index beb7c7e86c9..990d830234d 100644 --- a/dlls/vbscript/tests/lang.vbs +++ b/dlls/vbscript/tests/lang.vbs @@ -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()