Jacek Caban : vbscript: Added VT_R8 support to to_int.

Alexandre Julliard julliard at winehq.org
Wed Sep 26 14:06:51 CDT 2012


Module: wine
Branch: master
Commit: 1fc2896c7c57e6feb8dbcf6156da1f505ad2668e
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=1fc2896c7c57e6feb8dbcf6156da1f505ad2668e

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Wed Sep 26 14:36:15 2012 +0200

vbscript: Added VT_R8 support to to_int.

---

 dlls/vbscript/global.c      |    9 +++++++++
 dlls/vbscript/tests/api.vbs |   12 ++++++++++++
 dlls/vbscript/vbscript.h    |   13 +++++++++++++
 3 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/dlls/vbscript/global.c b/dlls/vbscript/global.c
index 0facdf0..6e62a34 100644
--- a/dlls/vbscript/global.c
+++ b/dlls/vbscript/global.c
@@ -125,6 +125,15 @@ static HRESULT to_int(VARIANT *v, int *ret)
     case VT_I4:
         *ret = V_I4(v);
         break;
+    case VT_R8: {
+        double n = round(V_R8(v));
+        if(!is_int32(n)) {
+            FIXME("%lf is out of int range\n", n);
+            return E_FAIL;
+        }
+        *ret = n;
+        break;
+    }
     default:
         FIXME("not supported %s\n", debugstr_variant(v));
         return E_NOTIMPL;
diff --git a/dlls/vbscript/tests/api.vbs b/dlls/vbscript/tests/api.vbs
index f7b4295..5efde28 100644
--- a/dlls/vbscript/tests/api.vbs
+++ b/dlls/vbscript/tests/api.vbs
@@ -124,6 +124,15 @@ Call ok(isNull(x), "InStr returned " & x)
 x = InStr(2, null, "abcd")
 Call ok(isNull(x), "InStr returned " & x)
 
+x = InStr(1.3, "abcd", "bc")
+Call ok(x = 2, "InStr returned " & x)
+
+x = InStr(2.3, "abcd", "bc")
+Call ok(x = 2, "InStr returned " & x)
+
+x = InStr(2.6, "abcd", "bc")
+Call ok(x = 0, "InStr returned " & x)
+
 Sub TestMid(str, start, len, ex)
     x = Mid(str, start, len)
     Call ok(x = ex, "Mid(" & str & ", " & start & ", " & len & ") = " & x & " expected " & ex)
@@ -182,6 +191,9 @@ Call ok(Len(empty) = 0, "Len(empty) = " & Len(empty))
 Call ok(Space(1) = " ", "Space(1) = " & Space(1) & """")
 Call ok(Space(0) = "", "Space(0) = " & Space(0) & """")
 Call ok(Space(5) = "     ", "Space(5) = " & Space(5) & """")
+Call ok(Space(5.2) = "     ", "Space(5.2) = " & Space(5.2) & """")
+Call ok(Space(5.8) = "      ", "Space(5.8) = " & Space(5.8) & """")
+Call ok(Space(5.5) = "      ", "Space(5.5) = " & Space(5.5) & """")
 
 Sub TestRound(val, exval, vt)
     Call ok(Round(val) = exval, "Round(" & val & ") = " & Round(val))
diff --git a/dlls/vbscript/vbscript.h b/dlls/vbscript/vbscript.h
index 77cf0e7..41982da 100644
--- a/dlls/vbscript/vbscript.h
+++ b/dlls/vbscript/vbscript.h
@@ -343,6 +343,19 @@ TID_LIST
 
 HRESULT get_typeinfo(tid_t,ITypeInfo**) DECLSPEC_HIDDEN;
 
+#ifndef INT32_MIN
+#define INT32_MIN (-2147483647-1)
+#endif
+
+#ifndef INT32_MAX
+#define INT32_MAX (2147483647)
+#endif
+
+static inline BOOL is_int32(double d)
+{
+    return INT32_MIN <= d && d <= INT32_MAX && (double)(int)d == d;
+}
+
 HRESULT WINAPI VBScriptFactory_CreateInstance(IClassFactory*,IUnknown*,REFIID,void**) DECLSPEC_HIDDEN;
 
 const char *debugstr_variant(const VARIANT*) DECLSPEC_HIDDEN;




More information about the wine-cvs mailing list