Re: [Mingw-w64-public] Patch for ffmpeg

2015-12-29 Thread Mateusz

> I don`t see that this patch is valid.  I would request here more
> details about reasoning. I would be curious to learn that we have
> useless code in repro for years
>
> Kai

Current code works with msvcrt.dll in Win32 + _USE_32BIT_TIME_T (which 
is defined by default in Win32).


It doesn't work with msvcr120.dll (or msvcr110.dll) in Win32 + 
_USE_32BIT_TIME_T, doesn't work with msvcrt.dll in Win32 + 64BIT_TIME_T 
(which you can achieve by define __MINGW_USE_VC2005_COMPAT). It is also 
not 100% compliant with current Microsoft documentation.


I think we can choose one from three possibilities:
1) to do nothing (Win32 should die soon),
2) to change header files according M$ documentation and move function 
aliases from header file to 32-bit libmsvcrt.a (like in patch), it 
allows to work with msvcr120.dll in Win32 (but still msvcrt.dll in Win32 
+ 64BIT_TIME_T will be not working),
3) to change header files and 32-bit libmsvcrt.a to 100% compliant with 
M$ documentation.


At bottom of the page
https://msdn.microsoft.com/en-us/library/w4ddyt9h.aspx
I found information, that M$ made change in time functions in MSVC 2005. 
It was 10 years ago, now VS 2015 is free for open source projects. We 
could consider make mingw-w64 100% compliant with M$ documentation.


I attached example code t.cpp (based on page 
https://msdn.microsoft.com/en-us/library/95e68951.aspx) that works with 
VS 2015 64-bit & 32-bit & 32-bit + _USE_32BIT_TIME_T.


t.cpp works with GCC 64-bit (msvcrt.dll), GCC 32-bit (msvcrt.dll).

It doesn't work with GCC 64-bit with msvcr120.dll:
$ g++ -Wall -o t-gcc64-msvcr120.exe t.cpp
C:\Users\Mateusz\AppData\Local\Temp\ccmui7l3.o:t.cpp:(.text+0x17): 
undefined reference to `__imp__ftime'

collect2.exe: error: ld returned 1 exit status

It doesn't work with GCC 32-bit with msvcr120.dll (the same link error).

It can't compile with GCC 32-bit + -D__MINGW_USE_VC2005_COMPAT:
$ g++ -Wall -D__MINGW_USE_VC2005_COMPAT -o tg.exe t.cpp
t.cpp: In function 'int main()':
t.cpp:32:55: error: cannot convert '__time32_t* {aka long int*}' to 
'const time_t* {aka const long long int*}' for argument '3'

to 'errno_t ctime_s(char*, size_t, const time_t*)'
 err = ctime_s( timeline, 26, & ( timebuffer.time ) );
^

I attached also t0.cpp which works with all variants of VS 2015 and 
doesn't work with any variant of GCC.


My question is: should I try to make patch for 100% compliance with M$ 
documentation that works with all variants of GCC?
// crt_ftime64_s.c
// This program uses _ftime64_s to obtain the current
// time and then stores this time in timebuffer.

#include 
#include 
#include 

int main( void )
{
   struct _timeb timebuffer;
   char timeline[26];
   errno_t err;
   time_t time1;
   unsigned short millitm1;
   short timezone1;
   short dstflag1;

   _ftime(  );

time1 = timebuffer.time;
millitm1 = timebuffer.millitm;
timezone1 = timebuffer.timezone;
dstflag1 = timebuffer.dstflag;

   printf( "Seconds since midnight, January 1, 1970 (UTC): %ld\n", (unsigned 
long)time1);
   printf( "Milliseconds: %d\n", millitm1);
   printf( "Minutes between UTC and local time: %d\n", timezone1);
   printf( "Daylight savings time flag (1 means Daylight time is in "
   "effect): %d\n", dstflag1); 

   err = ctime_s( timeline, 26, & ( timebuffer.time ) );
   if (err)
   {
   printf("Invalid argument to ctime_s. ");
   }
   printf( "The time is %.19s.%hu %s", timeline, timebuffer.millitm,
   [20] );
}

// crt_ftime64_s.c
// This program uses _ftime64_s to obtain the current
// time and then stores this time in timebuffer.

#include 
#include 
#include 

int main( void )
{
   struct _timeb timebuffer;
   char timeline[26];
   errno_t err;
   time_t time1;
   unsigned short millitm1;
   short timezone1;
   short dstflag1;

   _ftime_s(  );

time1 = timebuffer.time;
millitm1 = timebuffer.millitm;
timezone1 = timebuffer.timezone;
dstflag1 = timebuffer.dstflag;

   printf( "Seconds since midnight, January 1, 1970 (UTC): %ld\n", (unsigned 
long)time1);
   printf( "Milliseconds: %d\n", millitm1);
   printf( "Minutes between UTC and local time: %d\n", timezone1);
   printf( "Daylight savings time flag (1 means Daylight time is in "
   "effect): %d\n", dstflag1); 

   err = ctime_s( timeline, 26, & ( timebuffer.time ) );
   if (err)
   {
   printf("Invalid argument to ctime_s. ");
   }
   printf( "The time is %.19s.%hu %s", timeline, timebuffer.millitm,
   [20] );
}

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


Re: [Mingw-w64-public] Patch for ffmpeg

2015-12-29 Thread JonY
On 12/3/2015 03:32, Mateusz wrote:
> I've prepared small patch for _mingw_stat64.h and mkstemp.c files.
> 
> First problem is that in _mingw_stat64.h header file #define section for
> _USE_32BIT_TIME_T case is switched from
> #define  new_name  msvcrt_function
> to
> #define  msvcrt_function  new_name
> which is nonsense. ffmpeg in file libavformat/os_support.h undefines
> stat & fstat in blind for _WIN32.
> 
> Second problem is described in ticket #471
> http://sourceforge.net/p/mingw-w64/bugs/471/
> so I've removed _O_TEMPORARY flag.
> 
> 

Kai, Ping?



0xD4EBC740.asc
Description: application/pgp-keys


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


Re: [Mingw-w64-public] Patch for ffmpeg

2015-12-29 Thread Kai Tietz
I don`t see that this patch is valid.  I would request here more details
about reasoning.  I would be curious to learn that we have useless code in
repro for years

Kai
Am 29.12.2015 10:45 schrieb "JonY" :

> On 12/3/2015 03:32, Mateusz wrote:
> > I've prepared small patch for _mingw_stat64.h and mkstemp.c files.
> >
> > First problem is that in _mingw_stat64.h header file #define section for
> > _USE_32BIT_TIME_T case is switched from
> > #define  new_name  msvcrt_function
> > to
> > #define  msvcrt_function  new_name
> > which is nonsense. ffmpeg in file libavformat/os_support.h undefines
> > stat & fstat in blind for _WIN32.
> >
> > Second problem is described in ticket #471
> > http://sourceforge.net/p/mingw-w64/bugs/471/
> > so I've removed _O_TEMPORARY flag.
> >
> >
>
> Kai, Ping?
>
>
--
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] Patch for ffmpeg

2015-12-28 Thread Mateusz

I execute command
gcc -dumpspecs >/local/specs.org

and then edit /local/specs.org file. I find 'msvcrt' word and delete all 
text except '*libgcc:' section (which contains 'msvcrt' word). In my GCC 
it looks like this:


*libgcc:
%{mthreads:-lmingwthrd} -lmingw32 -lgcc -lmoldname -lmingwex 
-lmsvcrt


It could be longer line if you compile GCC without '--disable-shared' 
option.
Then I copy file specs.org to specs.new and edit specs.new file to 
change '-lmsvcrt' to '-lmsvcr120'. It looks like this:


*libgcc:
%{mthreads:-lmingwthrd} -lmingw32 -lgcc -lmoldname -lmingwex 
-lmsvcr120


Then I copy both files specs.org and specs.new to 
\lib\gcc\x86_64-w64-mingw32\5.3.0\ folder in GCC directory. If I want to 
link to msvcr120.dll I copy 'specs.new' file to 'specs' file (without 
any extension). If I want link to old msvcrt.dll I copy 'cpecs.old' file 
to 'specs' file (I've made batch files to change this).


This is example for x86-64 version of GCC 5.3 compiled with actual trunk 
version of mingw-w64 (which has 'libmsvcr120.a' file).


Why?
Many open source project uses 'll' (long long) size specification in 
printf and scanf family functions. This not work in msvcrt.dll but works 
perfect in msvcr120.dll. So I turn off '__USE_MINGW_ANSI_STDIO' in 
'_mingw.h' header file and link to new msvcr120.dll. The printf family 
functions from Microsoft DLLs are threads safe (actual trunk version of 
mingw printf functions are threads safe too, but release 4.0.4 version 
is not threads safe).


Second problem is C++ project x265. If you don't turn off 
'__USE_MINGW_ANSI_STDIO' in '_mingw.h' header file each 'fprintf' 
function is replaced by

int fprintf (FILE *__stream, const char *__format, ...)
{
  register int __retval;
  __builtin_va_list __local_argv; __builtin_va_start( __local_argv, 
__format );

  __retval = __mingw_vfprintf( __stream, __format, __local_argv );
  __builtin_va_end( __local_argv );
  return __retval;
}
which eats L1 cache for code that on my CPU is only 32 KiB. It makes EXE 
file bigger and slower.



W dniu 2015-12-28 o 08:36, Baruch Burstein pisze:
On Thu, Dec 3, 2015 at 12:35 AM, Mateusz > wrote:


Sorry for previous patch -- I often link to msvcr120.dll instead
of msvcrt.dll.


I didn't know that was possible. How do you do that and why would you? 
What is the advantage?



--
˙uʍop-ǝpısdn sı ɹoʇıuoɯ ɹnoʎ 'sıɥʇ pɐǝɹ uɐɔ noʎ ɟı


--


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


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


Re: [Mingw-w64-public] Patch for ffmpeg

2015-12-27 Thread Baruch Burstein
On Thu, Dec 3, 2015 at 12:35 AM, Mateusz  wrote:

> Sorry for previous patch -- I often link to msvcr120.dll instead of
> msvcrt.dll.
>

I didn't know that was possible. How do you do that and why would you? What
is the advantage?


-- 
˙uʍop-ǝpısdn sı ɹoʇıuoɯ ɹnoʎ 'sıɥʇ pɐǝɹ uɐɔ noʎ ɟı
--
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] Patch for ffmpeg

2015-12-02 Thread Mateusz
Sorry for previous patch -- I often link to msvcr120.dll instead of 
msvcrt.dll.


For normal linking to msvcrt.dll the patch should be bigger -- we should 
add _fstat32i64, _stat32i64, _wstat32i64, _ftime32 aliases to 32-bit 
version of libmsvcrt.a (these functions are present in libmsvcr120.a).


Included new version of the patch which works witch msvcrt.dll and 
msvcr120.dll.



W dniu 2015-12-02 o 20:32, Mateusz pisze:

I've prepared small patch for _mingw_stat64.h and mkstemp.c files.

First problem is that in _mingw_stat64.h header file #define section 
for _USE_32BIT_TIME_T case is switched from

#define  new_name  msvcrt_function
to
#define  msvcrt_function  new_name
which is nonsense. ffmpeg in file libavformat/os_support.h undefines 
stat & fstat in blind for _WIN32.


Second problem is described in ticket #471
http://sourceforge.net/p/mingw-w64/bugs/471/
so I've removed _O_TEMPORARY flag.


--
Go from Idea to Many App Stores Faster with Intel(R) XDK
Give your users amazing mobile app experiences with Intel(R) XDK.
Use one codebase in this all-in-one HTML5 development environment.
Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs.
http://pubads.g.doubleclick.net/gampad/clk?id=254741911=/4140


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


diff --git a/mingw-w64-crt/lib32/msvcrt.def.in 
b/mingw-w64-crt/lib32/msvcrt.def.in
index 71bdf56..94378a4 100644
--- a/mingw-w64-crt/lib32/msvcrt.def.in
+++ b/mingw-w64-crt/lib32/msvcrt.def.in
@@ -196,7 +196,9 @@ _fsopen
 _fstat
 _fstat32 == _fstat
 _fstati64
+_fstat32i64 == _fstati64
 _ftime
+_ftime32 == _ftime
 _ftol
 _fullpath
 _futime
@@ -403,6 +405,7 @@ _stat
 _stat64
 _stati64
 _stat32 == _stat
+_stat32i64 == _stati64
 _statusfp
 _strcmpi
 _strdate
@@ -517,6 +520,7 @@ _wsplitpath
 _wstat
 _wstati64
 _wstat32 == _wstat
+_wstat32i64 == _wstati64
 _wstrdate
 _wstrtime
 _wsystem
diff --git a/mingw-w64-crt/misc/mkstemp.c b/mingw-w64-crt/misc/mkstemp.c
index d3c4aad..c78b7c5 100644
--- a/mingw-w64-crt/misc/mkstemp.c
+++ b/mingw-w64-crt/misc/mkstemp.c
@@ -48,7 +48,7 @@ int __cdecl mkstemp (char *template_name)
 template_name[j] = letters[rand () % 62];
 }
 fd = _sopen(template_name,
-_O_RDWR | _O_CREAT | _O_EXCL | _O_TEMPORARY | _O_BINARY,
+_O_RDWR | _O_CREAT | _O_EXCL | _O_BINARY,
 _SH_DENYRW, _S_IREAD | _S_IWRITE);
 if (fd != -1) return fd;
 if (fd == -1 && errno != EEXIST) return -1;
diff --git a/mingw-w64-headers/crt/_mingw_stat64.h 
b/mingw-w64-headers/crt/_mingw_stat64.h
index 17e754c..8ce0975 100644
--- a/mingw-w64-headers/crt/_mingw_stat64.h
+++ b/mingw-w64-headers/crt/_mingw_stat64.h
@@ -1,12 +1,12 @@
 #ifndef _STAT_DEFINED
 
 #ifdef _USE_32BIT_TIME_T
-#define _fstat32 _fstat
-#define _stat32 _stat
-#define _wstat32 _wstat
-#define _fstat32i64 _fstati64
-#define _stat32i64 _stati64
-#define _wstat32i64 _wstati64
+#define _fstat _fstat32
+#define _fstati64 _fstat32i64
+#define _stat _stat32
+#define _stati64 _stat32i64
+#define _wstat _wstat32
+#define _wstati64 _wstat32i64
 #else
 #define _fstat _fstat64i32
 #define _fstati64 _fstat64
diff --git a/mingw-w64-headers/crt/sys/timeb.h 
b/mingw-w64-headers/crt/sys/timeb.h
index c92c8e0..d60ac45 100644
--- a/mingw-w64-headers/crt/sys/timeb.h
+++ b/mingw-w64-headers/crt/sys/timeb.h
@@ -77,12 +77,13 @@ extern "C" {
 
   _CRTIMP void __cdecl _ftime64(struct __timeb64 *_Time);
 
-#ifdef _WIN64
+#ifndef _USE_32BIT_TIME_T
 #define _timeb __timeb64
-  _CRTIMP void __cdecl _ftime(struct __timeb64 *);
+#define _ftime _ftime64
 #else
 #define _timeb __timeb32
-  _CRTIMP void __cdecl _ftime(struct __timeb32 *);
+  _CRTIMP void __cdecl _ftime32(struct __timeb32 *);
+#define _ftime _ftime32
 #endif
 
 #ifndef _TIMESPEC_DEFINED
--
Go from Idea to Many App Stores Faster with Intel(R) XDK
Give your users amazing mobile app experiences with Intel(R) XDK.
Use one codebase in this all-in-one HTML5 development environment.
Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs.
http://pubads.g.doubleclick.net/gampad/clk?id=254741911=/4140___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public