[PATCH] msvcrt: Implement __std_type_info_hash

GOUJON Alexandre ale.goujon at gmail.com
Tue Oct 4 15:49:05 CDT 2016


Fixes https://bugs.winehq.org/show_bug.cgi?id=41437

Signed-off-by: GOUJON Alexandre <ale.goujon at gmail.com>
---
 dlls/msvcrt/cpp.c         | 21 ++++++++++++++++-----
 dlls/ucrtbase/tests/cpp.c |  4 +++-
 2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/dlls/msvcrt/cpp.c b/dlls/msvcrt/cpp.c
index 0ffe61e..cc06c07 100644
--- a/dlls/msvcrt/cpp.c
+++ b/dlls/msvcrt/cpp.c
@@ -1591,20 +1591,31 @@ void CDECL MSVCRT_type_info_destroy_list(SLIST_HEADER *header)
 
 /******************************************************************
  *              __std_type_info_hash (UCRTBASE.@)
- *
- * TODO: 64-bit version of the function uses different constants
  */
 MSVCRT_size_t CDECL MSVCRT_type_info_hash(const type_info140 *ti)
 {
-    MSVCRT_size_t hash = 0x811c9dc5;
+    MSVCRT_size_t hash;
+    MSVCRT_size_t fnvPrime;
     const char *p;
 
+    if(sizeof(void*) == sizeof(int))
+    {
+        hash = 0x811c9dc5;
+        fnvPrime = 0x1000193;
+    }
+    else
+    {
+        hash = 0xcbf29ce484222325;
+        fnvPrime = 0x100000001b3;
+    }
+
     TRACE("(%p)->%s\n", ti, ti->mangled);
 
     for(p = ti->mangled+1; *p; p++) {
         hash ^= *p;
-        hash *= 0x1000193;
+        hash *= fnvPrime;
     }
-    return hash;
+
+    return hash ^ (hash >> 32);
 }
 #endif
diff --git a/dlls/ucrtbase/tests/cpp.c b/dlls/ucrtbase/tests/cpp.c
index 1a01fea..659269c 100644
--- a/dlls/ucrtbase/tests/cpp.c
+++ b/dlls/ucrtbase/tests/cpp.c
@@ -163,7 +163,7 @@ static void test___std_type_info(void)
     ti1.mangled[2] = 0;
     hash1 = p___std_type_info_hash(&ti1);
 #ifdef _WIN64
-    todo_wine ok(hash1 == 0xcbf29ce44fd0bfc1, "hash = %p\n", (void*)hash1);
+    ok(hash1 == 0xcbf29ce44fd0bfc1, "hash = %p\n", (void*)hash1);
 #else
     ok(hash1 == 0x811c9dc5, "hash = %p\n", (void*)hash1);
 #endif
@@ -176,6 +176,8 @@ static void test___std_type_info(void)
     hash1 = p___std_type_info_hash(&ti1);
     if(sizeof(void*) == sizeof(int))
         ok(hash1 == 0x40c5b8c, "hash = %p\n", (void*)hash1);
+    else
+        ok(hash1 == 0xaf63bc4c29620a60, "hash = %p\n", (void*)hash1);
     ok(hash1 != hash2, "hash1 == hash2 for different strings\n");
 
     ti1.mangled[1] = 2;
-- 
2.7.4




More information about the wine-patches mailing list