On Win2k rand_s is not supported, would it be possible
to apply attached patch? (diff against qt-copy).
With this patch I don't see any problems on Win2k,
without it crashes on startup.
See also
http://bugs.webkit.org/show_bug.cgi?id=17032
Thanks,
Peter
Index: JavaScriptCore/wtf/MathExtras.cpp
===================================================================
--- JavaScriptCore/wtf/MathExtras.cpp (revision 0)
+++ JavaScriptCore/wtf/MathExtras.cpp (revision 0)
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if COMPILER(MSVC)
+#ifdef _CRT_RAND_S
+
+#include "MathExtras.h"
+#include <windows.h>
+
+bool rand_s_exists;
+static bool already_checked = false;
+
+void check_for_rand_s()
+{
+ if (!already_checked) {
+ HMODULE dll = LoadLibraryA("ADVAPI32.DLL");
+ if (dll) {
+ if (GetProcAddress(dll, "RtlGenRandom") ) {
+ rand_s_exists = true;
+ } else {
+ rand_s_exists = false;
+ }
+ FreeLibrary(dll);
+ }
+ already_checked = true;
+ }
+}
+
+#endif
+#endif
Index: JavaScriptCore/wtf/MathExtras.h
===================================================================
--- JavaScriptCore/wtf/MathExtras.h (revision 793374)
+++ JavaScriptCore/wtf/MathExtras.h (working copy)
@@ -118,18 +118,23 @@
#if defined(_CRT_RAND_S)
// Initializes the random number generator.
-inline void wtf_random_init()
-{
- // No need to initialize for rand_s.
+extern bool rand_s_exists;
+extern void check_for_rand_s();
+inline void wtf_random_init()
+{
+ // under Win2K there is no rand_s
+ check_for_rand_s();
}
// Returns a pseudo-random number in the range [0, 1).
inline double wtf_random()
{
- unsigned u;
- rand_s(&u);
-
- return static_cast<double>(u) / (static_cast<double>(UINT_MAX) + 1.0);
+ if (rand_s_exists) {
+ unsigned u;
+ rand_s(&u);
+ return static_cast<double>(u) / (static_cast<double>(UINT_MAX) + 1.0);
+ }
+ return static_cast<double>(rand()) / (static_cast<double>(RAND_MAX) + 1.0);
}
#endif // _CRT_RAND_S
Index: JavaScriptCore/JavaScriptCore.pri
===================================================================
--- JavaScriptCore/JavaScriptCore.pri (revision 793374)
+++ JavaScriptCore/JavaScriptCore.pri (working copy)
@@ -35,6 +35,7 @@
wtf/Assertions.cpp \
wtf/HashTable.cpp \
wtf/FastMalloc.cpp \
+ wtf/MathExtras.cpp \
bindings/NP_jsobject.cpp \
bindings/npruntime.cpp \
bindings/runtime_array.cpp \