Module: wine Branch: master Commit: ea6e0a833b86cbc1b0b518263d529dc4c32f9bcc URL: http://source.winehq.org/git/wine.git/?a=commit;h=ea6e0a833b86cbc1b0b518263d...
Author: Daniel Lehman dlehman@esri.com Date: Mon Apr 16 14:53:43 2012 -0700
gdi32: Use HandleToULong inline function to convert handle to index instead of casting.
---
dlls/gdi32/gdiobj.c | 4 ++-- dlls/gdi32/tests/gdiobj.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-)
diff --git a/dlls/gdi32/gdiobj.c b/dlls/gdi32/gdiobj.c index 14ac692..06279dd 100644 --- a/dlls/gdi32/gdiobj.c +++ b/dlls/gdi32/gdiobj.c @@ -699,7 +699,7 @@ void *free_gdi_handle( HGDIOBJ handle ) GDIOBJHDR *object = NULL; int i;
- i = ((ULONG_PTR)handle >> 2) - FIRST_LARGE_HANDLE; + i = (HandleToULong(handle) >> 2) - FIRST_LARGE_HANDLE; if (i >= 0 && i < MAX_LARGE_HANDLES) { EnterCriticalSection( &gdi_section ); @@ -732,7 +732,7 @@ void *GDI_GetObjPtr( HGDIOBJ handle, WORD type )
EnterCriticalSection( &gdi_section );
- i = ((UINT_PTR)handle >> 2) - FIRST_LARGE_HANDLE; + i = (HandleToULong(handle) >> 2) - FIRST_LARGE_HANDLE; if (i >= 0 && i < MAX_LARGE_HANDLES) { ptr = large_handles[i]; diff --git a/dlls/gdi32/tests/gdiobj.c b/dlls/gdi32/tests/gdiobj.c index c854311..3b9f734 100644 --- a/dlls/gdi32/tests/gdiobj.c +++ b/dlls/gdi32/tests/gdiobj.c @@ -319,10 +319,54 @@ static void test_region(void) DeleteObject(hrgn); }
+static void test_handles_on_win64(void) +{ + int i; + BOOL ret; + DWORD type; + HRGN hrgn, hrgn_test; + + static const struct + { + ULONG high; + ULONG low; + BOOL ret; + } cases[] = + { + { 0x00000000, 0x00000000, TRUE }, + { 0x00000000, 0x0000ffe0, FALSE }, /* just over MAX_LARGE_HANDLES */ + { 0x00000000, 0x0000ffb0, FALSE }, /* just under MAX_LARGE_HANDLES */ + { 0xffffffff, 0xffff0000, FALSE }, + { 0xffffffff, 0x00000000, TRUE }, + { 0xdeadbeef, 0x00000000, TRUE }, + { 0xcccccccc, 0xcccccccc, FALSE } + }; + + if (sizeof(void*) != 8) + return; + + for (i = 0; i < sizeof(cases)/sizeof(cases[0]); i++) + { + hrgn = CreateRectRgn(10, 10, 20, 20); + hrgn_test = (HRGN)(ULONG_PTR)((ULONG_PTR)hrgn | ((ULONGLONG)cases[i].high << 32) | cases[i].low); + type = GetObjectType( hrgn_test ); + if (cases[i].ret) + ok( type == OBJ_REGION, "wrong type %u\n", type ); + else + ok( type == 0, "wrong type %u\n", type ); + ret = DeleteObject(hrgn_test); + ok( cases[i].ret == ret, "DeleteObject should return %s (%p)\n", + cases[i].ret ? "TRUE" : "FALSE", hrgn_test); + /* actually free it if above is expected to fail */ + if (!ret) DeleteObject(hrgn); + } +} + START_TEST(gdiobj) { test_gdi_objects(); test_thread_objects(); test_GetCurrentObject(); test_region(); + test_handles_on_win64(); }