Pali Rohár <[email protected]> wrote:

> Hello, I looked at changes and I have few comments for some of them. See 
> below.
>
> ...
>
> For these two macros there is missing opposite direction of xfail.
> If the test passes and xfail is set then it should return 1 (indicate
> failure).

I'm not sure about it. In the current state, this test will pass regardless of 
whether `_aligned_realloc` is buggy or not; if any subtest fails, there will be 
output in log files.

If we were to make the test fail when an `xfail` subtest passes, we would hit a 
random CI failure at some point and would need to fix this test. Doing so, 
would make this test fail on all older systems without the fix.

What do others think?

> Those ifdefs for library name is really ugly. I needed it more times and
> I was thinking about this idea:
>
> What about providing one specific symbol into every mingw-w64 CRT import
> library which would be a global char array with content of the library
> name?
>
> With this, it would be needed just to reference that symbol (e.g.
> __mingw_crt_library_name) and could be used in any application which
> needs this.

I agree that this is pretty ugly, but it was the best way to do it locally. I 
actually like your idea, except I would prefer to keep this stuff for internal 
use only.

In posix32, I have function `p32_crt_handle`[1] which returns handle to CRT the 
library is linked against (or terminates the process if it failed); when linked 
against static CRT (MSVC with /MT switches), it returns zero to inidcate static 
CRT. We might as well do something similar.

[1] 
https://github.com/maiddaisuki/posix32/blob/master/lib/posix32-core/src/crt.c

> Another idea: Via WinAPI it is possible to get HMODULE from any passed
> address of function. So what about using address of exit function (which
> is available in every CRT library) then deduce HMODULE of it (which
> would be the currently linked CRT DLL library) and on that call
> GetProcAddress?

I really forgot that it was an option. I think your idea above is generally 
better.

> I think that this test should still asserts that the lpCmdLine[0] is not '\0'
> like it was done before.

This was the initial idea, but then assertion has failed; when you pass no args 
to executable which uses `WinMain` as entry point, `lpCmdLine` will be an empty 
string.

> The proper way to compile windows gui application is to pass -mwindows
> command line switch. It will properly sets subsystem to gui and
> correctly choose required gui library. So the -lgdi32 is not needed in
> this case.

I really forgot that -mwindows exists. Nice catch, fix is in attachment.

> This is not quite correct. Usage of __MINGW_USE_ANSI_STDIO replaces
> _all_ usage of (ms)printf by (mingw)printf. I think that the purpose of
> test was to check that code works correctly with the default (possible)
> (ms)printf functions. And just usage of long double needs to be done
> explicitly by (mingw)printf as the ms variant has no 80-bit float
> support.
>
> So IMHO the previous code was correct.

I think these tests have nothing to do with testing printf's formatting 
capabilities and the output is just for debugging. I assume that back when this 
test was written, you would simply compile and run the tests, and examine 
output to see if anything is odd.

If we want to test printf's formatting capabilities with floating point 
numbers, I think we need a separate test for it.

> nit: There is a mix of TABs and spaces (something which you tried to
> clean in previous changes in series).

Nice catch; fix is in attachment.

> assert here is wrong. If the _set_error_mode fails then the assert will
> pop-up message box.

Hm... I copied this block from my posix32 library, where I ran this code 
hundreds if not thousands of times with almost every CRT. I have never hit an 
error return from `_set_error_mode`.

What others think?

> I would propose to call this function at the beginning of main() before
> declaring or initializing any variable, to ensure that it is always
> called at the beginning. Initialization of variable could be done by
> function call which could potentially cause assert/failure.

I'm certain that I made sure that in every test which calls `mingw_test_init`, 
this it is the first function called.

I wasn't sure whether I should call `mingw_test_init` before declaration block. 
My guess was that the declaration block like this is used or allow code to 
compile in strict C89 mode, which does not support mixing declarations and 
code. So, I tried to keep it whenever possible.

- Kirill Makurin
From e0b3fd06db719f937bae3be9354843cd67382c8a Mon Sep 17 00:00:00 2001
From: Kirill Makurin <[email protected]>
Date: Wed, 17 Jun 2026 15:02:21 +0900
Subject: [PATCH 1/2] crt: tests: build t_winmain with -mwindows

Using -mwindows makes compiler pass libraries required to link GUI Apps
as well as linker flags to properly set subsystem in executable's header.

Signed-off-by: Kirill Makurin <[email protected]>
---
 mingw-w64-crt/testcases/Makefile.am | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mingw-w64-crt/testcases/Makefile.am 
b/mingw-w64-crt/testcases/Makefile.am
index 0b6336e80..e695eee83 100644
--- a/mingw-w64-crt/testcases/Makefile.am
+++ b/mingw-w64-crt/testcases/Makefile.am
@@ -188,8 +188,8 @@ t_tls_ansi_CFLAGS = -std=c89 $(AM_CFLAGS)
 # Compile t_tls_c11 in C11 mode
 t_tls_c11_CFLAGS = -std=c11 $(AM_CFLAGS)
 
-# Link t_winmain against gdi32.dll
-t_winmain_LDADD = -lgdi32 $(LDADD)
+# t_winmain is a GUI App; use -mwindows to properly link it and set subsystem
+t_winmain_CFLAGS = $(AM_CFLAGS) -mwindows
 
 if ENABLE_TESTS_UNICODE
   # The following tests require compiler support for -municode option
-- 
2.51.0.windows.1

From f37f3251b6465fbaae4bf7a750c391083caff88d Mon Sep 17 00:00:00 2001
From: Kirill Makurin <[email protected]>
Date: Wed, 17 Jun 2026 15:05:02 +0900
Subject: [PATCH 2/2] crt: tests: fix indentation in libtest.c

Ensure that only spaces are used for indentation.

Signed-off-by: Kirill Makurin <[email protected]>
---
 mingw-w64-crt/testcases/libtest.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mingw-w64-crt/testcases/libtest.c 
b/mingw-w64-crt/testcases/libtest.c
index 9d39c4061..540d5636a 100644
--- a/mingw-w64-crt/testcases/libtest.c
+++ b/mingw-w64-crt/testcases/libtest.c
@@ -42,7 +42,7 @@ static void __cdecl mingw_test_invalid_parameter_handler (
   fprintf(stderr, "\n");
   (void)pReserved;
   /* Ensure that this handler does not return, as the whole handler replaces 
calling of Dr. Watson */
-       abort ();
+  abort ();
 }
 
 static int __cdecl mingw_test_fini (void) {
-- 
2.51.0.windows.1

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to