public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@vinschen.de>
To: Bastien Bouclet <bastien.bouclet@gmail.com>
Cc: newlib@sourceware.org, Takashi Yano <takashi.yano@nifty.ne.jp>,
	Marco Atzeri <marco.atzeri@gmail.com>
Subject: Re: [PATCH] newlib: fix fseek optimization with SEEK_CUR
Date: Wed, 29 Jan 2020 18:02:00 -0000	[thread overview]
Message-ID: <20200129180217.GR3549@calimero.vinschen.de> (raw)
In-Reply-To: <20191118101153.GB3372@calimero.vinschen.de>


[-- Attachment #1.1: Type: text/plain, Size: 1263 bytes --]

On Nov 18 11:11, Corinna Vinschen wrote:
> On Nov  9 17:28, Bastien Bouclet wrote:
> > The call to fflush was invalidating the read buffer, preventing relative
> > seeks to positions that would have been inside the read buffer from
> > being optimized. The call to srefill would then re-read mostly the same
> > data that was initially in the read buffer.
> > ---
> >  newlib/libc/stdio/fseeko.c     | 31 ++++++-------------------------
> >  newlib/libc/stdio64/fseeko64.c | 31 ++++++-------------------------
> >  2 files changed, 12 insertions(+), 50 deletions(-)
> 
> Pushed.

Sorry, but I had to revert this patch.  It breaks gnulib's autoconf
test.  The attached conftest.c returns 5, rather than 0 as before
because lseek and ftello return different results.

While this is expected on BSD systems, it's not expected on at least
Linux and Cygwin.  Since this breaks backward compatibility and
leads to gnulib wrongly providing its own fflush, fseek and fseeko
implementations when building for newlib/Cygwin.

I attached the gnulib testcase for completeness.

Many thanks to Takashi Yano for figuring this out after the CYgwin
octave build was broken.


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat



[-- Attachment #1.2: conftest.c --]
[-- Type: text/plain, Size: 1462 bytes --]

#include <stdio.h>
# include <unistd.h>

int
main ()
{
FILE *f = fopen ("conftest.txt", "r");
         char buffer[10];
         int fd;
         int c;
         if (f == NULL)
           return 1;
         fd = fileno (f);
         if (fd < 0 || fread (buffer, 1, 5, f) != 5)
           { fclose (f); return 2; }
         /* For deterministic results, ensure f read a bigger buffer.  */
         if (lseek (fd, 0, SEEK_CUR) == 5)
           { fclose (f); return 3; }
         /* POSIX requires fflush-fseek to set file offset of fd.  This fails
            on BSD systems and on mingw.  */
         if (fflush (f) != 0 || fseek (f, 0, SEEK_CUR) != 0)
           { fclose (f); return 4; }
         if (lseek (fd, 0, SEEK_CUR) != 5)
           { fclose (f); return 5; }
         /* Verify behaviour of fflush after ungetc. See
            <http://www.opengroup.org/austin/aardvark/latest/xshbug3.txt>  */
         /* Verify behaviour of fflush after a backup ungetc.  This fails on
            mingw.  */
         c = fgetc (f);
         ungetc (c, f);
         fflush (f);
         if (fgetc (f) != c)
           { fclose (f); return 6; }
         /* Verify behaviour of fflush after a non-backup ungetc.  This fails
            on glibc 2.8 and on BSD systems.  */
         c = fgetc (f);
         ungetc ('@', f);
         fflush (f);
         if (fgetc (f) != c)
           { fclose (f); return 7; }
         fclose (f);
         return 0;

  ;
  return 0;
}

[-- Attachment #1.3: conftest.txt --]
[-- Type: text/plain, Size: 13 bytes --]

hello world


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2020-01-29 18:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-09 16:28 Bastien Bouclet
2019-11-13 10:15 ` Corinna Vinschen
2019-11-18 10:11 ` Corinna Vinschen
2020-01-29 18:02   ` Corinna Vinschen [this message]
2019-11-13 20:36 Bastien Bouclet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200129180217.GR3549@calimero.vinschen.de \
    --to=corinna@vinschen.de \
    --cc=bastien.bouclet@gmail.com \
    --cc=marco.atzeri@gmail.com \
    --cc=newlib@sourceware.org \
    --cc=takashi.yano@nifty.ne.jp \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).