Re: MSVC and fseeko.c

2016-12-13 Thread Bruno Haible
Gisle Vanem wrote:
> Bruno Haible wrote:
> 
> > $ ./gnulib-tool --create-testdir --dir=/tmp/testdir-stdioext --with-tests \
> > --single-configure --avoid=havelib-tests \
> > fseterr freadable fwritable fbufmode freading fwriting \
> > freadptr freadseek freadahead fpurge fseeko ftello fpending 
> > \
> > fflush
> > 
> > With this patch, this testdir passes its testsuite on MSVC 14, both in 
> > 32-bit
> > and in 64-bit mode, except for the 'fpending' module.
> 
> Thanks alot for your effort on this. It compiles fine, but I'm not sure
> it works for all test-f*.exe tests. In test-fseeko.exe, I get this assert:
>   test-fseeko.c:45: assertion 'r1 == r2 && r1 == expected' failed
> 
> (r1 = -1, r2 = 0, expected = 0).

And what about the other tests? When "make check" runs, which fail?
(This info should give a hint about where to start looking.)

> You tested this with MSVC 14?

Yes.

> Does this use the "old" MSVCRT.dll?

No, it uses vcruntime140.dll.

> BTW. I'm on Win-10 using MSVC 2015 and the WindowsKit (Universal CRT
> ver. 10.0.10586.0).

Mine is 10.0.10240.0.

> I noticed you patched stdio-impl.h with the 'struct _gl_real_FILE' stuff.
> Are you sure this is compatible with this newer Windows SDK?

No, Microsoft won't tell me when they make internal changes in their library.

Bruno




Re: MSVC and fseeko.c

2016-12-13 Thread Gisle Vanem
Bruno Haible wrote:

> $ ./gnulib-tool --create-testdir --dir=/tmp/testdir-stdioext --with-tests \
> --single-configure --avoid=havelib-tests \
> fseterr freadable fwritable fbufmode freading fwriting \
> freadptr freadseek freadahead fpurge fseeko ftello fpending \
> fflush
> 
> With this patch, this testdir passes its testsuite on MSVC 14, both in 32-bit
> and in 64-bit mode, except for the 'fpending' module.

Thanks alot for your effort on this. It compiles fine, but I'm not sure
it works for all test-f*.exe tests. In test-fseeko.exe, I get this assert:
  test-fseeko.c:45: assertion 'r1 == r2 && r1 == expected' failed

(r1 = -1, r2 = 0, expected = 0).

You tested this with MSVC 14? Does this use the "old" MSVCRT.dll?
BTW. I'm on Win-10 using MSVC 2015 and the WindowsKit (Universal CRT
ver. 10.0.10586.0).

I noticed you patched stdio-impl.h with the 'struct _gl_real_FILE' stuff.
Are you sure this is compatible with this newer Windows SDK?

-- 
--gv



Re: MSVC and fseeko.c

2016-12-12 Thread Bruno Haible
Gisle Vanem wrote:
> Seems this file supports every archaic target in existence, but
> not MSVC. I've patched it like:
> 
> --- a/lib/fseeko.c 2016-01-30 20:42:16
> +++ b/lib/fseeko.c 2016-01-31 10:25:06
> @@ -100,7 +100,7 @@
>  #elif defined EPLAN9/* Plan9 */
>if (fp->rp == fp->buf
>&& fp->wp == fp->buf)
> -#elif FUNC_FFLUSH_STDIN < 0 && 200809 <= _POSIX_VERSION
> +#elif FUNC_FFLUSH_STDIN < 0 && 200809 <= _POSIX_VERSION || _MSC_VER
>/* Cross-compiling to some other system advertising conformance to
>   POSIX.1-2008 or later.  Assume fseeko and fflush work as advertised.
>   If this assumption is incorrect, please report the bug to
> 
> but I've no idea if it's correct. Any pointers?

To determine whether the set of "stdioext" modules is correct, one can use a
testdir / tarball generated through

$ ./gnulib-tool --create-testdir --dir=/tmp/testdir-stdioext --with-tests \
--single-configure --avoid=havelib-tests \
fseterr freadable fwritable fbufmode freading fwriting \
freadptr freadseek freadahead fpurge fseeko ftello fpending \
fflush

With this patch, this testdir passes its testsuite on MSVC 14, both in 32-bit
and in 64-bit mode, except for the 'fpending' module.


2016-12-12  Bruno Haible  

stdioext: Port to native Windows with MSVC.
* lib/stdio-impl.h (WINDOWS_OPAQUE_FILE): New macro.
(struct _gl_real_FILE): New type.
(fp_, _IOREAD, _IOWRT, _IORW, _IOEOF, _IOERR): New macros, for native
Windows.
* lib/fbufmode.c (fbufmode): Add code for native Windows.
* lib/fflush.c (clear_ungetc_buffer): Treat native Windows like the
other SystemV derived implementations.
* lib/fpurge.c (fpurge): Likewise.
* lib/freadable.c (freadable): Likewise.
* lib/freadahead.c (freadahead): Likewise.
* lib/freading.c (freading): Likewise.
* lib/freadptr.c (freadptr): Likewise.
* lib/freadseek.c (freadptrinc): Likewise.
* lib/fseeko.c (fseeko): Likewise.
* lib/fseterr.c (fseterr): Likewise.
* lib/fwritable.c (fwritable): Likewise.
* lib/fwriting.c (fwriting): Likewise.
Reported by Gisle Vanem .

diff --git a/lib/stdio-impl.h b/lib/stdio-impl.h
index 987897a..7d389e9 100644
--- a/lib/stdio-impl.h
+++ b/lib/stdio-impl.h
@@ -110,4 +110,31 @@
 #  define _flag __flag
 # endif
 
+#elif (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__  /* newer 
Windows with MSVC */
+
+/*  does not define the innards of FILE any more.  */
+# define WINDOWS_OPAQUE_FILE
+
+struct _gl_real_FILE
+{
+  /* Note: Compared to older Windows and to mingw, it has the fields
+ _base and _cnt swapped. */
+  unsigned char *_ptr;
+  unsigned char *_base;
+  int _cnt;
+  int _flag;
+  int _file;
+  int _charbuf;
+  int _bufsiz;
+};
+# define fp_ ((struct _gl_real_FILE *) fp)
+
+/* These values were determined by a program similar to the one at
+   .  */
+# define _IOREAD   0x1
+# define _IOWRT0x2
+# define _IORW 0x4
+# define _IOEOF0x8
+# define _IOERR   0x10
+
 #endif
diff --git a/lib/fbufmode.c b/lib/fbufmode.c
index 828eed7..483c8f0 100644
--- a/lib/fbufmode.c
+++ b/lib/fbufmode.c
@@ -53,17 +53,24 @@ fbufmode (FILE *fp)
   return fp->_flags & (_IOLBF | _IONBF | _IOFBF);
 #elif defined __minix   /* Minix */
   return fp->_flags & (_IOLBF | _IONBF | _IOFBF);
-#elif defined _IOERR/* AIX, HP-UX, IRIX, OSF/1, Solaris, 
OpenServer, mingw, NonStop Kernel */
-# if HAVE___FLBF/* Solaris >= 7 */
+#elif defined _IOERR/* AIX, HP-UX, IRIX, OSF/1, Solaris, 
OpenServer, mingw, MSVC, NonStop Kernel */
+# if defined WINDOWS_OPAQUE_FILE
+  if (fp_->_flag & 0x100)
+return _IOFBF; /* Impossible to distinguish _IOFBF and _IOLBF.  */
+  else
+return _IONBF;
+# else
+#  if HAVE___FLBF   /* Solaris >= 7 */
   if (__flbf (fp))
 return _IOLBF;
-# else
+#  else
   if (fp->_flag & _IOLBF)
 return _IOLBF;
-# endif
+#  endif
   if (fp_->_flag & _IONBF)
 return _IONBF;
   return _IOFBF;
+# endif
 #elif defined __UCLIBC__/* uClibc */
   if (fp->__modeflags & __FLAG_LBF)
 return _IOLBF;
diff --git a/lib/fflush.c b/lib/fflush.c
index 2bd7cc9..ef2a7f1 100644
--- a/lib/fflush.c
+++ b/lib/fflush.c
@@ -63,7 +63,7 @@ clear_ungetc_buffer (FILE *fp)
   fp->_ungetc_count = 0;
   fp->_rcount = - fp->_rcount;
 }
-# elif defined _IOERR   /* Minix, AIX, HP-UX, IRIX, OSF/1, 
Solaris, OpenServer, mingw, NonStop Kernel */
+# elif defined _IOERR   /* Minix, AIX, HP-UX, IRIX, OSF/1, 
Solaris, OpenServer, mingw, MSVC, NonStop Kernel */
   /* Nothing to do.  */
 # else  /* other implementations */
   fseeko (fp, 0, SEEK_CUR);
diff --git a/lib/fpurge.c 

MSVC and fseeko.c

2016-12-12 Thread Gisle Vanem
Seems this file supports every archaic target in existence, but
not MSVC. I've patched it like:

--- a/lib/fseeko.c 2016-01-30 20:42:16
+++ b/lib/fseeko.c 2016-01-31 10:25:06
@@ -100,7 +100,7 @@
 #elif defined EPLAN9/* Plan9 */
   if (fp->rp == fp->buf
   && fp->wp == fp->buf)
-#elif FUNC_FFLUSH_STDIN < 0 && 200809 <= _POSIX_VERSION
+#elif FUNC_FFLUSH_STDIN < 0 && 200809 <= _POSIX_VERSION || _MSC_VER
   /* Cross-compiling to some other system advertising conformance to
  POSIX.1-2008 or later.  Assume fseeko and fflush work as advertised.
  If this assumption is incorrect, please report the bug to

but I've no idea if it's correct. Any pointers?

-- 
--gv