Hello, I'm not sure if it is correct to alias every one __ms_ and non-ms ucrt printf/scanf function.
For example in -std=c99 mode we should rather follow C99 standard and hence %s in wprintf should take char*. But __ms_wprintf should take wchar_t* (independently of -std= option) as this is on what tchar.h depends. My original idea was to define everything in separate .c files, not via aliases in header files. This could also solve above problem and for example problems with non-standard _vsnprintf or _vsnwprintf functions (which should never use _CRT_INTERNAL_PRINTF_STANDARD_SNPRINTF_BEHAVIOR and always use _CRT_INTERNAL_PRINTF_LEGACY_VSPRINTF_NULL_TERMINATION). But you said that this is not maintainable and I have not come up with a better idea. One suggestion: What about moving all ucrt stdio functions into own subdirectory? E.g. mingw-w64-crt/stdio/ucrt/ So we do not need to prefix every file with ucrt_. It would be quite confusing how we should call a file which contains UCRT's _vsnprintf function and file with UCRT vsnprintf function. On Thursday 20 March 2025 19:54:16 Martin Storsjö wrote: > Hi, > > This is a series of patches, which essentially does three different > things. > > The ultimate target of the series is to fix a regression; in > 581532b8e49a0e10cbdfe2332a8c1d61ff3d6820, tchar.h started referencing > __ms_ prefixed symbols for many functions, even if UCRT didn't > actually provide those symbols. This issue was quickly noticed at > https://github.com/msys2/MINGW-packages/pull/22697#issuecomment-2541206219. > > We did a quick fix for this in c9eca28decb3aa5213fe22ab1f9883df91d79806, > by providing a separate __ms_fprintf function. However, doing the same, > providing separate __ms_ prefixed concrete functions for UCRT, for > all the relevant functions, felt like overkill. (The __ms_ prefixed > functions are really only meant to be set up via aliases in .def files, > or similar.) > > Meanwhile, another case of a regression from > 581532b8e49a0e10cbdfe2332a8c1d61ff3d6820 was uncovered in > https://github.com/git-for-windows/build-extra/commit/b1b6eb5c5d78c4d8da53c4daa6aa6cf7dae7f8fb; > they also use _tprintf and _stscanf, which end up > as undefined references to __ms_printf and __ms_sscanf, so a > full solution is needed (or 581532b8e49a0e10cbdfe2332a8c1d61ff3d6820 > would need to be reverted). > > This patchset fixes the __ms_ prefixed functions for UCRT, by > redirecting them to the regular implementations, using > __MINGW_ASM_CALL(). > > In order to do that, we need to provide all the relevant *wprintf > and *wscanf functions as non-inline functions. > > Before converting the wide char UCRT stdio functions to non-inline, > I wanted a better solution to setting the UCRT stdio options, > in order to be able to switch between the C99 and legacy wide > specifiers for format strings. > > Therefore, this patch series does these three major steps: > - Allows changing _CRT_INTERNAL_LOCAL_PRINTF_OPTIONS and > _CRT_INTERNAL_LOCAL_SCANF_OPTIONS at runtime by assigning to it, > similar to how it works in MSVC > - Converts most *wprintf and *wscanf functions to non-inline > - Redirects __ms_ functions to the right ones using __MINGW_ASM_CALL() > in headers > > // Martin > > > Martin Storsjö (10): > crt: Remove workarounds for defining non-inline versions of inline > functions > crt: Make ucrt_fwprintf consistent with the other ucrt_* files > headers, crt: Convert the UCRT stdio options to a mutable state > crt: Use _CRT_INTERNAL_LOCAL_SCANF_OPTIONS in non-inline scanf > functions > crt: Use the default _CRT_INTERNAL_LOCAL_PRINTF_OPTIONS in > __ms_fwprintf > crt: Sort the stdio filenames in src_ucrtbase in alphabetical order > crt, headers: Convert the UCRT *wprintf functions to non-inline > crt, headers: Convert the UCRT *wscanf functions to non-inline > headers: Redirect __ms_<func> back to plain <func> for UCRT > crt: Remove the separate UCRT __ms_fprintf function > > Pali Rohár (1): > headers: Declare __ms_vsscanf, __ms_vscanf, __ms_vfscanf, > __ms_vswscanf, __ms_vwscanf, __ms_vfwscanf, __ms_snprintf, > __ms_vsnprintf, __ms_snwprintf and __ms_vsnwprintf also for UCRT > builds > > mingw-w64-crt/Makefile.am | 32 ++- > .../stdio/ucrt___local_stdio_printf_options.c | 15 ++ > .../stdio/ucrt___local_stdio_scanf_options.c | 15 ++ > mingw-w64-crt/stdio/ucrt__snscanf.c | 2 +- > mingw-w64-crt/stdio/ucrt__snwprintf.c | 16 -- > mingw-w64-crt/stdio/ucrt_fscanf.c | 2 +- > mingw-w64-crt/stdio/ucrt_fwprintf.c | 18 +- > mingw-w64-crt/stdio/ucrt_fwscanf.c | 19 ++ > mingw-w64-crt/stdio/ucrt_ms_fwprintf.c | 2 +- > mingw-w64-crt/stdio/ucrt_scanf.c | 2 +- > mingw-w64-crt/stdio/ucrt_snwprintf.c | 21 ++ > mingw-w64-crt/stdio/ucrt_sscanf.c | 2 +- > mingw-w64-crt/stdio/ucrt_swprintf.c | 31 +++ > mingw-w64-crt/stdio/ucrt_swscanf.c | 20 ++ > mingw-w64-crt/stdio/ucrt_vfscanf.c | 2 +- > mingw-w64-crt/stdio/ucrt_vfwprintf.c | 15 ++ > mingw-w64-crt/stdio/ucrt_vfwscanf.c | 14 + > mingw-w64-crt/stdio/ucrt_vscanf.c | 2 +- > mingw-w64-crt/stdio/ucrt_vsnwprintf.c | 16 ++ > mingw-w64-crt/stdio/ucrt_vsscanf.c | 2 +- > mingw-w64-crt/stdio/ucrt_vswprintf.c | 28 ++ > mingw-w64-crt/stdio/ucrt_vswscanf.c | 14 + > mingw-w64-crt/stdio/ucrt_vwprintf.c | 15 ++ > mingw-w64-crt/stdio/ucrt_vwscanf.c | 14 + > .../{ucrt_ms_fprintf.c => ucrt_wprintf.c} | 13 +- > mingw-w64-crt/stdio/ucrt_wscanf.c | 19 ++ > mingw-w64-headers/crt/_mingw.h.in | 6 + > mingw-w64-headers/crt/corecrt_stdio_config.h | 14 +- > mingw-w64-headers/crt/stdio.h | 242 +++++++----------- > mingw-w64-headers/crt/wchar.h | 181 ++++--------- > 30 files changed, 451 insertions(+), 343 deletions(-) > create mode 100644 mingw-w64-crt/stdio/ucrt___local_stdio_printf_options.c > create mode 100644 mingw-w64-crt/stdio/ucrt___local_stdio_scanf_options.c > create mode 100644 mingw-w64-crt/stdio/ucrt_fwscanf.c > create mode 100644 mingw-w64-crt/stdio/ucrt_snwprintf.c > create mode 100644 mingw-w64-crt/stdio/ucrt_swprintf.c > create mode 100644 mingw-w64-crt/stdio/ucrt_swscanf.c > create mode 100644 mingw-w64-crt/stdio/ucrt_vfwprintf.c > create mode 100644 mingw-w64-crt/stdio/ucrt_vfwscanf.c > create mode 100644 mingw-w64-crt/stdio/ucrt_vsnwprintf.c > create mode 100644 mingw-w64-crt/stdio/ucrt_vswprintf.c > create mode 100644 mingw-w64-crt/stdio/ucrt_vswscanf.c > create mode 100644 mingw-w64-crt/stdio/ucrt_vwprintf.c > create mode 100644 mingw-w64-crt/stdio/ucrt_vwscanf.c > rename mingw-w64-crt/stdio/{ucrt_ms_fprintf.c => ucrt_wprintf.c} (53%) > create mode 100644 mingw-w64-crt/stdio/ucrt_wscanf.c > > -- > 2.43.0 > _______________________________________________ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public