[PATCH v2 0/2] MR10907: vbscript: Parse &H8000 as Long(-32768) like native.
Native cscript parses every 4-digit hex literal that fits 16 bits as Integer except &H8000: its value -32768 (INT16_MIN) has no positive Int16 representation, so native promotes it to Long. Wine returned Integer for that one case because interp_int narrows any value that fits VT_I2. Introduce OP_long that unconditionally pushes VT_I4, and route the &H8000 case through it via a new tLong token. -- v2: vbscript: Parse &H8000 as Long(-32768) like native. https://gitlab.winehq.org/wine/wine/-/merge_requests/10907
From: Francis De Brabandere <francisdb@gmail.com> --- dlls/vbscript/tests/lang.vbs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/dlls/vbscript/tests/lang.vbs b/dlls/vbscript/tests/lang.vbs index 1b6cdf763e4..01f86406965 100644 --- a/dlls/vbscript/tests/lang.vbs +++ b/dlls/vbscript/tests/lang.vbs @@ -72,6 +72,17 @@ Call ok(&H000000031& = 49, "&H000000031& <> 49") Call ok(getVT(&H00000000000000FF) = "VT_I2", "getVT(&H00000000000000FF) is not VT_I2") Call ok(getVT(&H007FFFFFFF) = "VT_I4", "getVT(&H007FFFFFFF) is not VT_I4") Call ok(&h0 = 0, "&h0 <> 0") + +' &H8000 (INT16_MIN bit pattern) is the one 16-bit value parsed as Long, not +' Integer: -32768 has no positive Int16 representation, so native promotes it. +Call ok(&H8000 = -32768, "&H8000 <> -32768") +todo_wine_ok getVT(&H8000) = "VT_I4", "getVT(&H8000) is not VT_I4" +Call ok(&H8001 = -32767, "&H8001 <> -32767") +Call ok(getVT(&H8001) = "VT_I2", "getVT(&H8001) is not VT_I2") +Call ok(&H7FFF = 32767, "&H7FFF <> 32767") +Call ok(getVT(&H7FFF) = "VT_I2", "getVT(&H7FFF) is not VT_I2") +Call ok(&H8000& = 32768, "&H8000& <> 32768") +Call ok(getVT(&H8000&) = "VT_I4", "getVT(&H8000&) is not VT_I4") Call ok(&h0& = 0, "&h0& <> 0") Call ok(&h00 = 0, "&h00 <> 0") Call ok(&h000000000 = 0, "&h000000000 <> 0") -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10907
From: Francis De Brabandere <francisdb@gmail.com> Native cscript parses every 4-digit hex literal that fits 16 bits as Integer except &H8000: its value -32768 (INT16_MIN) has no positive Int16 representation, so native promotes it to Long. Wine returned Integer for that one case because interp_int narrows any value that fits VT_I2. Skip narrowing for INT16_MIN in interp_int. The only OP_int call site that emits this value is the hex/oct lexer; unary `-32768` is two ops (push 32768, then neg) so it isn't affected. --- dlls/vbscript/interp.c | 6 +++++- dlls/vbscript/tests/lang.vbs | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/dlls/vbscript/interp.c b/dlls/vbscript/interp.c index 219b4fdefda..e8712b343ea 100644 --- a/dlls/vbscript/interp.c +++ b/dlls/vbscript/interp.c @@ -1993,7 +1993,11 @@ static HRESULT interp_int(exec_ctx_t *ctx) TRACE("%ld\n", arg); - if(arg == (INT16)arg) { + /* INT16_MIN is the one I2-fitting value native always parses as Long: it + * has no positive Int16 representation, so &H8000 / decimal 32768 etc. + * produce a Long literal. The only OP_int call site that emits this value + * is the hex/oct lexer; unary `-32768` is two ops (push 32768, then neg). */ + if(arg == (INT16)arg && arg != INT16_MIN) { V_VT(&v) = VT_I2; V_I2(&v) = arg; }else { diff --git a/dlls/vbscript/tests/lang.vbs b/dlls/vbscript/tests/lang.vbs index 01f86406965..ef5b3445b39 100644 --- a/dlls/vbscript/tests/lang.vbs +++ b/dlls/vbscript/tests/lang.vbs @@ -76,7 +76,7 @@ Call ok(&h0 = 0, "&h0 <> 0") ' &H8000 (INT16_MIN bit pattern) is the one 16-bit value parsed as Long, not ' Integer: -32768 has no positive Int16 representation, so native promotes it. Call ok(&H8000 = -32768, "&H8000 <> -32768") -todo_wine_ok getVT(&H8000) = "VT_I4", "getVT(&H8000) is not VT_I4" +Call ok(getVT(&H8000) = "VT_I4", "getVT(&H8000) is not VT_I4") Call ok(&H8001 = -32767, "&H8001 <> -32767") Call ok(getVT(&H8001) = "VT_I2", "getVT(&H8001) is not VT_I2") Call ok(&H7FFF = 32767, "&H7FFF <> 32767") -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10907
participants (2)
-
Francis De Brabandere -
Francis De Brabandere (@francisdb)