Based on @rbernon's [branch](https://gitlab.winehq.org/rbernon/wine/-/tree/wip/libc++-fixes).
From: Rémi Bernon rbernon@codeweavers.com
--- include/msvcrt/ctype.h | 7 +++++++ include/msvcrt/stdlib.h | 3 +++ 2 files changed, 10 insertions(+)
diff --git a/include/msvcrt/ctype.h b/include/msvcrt/ctype.h index 88e79411f64..5cfe312ea6d 100644 --- a/include/msvcrt/ctype.h +++ b/include/msvcrt/ctype.h @@ -50,6 +50,13 @@ _ACRTIMP int __cdecl isxdigit(int); _ACRTIMP int __cdecl tolower(int); _ACRTIMP int __cdecl toupper(int);
+#ifndef MB_CUR_MAX +_ACRTIMP int __cdecl ___mb_cur_max_func(void); +_ACRTIMP int __cdecl ___mb_cur_max_l_func(_locale_t); +#define __mb_cur_max ___mb_cur_max_func() +#define MB_CUR_MAX ___mb_cur_max_func() +#endif /* MB_CUR_MAX */ + #ifdef __cplusplus } #endif diff --git a/include/msvcrt/stdlib.h b/include/msvcrt/stdlib.h index 9cb8ccb110a..8d64246c0b5 100644 --- a/include/msvcrt/stdlib.h +++ b/include/msvcrt/stdlib.h @@ -121,10 +121,13 @@ extern unsigned int _fmode;
#endif /* __i386__ */
+#ifndef MB_CUR_MAX _ACRTIMP int __cdecl ___mb_cur_max_func(void); _ACRTIMP int __cdecl ___mb_cur_max_l_func(_locale_t); #define __mb_cur_max ___mb_cur_max_func() #define MB_CUR_MAX ___mb_cur_max_func() +#endif /* MB_CUR_MAX */ + _ACRTIMP __msvcrt_ulong* __cdecl __doserrno(void); #define _doserrno (*__doserrno()) _ACRTIMP int* __cdecl _errno(void);
From: Rémi Bernon rbernon@codeweavers.com
--- include/msvcrt/intrin.h | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/include/msvcrt/intrin.h b/include/msvcrt/intrin.h index ba825b7b09e..178c85ff59e 100644 --- a/include/msvcrt/intrin.h +++ b/include/msvcrt/intrin.h @@ -90,6 +90,14 @@ unsigned __int64 __getReg(int);
#endif
+#if defined(_MSC_VER) +unsigned char _BitScanForward(unsigned long*,unsigned long); +#endif + +#if defined(_MSC_VER) && (defined(__x86_64__) || defined(__aarch64__)) +unsigned char _BitScanForward64(unsigned long*,unsigned __int64); +#endif + #ifdef __cplusplus } #endif
From: Rémi Bernon rbernon@codeweavers.com
--- include/guiddef.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/include/guiddef.h b/include/guiddef.h index 0837ed34ad7..b9ae4de8ae9 100644 --- a/include/guiddef.h +++ b/include/guiddef.h @@ -158,10 +158,10 @@ typedef GUID FMTID,*LPFMTID; #define IsEqualGUID(rguid1, rguid2) (!memcmp(&(rguid1), &(rguid2), sizeof(GUID))) inline int InlineIsEqualGUID(REFGUID rguid1, REFGUID rguid2) { - return (((unsigned int *)&rguid1)[0] == ((unsigned int *)&rguid2)[0] && - ((unsigned int *)&rguid1)[1] == ((unsigned int *)&rguid2)[1] && - ((unsigned int *)&rguid1)[2] == ((unsigned int *)&rguid2)[2] && - ((unsigned int *)&rguid1)[3] == ((unsigned int *)&rguid2)[3]); + return (((const unsigned int *)&rguid1)[0] == ((const unsigned int *)&rguid2)[0] && + ((const unsigned int *)&rguid1)[1] == ((const unsigned int *)&rguid2)[1] && + ((const unsigned int *)&rguid1)[2] == ((const unsigned int *)&rguid2)[2] && + ((const unsigned int *)&rguid1)[3] == ((const unsigned int *)&rguid2)[3]); } #else #define IsEqualGUID(rguid1, rguid2) (!memcmp(rguid1, rguid2, sizeof(GUID)))
From: Rémi Bernon rbernon@codeweavers.com
--- include/msvcrt/corecrt.h | 9 +++++++++ include/msvcrt/wchar.h | 12 ++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/include/msvcrt/corecrt.h b/include/msvcrt/corecrt.h index 8f6ed6ae6c6..6fc7da0846c 100644 --- a/include/msvcrt/corecrt.h +++ b/include/msvcrt/corecrt.h @@ -250,6 +250,15 @@ typedef int errno_t; #define _ERRNO_T_DEFINED #endif
+#ifndef _CONST_RETURN +# ifdef __cplusplus +# define _CONST_RETURN const +# define _CRT_CONST_CORRECT_OVERLOADS +# else +# define _CONST_RETURN +# endif +#endif + struct threadlocaleinfostruct; struct threadmbcinfostruct; typedef struct threadlocaleinfostruct *pthreadlocinfo; diff --git a/include/msvcrt/wchar.h b/include/msvcrt/wchar.h index 4ca189bd2c7..98167b59076 100644 --- a/include/msvcrt/wchar.h +++ b/include/msvcrt/wchar.h @@ -45,14 +45,22 @@ int __cdecl wctob(wint_t);
_ACRTIMP errno_t __cdecl wmemcpy_s(wchar_t *, size_t, const wchar_t *, size_t);
-static inline wchar_t *wmemchr(const wchar_t *s, wchar_t c, size_t n) +static inline _CONST_RETURN wchar_t *wmemchr(const wchar_t *s, wchar_t c, size_t n) { const wchar_t *end; for (end = s + n; s < end; s++) - if (*s == c) return (wchar_t*)s; + if (*s == c) return (_CONST_RETURN wchar_t *)s; return NULL; }
+#ifdef __cplusplus +extern "C++" inline wchar_t *wmemchr(wchar_t *s, wchar_t c, size_t n) +{ + wchar_t const* s_const = s; + return const_cast<wchar_t *>(wmemchr(s_const, c, n)); +} +#endif + static inline int wmemcmp(const wchar_t *s1, const wchar_t *s2, size_t n) { size_t i;
From: Jacek Caban jacek@codeweavers.com
Avoids conflict with FILE_DISPOSITION_INFO and matches Windows SDK. --- dlls/kernel32/tests/file.c | 2 -- dlls/scrrun/scrrun.idl | 1 - dlls/scrrun/tests/scrrun.idl | 1 - include/winbase.h | 11 ++++++++++- 4 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/dlls/kernel32/tests/file.c b/dlls/kernel32/tests/file.c index b651fc1a1ba..68b9f53700e 100644 --- a/dlls/kernel32/tests/file.c +++ b/dlls/kernel32/tests/file.c @@ -35,8 +35,6 @@ #include "winnls.h" #include "fileapi.h"
-#undef DeleteFile /* needed for FILE_DISPOSITION_INFO */ - static HANDLE (WINAPI *pFindFirstFileExA)(LPCSTR,FINDEX_INFO_LEVELS,LPVOID,FINDEX_SEARCH_OPS,LPVOID,DWORD); static BOOL (WINAPI *pReplaceFileW)(LPCWSTR, LPCWSTR, LPCWSTR, DWORD, LPVOID, LPVOID); static UINT (WINAPI *pGetSystemWindowsDirectoryA)(LPSTR, UINT); diff --git a/dlls/scrrun/scrrun.idl b/dlls/scrrun/scrrun.idl index 061d924d162..f369f2d985a 100644 --- a/dlls/scrrun/scrrun.idl +++ b/dlls/scrrun/scrrun.idl @@ -24,7 +24,6 @@ import "oaidl.idl";
cpp_quote("#ifdef WINE_NO_UNICODE_MACROS") cpp_quote("#undef CopyFile") -cpp_quote("#undef DeleteFile") cpp_quote("#undef MoveFile") cpp_quote("#endif") /* this is not defined in public headers */ diff --git a/dlls/scrrun/tests/scrrun.idl b/dlls/scrrun/tests/scrrun.idl index 86ac9e320d7..9b65aff1d5b 100644 --- a/dlls/scrrun/tests/scrrun.idl +++ b/dlls/scrrun/tests/scrrun.idl @@ -24,7 +24,6 @@ import "oaidl.idl";
cpp_quote("#ifdef WINE_NO_UNICODE_MACROS") cpp_quote("#undef CopyFile") -cpp_quote("#undef DeleteFile") cpp_quote("#undef MoveFile") cpp_quote("#endif") /* this is not defined in public headers */ diff --git a/include/winbase.h b/include/winbase.h index 40d973dd546..5ccf9551ece 100644 --- a/include/winbase.h +++ b/include/winbase.h @@ -2012,7 +2012,16 @@ WINBASEAPI void WINAPI DeleteCriticalSection(CRITICAL_SECTION *lpCrit); WINBASEAPI void WINAPI DeleteFiber(LPVOID); WINBASEAPI BOOL WINAPI DeleteFileA(LPCSTR); WINBASEAPI BOOL WINAPI DeleteFileW(LPCWSTR); -#define DeleteFile WINELIB_NAME_AW(DeleteFile) +#ifndef WINE_NO_UNICODE_MACROS +static inline BOOL DeleteFile( LPCTSTR file_name ) +{ +#ifdef UNICODE + return DeleteFileW( file_name ); +#else + return DeleteFileA( file_name ); +#endif +} +#endif WINBASEAPI void WINAPI DeleteProcThreadAttributeList(struct _PROC_THREAD_ATTRIBUTE_LIST*); WINBASEAPI BOOL WINAPI DeleteTimerQueue(HANDLE); WINBASEAPI BOOL WINAPI DeleteTimerQueueEx(HANDLE,HANDLE);
This merge request was approved by Jacek Caban.
Nikolay Sivov (@nsivov) commented about dlls/scrrun/scrrun.idl:
cpp_quote("#ifdef WINE_NO_UNICODE_MACROS") cpp_quote("#undef CopyFile") -cpp_quote("#undef DeleteFile") cpp_quote("#undef MoveFile") cpp_quote("#endif")
It's not important for what you're fixing most likely, but CopyFile/MoveFile are also using inline functions in SDK, so we can get rid of this block in principle. SDK also has an undef, but then again inlines are guarded with _M_CEE which we probably don't really care about.
On Mon Mar 3 15:49:29 2025 +0000, Nikolay Sivov wrote:
It's not important for what you're fixing most likely, but CopyFile/MoveFile are also using inline functions in SDK, so we can get rid of this block in principle. SDK also has an undef, but then again inlines are guarded with _M_CEE which we probably don't really care about.
Yes, I was planning to change those too.