Re: [Mingw-w64-public] inttypes Format Specifiers

2018-10-27 Thread Jacek Caban

On 27/10/2018 07:57, Liu Hao wrote:


在 2018/10/27 上午5:57, Mateusz 写道:

W dniu 26.10.2018 o 22:35, Tom Ritter pisze:

This is not really a MinGW problem, but MinGW does diverge from other
compilers and it caused Firefox to crash.

MinGW defines a lot of I64[foo] format specifiers in inttypes.h.
clang and clang-cl don't use I64[foo] they use ll[foo]. (I64[foo] is
valid according to Microsoft. MinGW mentions "MS runtime does not yet
understand C9x standard "ll"" but at some point they started
supporting ll[foo].  And as I mentioned, that's what clang[-cl] uses.

Mozilla has our own implementation of printf that does the format
specifier parsing. We don't support I64[foo]. So using it caused data
corruption and general bad behavior. Switching to ll[foo] fixed it.

I have a patch here:
https://hg.mozilla.org/try/raw-file/eaae7782a1dd/build/build-clang/mingw-int.patch

You can try to define
__USE_MINGW_ANSI_STDIO
instead of patching mingw-w64



It is the correct solution to define `__USE_MINGW_ANSI_STDIO` when
compiling Firefox, just like what libstdc++ does.


I don't see what makes __USE_MINGW_ANSI_STDIO a correct solution. 
Firefox builds use ucrt, which is sufficient for handling stdio (and 
official winapi+clang-cl builds use that anyway).



As for the patch:  The name `DEFINE_TWO_VERSION` is not descriptive for
this macro's purpose, and not suitable within a standard library header
because it doesn't start with an underscore. A better name would look
like `__MINGW_SELECT_C99_STDIO_FORMAT`.



I took a look at this and I think we want a more radical solution. Right 
now we have _mingw_print_push.h/_mingw_print_pop.h hack that has no 
clean purpose to me. I did some git history checking and when it was 
introduced, it was important for __USE_MINGW_ANSI_STDIO because that was 
where printf/scanf functions were #defined. It was later removed and the 
only thing that's left there is a bunch of PRI* macros. Instead of 
defining and redefining them, we may just as well define them correctly 
in the first place.


That's what the attached patch does. It also uses the same for ucrt and 
mingw stdio, leaving hackish values only for affected builds. This fixes 
Firefox issue and makes mingw stdio cleaner. It's not yet tested, I'm 
mostly sending it for comments now.


Cheers,
Jacek
commit 3060d249c397feffe6e00dbad6be64879e97294b
Author: Jacek Caban 
Date:   Sat Oct 27 13:35:38 2018 +0200

inttypes.h: Take into account __USE_MINGW_ANSI_STDIO and msvcrt version 
instead of depending on _mingw_print_p*.h headers.

diff --git a/mingw-w64-headers/configure.ac b/mingw-w64-headers/configure.ac
index d83037e8..dda8a629 100644
--- a/mingw-w64-headers/configure.ac
+++ b/mingw-w64-headers/configure.ac
@@ -39,7 +39,7 @@ AM_CONDITIONAL([HAVE_WIDL],[AS_VAR_TEST_SET([WIDL])])
 
 # Checks for header files.
 
-BASEHEAD_LIST="crt/_bsd_types.h crt/_cygwin.h crt/_mingw.h crt/_mingw_mac.h 
crt/_mingw_print_push.h crt/_mingw_print_pop.h crt/_mingw_secapi.h 
crt/_mingw_unicode.h crt/_timeval.h crt/crtdefs.h crt/excpt.h crt/intrin.h 
crt/vadefs.h crt/tchar.h "$srcdir/include/*.h
+BASEHEAD_LIST="crt/_bsd_types.h crt/_cygwin.h crt/_mingw.h crt/_mingw_mac.h 
crt/_mingw_secapi.h crt/_mingw_unicode.h crt/_timeval.h crt/crtdefs.h 
crt/excpt.h crt/intrin.h crt/vadefs.h crt/tchar.h "$srcdir/include/*.h
 SECHEAD_LIST="$srcdir/crt/sec_api/stralign_s.h"
 for i in c dlg h16 hxx rh ver; do
   BASEHEAD_LIST="$BASEHEAD_LIST "$srcdir/include/*.$i
diff --git a/mingw-w64-headers/crt/_mingw_print_pop.h 
b/mingw-w64-headers/crt/_mingw_print_pop.h
deleted file mode 100644
index 046b6203..
--- a/mingw-w64-headers/crt/_mingw_print_pop.h
+++ /dev/null
@@ -1,136 +0,0 @@
-/**
- * This file has no copyright assigned and is placed in the Public Domain.
- * This file is part of the mingw-w64 runtime package.
- * No warranty is given; refer to the file DISCLAIMER.PD within this package.
- */
-
-/* Define __mingw_ macros.  */
-#if defined(__USE_MINGW_ANSI_STDIO) && (defined(_INC_STDIO) || 
defined(_WSTDIO_DEFINED)) && ((__USE_MINGW_ANSI_STDIO + 0) != 0)
-
-/* Redefine to GNU specific PRI... and SCN... macros.  */
-#if defined(_INTTYPES_H_) && defined(PRId64)
-#undef PRId64
-#undef PRIdLEAST64
-#undef PRIdFAST64
-#undef PRIdMAX
-#undef PRIi64
-#undef PRIiLEAST64
-#undef PRIiFAST64
-#undef PRIiMAX
-#undef PRIo64
-#undef PRIoLEAST64
-#undef PRIoFAST64
-#undef PRIoMAX
-#undef PRIu64
-#undef PRIuLEAST64
-#undef PRIuFAST64
-#undef PRIuMAX
-#undef PRIx64
-#undef PRIxLEAST64
-#undef PRIxFAST64
-#undef PRIxMAX
-#undef PRIX64
-#undef PRIXLEAST64
-#undef PRIXFAST64
-#undef PRIXMAX
-
-#undef SCNd64
-#undef SCNdLEAST64
-#undef SCNdFAST64
-#undef SCNdMAX
-#undef SCNi64
-#undef SCNiLEAST64
-#undef SCNiFAST64
-#undef SCNiMAX
-#undef SCNo64
-#undef SCNoLEAST64
-#undef SCNoFAST64
-#undef SCNoMAX
-#undef SCNx64
-#undef SCNxLEAST64
-#undef SCNxFAST64
-#undef SCNxMAX
-#undef SCNu64
-#undef SCNuLEAST64
-#undef SCNuFAST64
-#undef SCNuMAX
-
-#ifdef _WIN64
-#undef PRIdPTR

Re: [Mingw-w64-public] inttypes Format Specifiers

2018-10-27 Thread Vincent Torri
On Fri, Oct 26, 2018 at 11:58 PM Mateusz  wrote:
>
> W dniu 26.10.2018 o 22:35, Tom Ritter pisze:
> > This is not really a MinGW problem, but MinGW does diverge from other
> > compilers and it caused Firefox to crash.
> >
> > MinGW defines a lot of I64[foo] format specifiers in inttypes.h.
> > clang and clang-cl don't use I64[foo] they use ll[foo]. (I64[foo] is
> > valid according to Microsoft. MinGW mentions "MS runtime does not yet
> > understand C9x standard "ll"" but at some point they started
> > supporting ll[foo].  And as I mentioned, that's what clang[-cl] uses.
> >
> > Mozilla has our own implementation of printf that does the format
> > specifier parsing. We don't support I64[foo]. So using it caused data
> > corruption and general bad behavior. Switching to ll[foo] fixed it.
> >
> > I have a patch here:
> > https://hg.mozilla.org/try/raw-file/eaae7782a1dd/build/build-clang/mingw-int.patch
>
> You can try to define
> __USE_MINGW_ANSI_STDIO
> instead of patching mingw-w64

i've mesure a significant performance loss when using printf
functions with __USE_MINGW_ANSI_STDIO cmopared to the ones in
msvcrt.dll

is it normal ?

Vincent Torri


___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] inttypes Format Specifiers

2018-10-27 Thread Liu Hao
在 2018/10/27 上午5:57, Mateusz 写道:
> W dniu 26.10.2018 o 22:35, Tom Ritter pisze:
>> This is not really a MinGW problem, but MinGW does diverge from other
>> compilers and it caused Firefox to crash.
>>
>> MinGW defines a lot of I64[foo] format specifiers in inttypes.h.
>> clang and clang-cl don't use I64[foo] they use ll[foo]. (I64[foo] is
>> valid according to Microsoft. MinGW mentions "MS runtime does not yet
>> understand C9x standard "ll"" but at some point they started
>> supporting ll[foo].  And as I mentioned, that's what clang[-cl] uses.
>>
>> Mozilla has our own implementation of printf that does the format
>> specifier parsing. We don't support I64[foo]. So using it caused data
>> corruption and general bad behavior. Switching to ll[foo] fixed it.
>>
>> I have a patch here:
>> https://hg.mozilla.org/try/raw-file/eaae7782a1dd/build/build-clang/mingw-int.patch
> 
> You can try to define
> __USE_MINGW_ANSI_STDIO
> instead of patching mingw-w64
> 
> 

It is the correct solution to define `__USE_MINGW_ANSI_STDIO` when
compiling Firefox, just like what libstdc++ does.

As for the patch:  The name `DEFINE_TWO_VERSION` is not descriptive for
this macro's purpose, and not suitable within a standard library header
because it doesn't start with an underscore. A better name would look
like `__MINGW_SELECT_C99_STDIO_FORMAT`.


-- 
Best regards,
LH_Mouse



signature.asc
Description: OpenPGP digital signature
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public