ucrtbase: Add __std_type_info_hash implementation.

Signed-off-by: Piotr Caban <piotr@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Piotr Caban 2016-09-14 15:34:02 +02:00 committed by Alexandre Julliard
parent 631fd7ffcc
commit 4931e6f92b
5 changed files with 52 additions and 3 deletions

View File

@ -46,7 +46,7 @@
@ cdecl __std_exception_destroy(ptr) ucrtbase.__std_exception_destroy
@ cdecl __std_type_info_compare(ptr ptr) ucrtbase.__std_type_info_compare
@ cdecl __std_type_info_destroy_list(ptr) ucrtbase.__std_type_info_destroy_list
@ stub __std_type_info_hash
@ cdecl __std_type_info_hash(ptr) ucrtbase.__std_type_info_hash
@ cdecl __std_type_info_name(ptr ptr) ucrtbase.__std_type_info_name
@ cdecl __unDName(ptr str long ptr ptr long) ucrtbase.__unDName
@ cdecl __unDNameEx(ptr str long ptr ptr ptr long) ucrtbase.__unDNameEx

View File

@ -1588,4 +1588,23 @@ void CDECL MSVCRT_type_info_destroy_list(SLIST_HEADER *header)
MSVCRT_free(cur);
}
}
/******************************************************************
* __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;
const char *p;
TRACE("(%p)->%s\n", ti, ti->mangled);
for(p = ti->mangled+1; *p; p++) {
hash ^= *p;
hash *= 0x1000193;
}
return hash;
}
#endif

View File

@ -51,6 +51,7 @@ static void (CDECL *p___std_exception_destroy)(__std_exception_data*);
static int (CDECL *p___std_type_info_compare)(const type_info140*, const type_info140*);
static const char* (CDECL *p___std_type_info_name)(type_info140*, SLIST_HEADER*);
static void (CDECL *p___std_type_info_destroy_list)(SLIST_HEADER*);
static size_t (CDECL *p___std_type_info_hash)(type_info140*);
static BOOL init(void)
@ -70,6 +71,7 @@ static BOOL init(void)
p___std_type_info_compare = (void*)GetProcAddress(module, "__std_type_info_compare");
p___std_type_info_name = (void*)GetProcAddress(module, "__std_type_info_name");
p___std_type_info_destroy_list = (void*)GetProcAddress(module, "__std_type_info_destroy_list");
p___std_type_info_hash = (void*)GetProcAddress(module, "__std_type_info_hash");
return TRUE;
}
@ -125,6 +127,7 @@ static void test___std_type_info(void)
SLIST_HEADER header;
type_info_list *elem;
const char *ret;
size_t hash1, hash2;
int eq;
@ -154,6 +157,33 @@ static void test___std_type_info(void)
eq = p___std_type_info_compare(&ti1, &ti3);
ok(eq == 0, "__std_type_info_compare(&ti1, &ti3) = %d\n", eq);
ti1.mangled[0] = 0;
ti1.mangled[1] = 0;
ti1.mangled[2] = 0;
hash1 = p___std_type_info_hash(&ti1);
#ifdef _WIN64
todo_wine ok(hash1 == 0xcbf29ce44fd0bfc1, "hash = %p\n", (void*)hash1);
#else
ok(hash1 == 0x811c9dc5, "hash = %p\n", (void*)hash1);
#endif
ti1.mangled[0] = 1;
hash2 = p___std_type_info_hash(&ti1);
ok(hash1 == hash2, "hash1 != hash2 (first char not ignorred)\n");
ti1.mangled[1] = 1;
hash1 = p___std_type_info_hash(&ti1);
if(sizeof(void*) == sizeof(int))
ok(hash1 == 0x40c5b8c, "hash = %p\n", (void*)hash1);
ok(hash1 != hash2, "hash1 == hash2 for different strings\n");
ti1.mangled[1] = 2;
hash2 = p___std_type_info_hash(&ti1);
ok(hash1 != hash2, "hash1 == hash2 for different strings\n");
hash1 = p___std_type_info_hash(&ti2);
ok(hash1 != hash2, "hash1 == hash2 for different strings\n");
}
START_TEST(cpp)

View File

@ -144,7 +144,7 @@
@ cdecl __std_exception_destroy(ptr) MSVCRT___std_exception_destroy
@ cdecl __std_type_info_compare(ptr ptr) MSVCRT_type_info_compare
@ cdecl __std_type_info_destroy_list(ptr) MSVCRT_type_info_destroy_list
@ stub __std_type_info_hash
@ cdecl __std_type_info_hash(ptr) MSVCRT_type_info_hash
@ cdecl __std_type_info_name(ptr ptr) MSVCRT_type_info_name_list
@ cdecl __stdio_common_vfprintf(int64 ptr str ptr ptr) MSVCRT__stdio_common_vfprintf
@ stub __stdio_common_vfprintf_p

View File

@ -41,7 +41,7 @@
@ stub __std_terminate
@ cdecl __std_type_info_compare(ptr ptr) ucrtbase.__std_type_info_compare
@ cdecl __std_type_info_destroy_list(ptr) ucrtbase.__std_type_info_destroy_list
@ stub __std_type_info_hash
@ cdecl __std_type_info_hash(ptr) ucrtbase.__std_type_info_hash
@ cdecl __std_type_info_name(ptr ptr) ucrtbase.__std_type_info_name
@ cdecl __telemetry_main_invoke_trigger(ptr)
@ cdecl __telemetry_main_return_trigger(ptr)