diff --git a/CMakeLists.txt b/CMakeLists.txt index 0711fe9..3276ae9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,7 +55,11 @@ endif() # Compiler flags handling include(sdk/cmake/compilerflags.cmake) -add_definitions(-D__REACTOS__) +add_definitions( + -D__REACTOS__ + # swprintf without count argument is used in most of the codebase + -D_CRT_NON_CONFORMING_SWPRINTFS +) # Double escape, since CMake unescapes before putting it on the command-line, where it's unescaped again by GCC/CL. add_definitions(-DREACTOS_SOURCE_DIR="${REACTOS_SOURCE_DIR}") diff --git a/modules/rostests/tests/CMakeLists.txt b/modules/rostests/tests/CMakeLists.txt index 7816434..d29a8ad 100644 --- a/modules/rostests/tests/CMakeLists.txt +++ b/modules/rostests/tests/CMakeLists.txt @@ -1,6 +1,3 @@ add_subdirectory(mmixer_test) -if(NOT MSVC) - add_subdirectory(pseh2) -endif() add_subdirectory(dllexport) add_subdirectory(spec2def) diff --git a/modules/rostests/winetests/msvcrt/printf.c b/modules/rostests/winetests/msvcrt/printf.c index d8a82a0..4bf55af 100644 --- a/modules/rostests/winetests/msvcrt/printf.c +++ b/modules/rostests/winetests/msvcrt/printf.c @@ -23,7 +23,9 @@ /* With Visual Studio >= 2005, swprintf() takes an extra parameter unless * the following macro is defined. */ +#ifndef _CRT_NON_CONFORMING_SWPRINTFS #define _CRT_NON_CONFORMING_SWPRINTFS +#endif #include #include diff --git a/sdk/include/crt/stdio.h b/sdk/include/crt/stdio.h index 40dd62a..495c7b3 100644 --- a/sdk/include/crt/stdio.h +++ b/sdk/include/crt/stdio.h @@ -122,6 +122,13 @@ extern "C" { #endif +#if defined(_M_IX86) // newer Windows versions always have it +_CRTIMP int* __cdecl __p__commode(void); +#endif + +/* On newer Windows windows versions, (*__p__commode()) is used */ +extern _CRTIMP int _commode; + #define _IOREAD 0x0001 #define _IOWRT 0x0002 @@ -391,8 +398,8 @@ extern "C" { _In_ __int64 _Offset, _In_ int _Origin); - _Check_return_ __MINGW_EXTENSION + _Check_return_ _CRTIMP __int64 __cdecl @@ -886,6 +893,7 @@ extern "C" { _In_z_ _Printf_format_string_ const wchar_t *_Format, va_list _ArgList); +#if defined __cplusplus || defined _CRT_NON_CONFORMING_SWPRINTFS _Check_return_opt_ _CRTIMP int @@ -902,6 +910,7 @@ extern "C" { _Out_ wchar_t*, const wchar_t*, va_list); +#endif _Check_return_opt_ _CRTIMP @@ -949,15 +958,38 @@ extern "C" { #include #endif -#if 0 //this is for MSVCRT80 and higher, which we don't use nor implement -#ifdef _CRT_NON_CONFORMING_SWPRINTFS -#ifndef __cplusplus -#define swprintf _swprintf -#define vswprintf _vswprintf -#define _swprintf_l __swprintf_l -#define _vswprintf_l __vswprintf_l -#endif -#endif +#ifndef _CRT_NON_CONFORMING_SWPRINTFS + _Check_return_opt_ + static inline + int + __cdecl + swprintf( + _Out_writes_z_(_SizeInWords) wchar_t* _DstBuf, + _In_ size_t _SizeInWords, + _In_z_ _Printf_format_string_ const wchar_t* _Format, + ...) + { + int ret; + va_list args; + + va_start(args, _Format); + ret = _vsnwprintf(_DstBuf, _SizeInWords, _Format, args); + va_end(args); + return ret; + } + + _Check_return_opt_ + static inline + int + __cdecl + vswprintf( + _Out_writes_z_(_SizeInWords) wchar_t* _DstBuf, + _In_ size_t _SizeInWords, + _In_z_ _Printf_format_string_ const wchar_t* _Format, + va_list _ArgList) + { + return _vsnwprintf(_DstBuf, _SizeInWords, _Format, _ArgList); + } #endif _Check_return_ @@ -1186,8 +1218,8 @@ extern "C" { _In_ __int64 _Offset, _In_ int _Origin); - _Check_return_ __MINGW_EXTENSION + _Check_return_ _CRTIMP __int64 __cdecl diff --git a/sdk/include/crt/wchar.h b/sdk/include/crt/wchar.h index eadde09..c6cd0d7 100644 --- a/sdk/include/crt/wchar.h +++ b/sdk/include/crt/wchar.h @@ -128,14 +128,6 @@ extern "C" { #define _WFINDDATA_T_DEFINED #endif /* !_WFINDDATA_T_DEFINED */ -#ifndef NULL -#ifdef __cplusplus -#define NULL 0 -#else -#define NULL ((void *)0) -#endif -#endif - #ifndef _CRT_CTYPEDATA_DEFINED # define _CRT_CTYPEDATA_DEFINED # ifndef _CTYPE_DISABLE_MACROS @@ -1080,6 +1072,7 @@ _CRTIMP int __cdecl iswblank(wint_t _C); _In_z_ _Printf_format_string_ const wchar_t *_Format, va_list _ArgList); +#if defined __cplusplus || defined _CRT_NON_CONFORMING_SWPRINTFS _CRTIMP int __cdecl @@ -1095,6 +1088,7 @@ _CRTIMP int __cdecl iswblank(wint_t _C); _Out_ wchar_t*, const wchar_t*, va_list); +#endif _Check_return_opt_ _CRTIMP @@ -1386,15 +1380,38 @@ _CRTIMP int __cdecl iswblank(wint_t _C); _CRTIMP int __cdecl __swprintf_l(wchar_t *_Dest,const wchar_t *_Format,_locale_t _Plocinfo,...); _CRTIMP int __cdecl __vswprintf_l(wchar_t *_Dest,const wchar_t *_Format,_locale_t _Plocinfo,va_list _Args); -#if 0 //this is for MSVCRT80 and higher, which we don't use nor implement -#ifdef _CRT_NON_CONFORMING_SWPRINTFS -#ifndef __cplusplus -#define swprintf _swprintf -#define vswprintf _vswprintf -#define _swprintf_l __swprintf_l -#define _vswprintf_l __vswprintf_l -#endif -#endif +#ifndef _CRT_NON_CONFORMING_SWPRINTFS + _Check_return_opt_ + static inline + int + __cdecl + swprintf( + _Out_writes_z_(_SizeInWords) wchar_t* _DstBuf, + _In_ size_t _SizeInWords, + _In_z_ _Printf_format_string_ const wchar_t* _Format, + ...) + { + int ret; + va_list args; + + va_start(args, _Format); + ret = _vsnwprintf(_DstBuf, _SizeInWords, _Format, args); + va_end(args); + return ret; + } + + _Check_return_opt_ + static inline + int + __cdecl + vswprintf( + _Out_writes_z_(_SizeInWords) wchar_t* _DstBuf, + _In_ size_t _SizeInWords, + _In_z_ _Printf_format_string_ const wchar_t* _Format, + va_list _ArgList) + { + return _vsnwprintf(_DstBuf, _SizeInWords, _Format, _ArgList); + } #endif _Check_return_ @@ -1761,16 +1778,16 @@ _CRTIMP int __cdecl iswblank(wint_t _C); _Pre_notnull_ _Post_z_ wchar_t *_DstBuf, _In_ int _Radix); - _Check_return_ __MINGW_EXTENSION + _Check_return_ _CRTIMP __int64 __cdecl _wtoi64( _In_z_ const wchar_t *_Str); - _Check_return_ __MINGW_EXTENSION + _Check_return_ _CRTIMP __int64 __cdecl @@ -1778,8 +1795,8 @@ _CRTIMP int __cdecl iswblank(wint_t _C); _In_z_ const wchar_t *_Str, _In_opt_ _locale_t _Locale); - _Check_return_ __MINGW_EXTENSION + _Check_return_ _CRTIMP __int64 __cdecl @@ -1788,8 +1805,8 @@ _CRTIMP int __cdecl iswblank(wint_t _C); _Out_opt_ _Deref_post_z_ wchar_t **_EndPtr, _In_ int _Radix); - _Check_return_ __MINGW_EXTENSION + _Check_return_ _CRTIMP __int64 __cdecl @@ -1799,8 +1816,8 @@ _CRTIMP int __cdecl iswblank(wint_t _C); _In_ int _Radix, _In_opt_ _locale_t _Locale); - _Check_return_ __MINGW_EXTENSION + _Check_return_ _CRTIMP unsigned __int64 __cdecl @@ -1809,8 +1826,8 @@ _CRTIMP int __cdecl iswblank(wint_t _C); _Out_opt_ _Deref_post_z_ wchar_t **_EndPtr, _In_ int _Radix); - _Check_return_ __MINGW_EXTENSION + _Check_return_ _CRTIMP unsigned __int64 __cdecl @@ -1929,6 +1946,7 @@ _CRTIMP int __cdecl iswblank(wint_t _C); _In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_Control); + _CRTIMP size_t __cdecl wcslen( diff --git a/sdk/include/reactos/wine/debug.h b/sdk/include/reactos/wine/debug.h index 35aefc9..fc39141 100644 --- a/sdk/include/reactos/wine/debug.h +++ b/sdk/include/reactos/wine/debug.h @@ -22,6 +22,7 @@ #define __WINE_DEBUG_H #include +#include #include #ifndef GUID_DEFINED #include diff --git a/sdk/include/reactos/wine/test.h b/sdk/include/reactos/wine/test.h index 5eb52d8..414215a 100644 --- a/sdk/include/reactos/wine/test.h +++ b/sdk/include/reactos/wine/test.h @@ -62,6 +62,7 @@ extern int winetest_interactive; extern const char *winetest_platform; extern void winetest_set_location( const char* file, int line ); +extern void winetest_subtest(const char* name); extern void winetest_start_todo( int is_todo ); extern int winetest_loop_todo(void); extern void winetest_end_todo(void); @@ -75,6 +76,7 @@ extern void winetest_add_failures( LONG new_failures ); extern void winetest_wait_child_process( HANDLE process ); extern const char *wine_dbgstr_wn( const WCHAR *str, intptr_t n ); +extern const char *wine_dbgstr_an( const CHAR *str, intptr_t n ); extern const char *wine_dbgstr_guid( const GUID *guid ); extern const char *wine_dbgstr_point( const POINT *guid ); extern const char *wine_dbgstr_size( const SIZE *guid ); @@ -82,6 +84,9 @@ extern const char *wine_dbgstr_rect( const RECT *rect ); #ifdef WINETEST_USE_DBGSTR_LONGLONG extern const char *wine_dbgstr_longlong( ULONGLONG ll ); #endif +static inline const char *debugstr_a( const char *s ) { return wine_dbgstr_an( s, -1 ); } +static inline const char *debugstr_an( const CHAR *s, intptr_t n ) { return wine_dbgstr_an( s, n ); } +static inline const char *wine_dbgstr_a( const char *s ) { return wine_dbgstr_an( s, -1 ); } static inline const char *wine_dbgstr_w( const WCHAR *s ) { return wine_dbgstr_wn( s, -1 ); } /* strcmpW is available for tests compiled under Wine, but not in standalone @@ -128,6 +133,8 @@ extern void __winetest_cdecl winetest_skip( const char *msg, ... ) __attribute__ extern void __winetest_cdecl winetest_win_skip( const char *msg, ... ) __attribute__((format (printf,1,2))); extern void __winetest_cdecl winetest_trace( const char *msg, ... ) __attribute__((format (printf,1,2))); extern void __winetest_cdecl winetest_print(const char* msg, ...) __attribute__((format(printf, 1, 2))); +extern void __winetest_cdecl winetest_push_context( const char *fmt, ... ) __attribute__((format(printf, 1, 2))); +extern void winetest_pop_context(void); #else /* __GNUC__ */ # define WINETEST_PRINTF_ATTR(fmt,args) @@ -136,14 +143,18 @@ extern void __winetest_cdecl winetest_skip( const char *msg, ... ); extern void __winetest_cdecl winetest_win_skip( const char *msg, ... ); extern void __winetest_cdecl winetest_trace( const char *msg, ... ); extern void __winetest_cdecl winetest_print(const char* msg, ...); +extern void __winetest_cdecl winetest_push_context( const char *fmt, ... ); +extern void winetest_pop_context(void); #endif /* __GNUC__ */ +#define subtest_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : winetest_subtest #define ok_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : winetest_ok #define skip_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : winetest_skip #define win_skip_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : winetest_win_skip #define trace_(file, line) (winetest_set_location(file, line), 0) ? (void)0 : winetest_trace +#define subtest subtest_(__FILE__, __LINE__) #define ok ok_(__FILE__, __LINE__) #define skip skip_(__FILE__, __LINE__) #define win_skip win_skip_(__FILE__, __LINE__) @@ -281,6 +292,8 @@ typedef struct int todo_do_loop; char *str_pos; /* position in debug buffer */ char strings[2000]; /* buffer for debug strings */ + char context[8][128]; /* data to print before messages */ + unsigned int context_count; /* number of context prefixes */ } tls_data; static DWORD tls_index; @@ -343,6 +356,39 @@ void winetest_set_location( const char* file, int line ) data->current_line=line; } +#ifdef __GNUC__ +static void __winetest_cdecl winetest_printf( const char *msg, ... ) __attribute__((format(printf,1,2))); +#else +static void __winetest_cdecl winetest_printf(const char* msg, ...); +#endif +static void __winetest_cdecl winetest_printf( const char *msg, ... ) +{ + tls_data *data = get_tls_data(); + __winetest_va_list valist; + + fprintf( stdout, __winetest_file_line_prefix ": ", data->current_file, data->current_line ); + __winetest_va_start( valist, msg ); + vfprintf( stdout, msg, valist ); + __winetest_va_end( valist ); +} + +static void __winetest_cdecl winetest_print_context( const char *msgtype ) +{ + tls_data *data = get_tls_data(); + unsigned int i; + + winetest_printf( "%s", msgtype ); + for (i = 0; i < data->context_count; ++i) + fprintf( stdout, "%s: ", data->context[i] ); +} + +void winetest_subtest(const char* name) +{ + tls_data* data = get_tls_data(); + fprintf(stdout, __winetest_file_line_prefix ": Subtest %s\n", + data->current_file, data->current_line, name); +} + int broken( int condition ) { return ((strcmp(winetest_platform, "windows") == 0) @@ -370,8 +416,7 @@ int winetest_vok( int condition, const char *msg, __winetest_va_list args ) { if (condition) { - fprintf( stdout, __winetest_file_line_prefix ": Test succeeded inside todo block: ", - data->current_file, data->current_line ); + winetest_print_context( "Test succeeded inside todo block: " ); vfprintf(stdout, msg, args); if ((data->nocount_level & 2) == 0) InterlockedIncrement(&todo_failures); @@ -382,8 +427,7 @@ int winetest_vok( int condition, const char *msg, __winetest_va_list args ) /* show todos even if traces are disabled*/ /*if (winetest_debug > 0)*/ { - fprintf( stdout, __winetest_file_line_prefix ": Test marked todo: ", - data->current_file, data->current_line ); + winetest_print_context( "Test marked todo: " ); vfprintf(stdout, msg, args); } if ((data->nocount_level & 1) == 0) @@ -395,8 +439,7 @@ int winetest_vok( int condition, const char *msg, __winetest_va_list args ) { if (!condition) { - fprintf( stdout, __winetest_file_line_prefix ": Test failed: ", - data->current_file, data->current_line ); + winetest_print_context( "Test failed: " ); vfprintf(stdout, msg, args); if ((data->nocount_level & 2) == 0) InterlockedIncrement(&failures); @@ -405,8 +448,9 @@ int winetest_vok( int condition, const char *msg, __winetest_va_list args ) else { if (report_success && (data->nocount_level & 1) == 0) - fprintf( stdout, __winetest_file_line_prefix ": Test succeeded\n", - data->current_file, data->current_line); + { + winetest_printf("Test succeeded\n"); + } if ((data->nocount_level & 1) == 0) InterlockedIncrement(&successes); return 1; @@ -426,11 +470,10 @@ void __winetest_cdecl winetest_ok( int condition, const char *msg, ... ) void __winetest_cdecl winetest_trace( const char *msg, ... ) { __winetest_va_list valist; - tls_data* data=get_tls_data(); if (winetest_debug > 0) { - fprintf( stdout, __winetest_file_line_prefix ": ", data->current_file, data->current_line ); + winetest_print_context( "" ); __winetest_va_start(valist, msg); vfprintf(stdout, msg, valist); __winetest_va_end(valist); @@ -450,9 +493,7 @@ void __winetest_cdecl winetest_print(const char* msg, ...) void winetest_vskip( const char *msg, __winetest_va_list args ) { - tls_data* data=get_tls_data(); - - fprintf( stdout, __winetest_file_line_prefix ": Tests skipped: ", data->current_file, data->current_line ); + winetest_print_context( "Tests skipped: " ); vfprintf(stdout, msg, args); skipped++; } @@ -529,6 +570,29 @@ void winetest_end_nocount(void) data->nocount_level >>= 2; } +void __winetest_cdecl winetest_push_context(const char* fmt, ...) +{ + tls_data* data = get_tls_data(); + __winetest_va_list valist; + + if (data->context_count < ARRAY_SIZE(data->context)) + { + __winetest_va_start(valist, fmt); + vsnprintf(data->context[data->context_count], sizeof(data->context[data->context_count]), fmt, valist); + __winetest_va_end(valist); + data->context[data->context_count][sizeof(data->context[data->context_count]) - 1] = 0; + } + ++data->context_count; +} + +void winetest_pop_context(void) +{ + tls_data* data = get_tls_data(); + + if (data->context_count) + --data->context_count; +} + int winetest_get_mainargs( char*** pargv ) { *pargv = winetest_argv; @@ -577,6 +641,61 @@ void winetest_wait_child_process( HANDLE process ) } } +const char *wine_dbgstr_an( const CHAR *str, intptr_t n ) +{ + char *dst, *res; + size_t size; + + if (!((ULONG_PTR)str >> 16)) + { + if (!str) return "(null)"; + res = get_temp_buffer( 6 ); + sprintf( res, "#%04x", LOWORD(str) ); + return res; + } + if (n == -1) + { + const CHAR *end = str; + while (*end) end++; + n = end - str; + } + if (n < 0) n = 0; + size = 12 + min( 300, n * 5 ); + dst = res = get_temp_buffer( size ); + *dst++ = '"'; + while (n-- > 0 && dst <= res + size - 10) + { + CHAR c = *str++; + switch (c) + { + case '\n': *dst++ = '\\'; *dst++ = 'n'; break; + case '\r': *dst++ = '\\'; *dst++ = 'r'; break; + case '\t': *dst++ = '\\'; *dst++ = 't'; break; + case '"': *dst++ = '\\'; *dst++ = '"'; break; + case '\\': *dst++ = '\\'; *dst++ = '\\'; break; + default: + if (c >= ' ' && c <= 126) + *dst++ = (char)c; + else + { + *dst++ = '\\'; + sprintf(dst,"%04x",c); + dst+=4; + } + } + } + *dst++ = '"'; + if (n > 0) + { + *dst++ = '.'; + *dst++ = '.'; + *dst++ = '.'; + } + *dst++ = 0; + release_temp_buffer( res, dst - res ); + return res; +} + const char *wine_dbgstr_wn( const WCHAR *str, intptr_t n ) { char *dst, *res;