From: Rémi Bernon <rbernon@codeweavers.com> --- dlls/user.exe16/message.c | 15 +++++++-------- dlls/win32u/class.c | 19 ++++++------------- dlls/win32u/ntuser_private.h | 3 +-- dlls/win32u/window.c | 2 +- 4 files changed, 15 insertions(+), 24 deletions(-) diff --git a/dlls/user.exe16/message.c b/dlls/user.exe16/message.c index 584eba0c396..a8531f2f9a7 100644 --- a/dlls/user.exe16/message.c +++ b/dlls/user.exe16/message.c @@ -112,9 +112,9 @@ typedef struct } WINPROC_THUNK; #pragma pack(pop) -#define WINPROC_HANDLE (~0u >> 16) -#define MAX_WINPROCS32 4096 -#define MAX_WINPROCS16 1024 +#define MAKE_WNDPROC16(index) ((WNDPROC)(UINT_PTR)(UINT)MAKELONG(index, 0xffff)) +#define MAX_WINPROCS32 4096 +#define MAX_WINPROCS16 1024 static WNDPROC16 winproc16_array[MAX_WINPROCS16]; static unsigned int winproc16_used; @@ -140,7 +140,7 @@ static int winproc_to_index( WNDPROC16 handle ) else { index = LOWORD(handle); - if ((ULONG_PTR)handle >> 16 != WINPROC_HANDLE) return -1; + if (handle != (WNDPROC16)MAKE_WNDPROC16(index)) return -1; /* check array limits */ if (index >= winproc16_used + MAX_WINPROCS32) return -1; } @@ -191,8 +191,7 @@ WNDPROC WINPROC_AllocProc16( WNDPROC16 func ) if (!func) return NULL; /* check if the function is already a win proc */ - if ((index = winproc_to_index( func )) != -1) - return (WNDPROC)(ULONG_PTR)(index | (WINPROC_HANDLE << 16)); + if ((index = winproc_to_index( func )) != -1) return MAKE_WNDPROC16(index); /* then check if we already have a winproc for that function */ for (index = 0; index < winproc16_used; index++) @@ -206,7 +205,7 @@ WNDPROC WINPROC_AllocProc16( WNDPROC16 func ) winproc16_array[winproc16_used++] = func; done: - ret = (WNDPROC)(ULONG_PTR)((index + MAX_WINPROCS32) | (WINPROC_HANDLE << 16)); + ret = MAKE_WNDPROC16(index + MAX_WINPROCS32); TRACE( "returning %p for %p/16-bit (%d/%d used)\n", ret, func, winproc16_used, MAX_WINPROCS16 ); return ret; @@ -221,7 +220,7 @@ WNDPROC16 WINPROC_GetProc16( WNDPROC proc, BOOL unicode ) { WNDPROC winproc = wow_handlers32.alloc_winproc( proc, unicode ); - if ((ULONG_PTR)winproc >> 16 != WINPROC_HANDLE) return (WNDPROC16)winproc; + if (winproc != MAKE_WNDPROC16(LOWORD(winproc))) return (WNDPROC16)winproc; return alloc_win16_thunk( winproc ); } diff --git a/dlls/win32u/class.c b/dlls/win32u/class.c index 19663e6dce9..1d474a1867b 100644 --- a/dlls/win32u/class.c +++ b/dlls/win32u/class.c @@ -202,18 +202,12 @@ static WINDOWPROC *find_winproc( WNDPROC func, BOOL ansi ) static WINDOWPROC *get_winproc_ptr( WNDPROC handle ) { UINT index = LOWORD(handle); - if ((ULONG_PTR)handle >> 16 != WINPROC_HANDLE) return NULL; + if (handle != MAKE_WNDPROC(index)) return NULL; if (index >= MAX_WINPROCS) return WINPROC_PROC16; if (index >= winproc_used) return NULL; return &winproc_array[index]; } -/* create a handle for a given window proc */ -static inline WNDPROC proc_to_handle( WINDOWPROC *proc ) -{ - return (WNDPROC)(ULONG_PTR)((proc - winproc_array) | (WINPROC_HANDLE << 16)); -} - /* allocate and initialize a new winproc */ static inline WINDOWPROC *alloc_winproc_ptr( WNDPROC func, BOOL ansi ) { @@ -233,13 +227,12 @@ static inline WINDOWPROC *alloc_winproc_ptr( WNDPROC func, BOOL ansi ) proc = &winproc_array[winproc_used++]; if (ansi) proc->procA = func; else proc->procW = func; - TRACE_(win)( "allocated %p for %c %p (%d/%d used)\n", - proc_to_handle(proc), ansi ? 'A' : 'W', func, - winproc_used, MAX_WINPROCS ); + TRACE_(win)( "allocated %p for %c %p (%d/%d used)\n", MAKE_WNDPROC(proc - winproc_array), + ansi ? 'A' : 'W', func, winproc_used, MAX_WINPROCS ); } else WARN_(win)( "too many winprocs, cannot allocate one for %p\n", func ); } - else TRACE_(win)( "reusing %p for %p\n", proc_to_handle(proc), func ); + else TRACE_(win)( "reusing %p for %p\n", MAKE_WNDPROC(proc - winproc_array), func ); pthread_mutex_unlock( &winproc_lock ); return proc; @@ -260,7 +253,7 @@ WNDPROC alloc_winproc( WNDPROC func, BOOL ansi ) if (!(proc = alloc_winproc_ptr( func, ansi ))) return func; if (proc == WINPROC_PROC16) return func; - return proc_to_handle( proc ); + return MAKE_WNDPROC(proc - winproc_array); } /* Get a window procedure pointer that can be passed to the Windows program. */ @@ -1112,7 +1105,7 @@ static void register_builtin( enum ntuser_client_procs proc ) .style = descr->style, .cbWndExtra = descr->extra, .hbrBackground = descr->brush, - .lpfnWndProc = BUILTIN_WINPROC( proc ), + .lpfnWndProc = MAKE_WNDPROC( proc ), }; if (descr->atom) return; /* already registered */ diff --git a/dlls/win32u/ntuser_private.h b/dlls/win32u/ntuser_private.h index 0c7f4802351..e066ef4b5d6 100644 --- a/dlls/win32u/ntuser_private.h +++ b/dlls/win32u/ntuser_private.h @@ -152,8 +152,7 @@ struct scroll_info BOOL painted; /* Whether the scroll bar is painted by DefWinProc() */ }; -#define WINPROC_HANDLE (~0u >> 16) -#define BUILTIN_WINPROC(index) ((WNDPROC)(ULONG_PTR)((index) | (WINPROC_HANDLE << 16))) +#define MAKE_WNDPROC(index) ((WNDPROC)(UINT_PTR)(UINT)MAKELONG(index, 0xffff)) #define MAX_ATOM_LEN 255 diff --git a/dlls/win32u/window.c b/dlls/win32u/window.c index 7afd444a027..70204bf4adb 100644 --- a/dlls/win32u/window.c +++ b/dlls/win32u/window.c @@ -1248,7 +1248,7 @@ static LONG_PTR get_window_long_size( HWND hwnd, INT offset, UINT size, BOOL ans * more tolerant to A/W mismatches. The lack of W->A->W conversion for such a mismatch suggests * that the hack is in GetWindowLongPtr[AW], not in winprocs. */ - if (win->winproc == BUILTIN_WINPROC(NTUSER_WNDPROC_EDIT) && (!!ansi != !(win->flags & WIN_ISUNICODE))) + if (win->winproc == MAKE_WNDPROC(NTUSER_WNDPROC_EDIT) && (!!ansi != !(win->flags & WIN_ISUNICODE))) retval = (ULONG_PTR)win->winproc; else retval = (ULONG_PTR)get_winproc( win->winproc, ansi ); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/11123