From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 102118 invoked by alias); 29 Jan 2020 18:02:32 -0000 Mailing-List: contact newlib-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: newlib-owner@sourceware.org Received: (qmail 102093 invoked by uid 89); 29 Jan 2020 18:02:30 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.9 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=H*f:sk:2019111, stdio, H*Ad:D*ne.jp, UD:fseeko.c X-HELO: mout.kundenserver.de Received: from mout.kundenserver.de (HELO mout.kundenserver.de) (212.227.17.24) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 29 Jan 2020 18:02:28 +0000 Received: from calimero.vinschen.de ([24.134.7.25]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MXH3Y-1j55wi1sRa-00YgSP; Wed, 29 Jan 2020 19:02:18 +0100 Received: by calimero.vinschen.de (Postfix, from userid 500) id 50537A80BDF; Wed, 29 Jan 2020 19:02:17 +0100 (CET) Date: Wed, 29 Jan 2020 18:02:00 -0000 From: Corinna Vinschen To: Bastien Bouclet Cc: newlib@sourceware.org, Takashi Yano , Marco Atzeri Subject: Re: [PATCH] newlib: fix fseek optimization with SEEK_CUR Message-ID: <20200129180217.GR3549@calimero.vinschen.de> Reply-To: newlib@sourceware.org Mail-Followup-To: Bastien Bouclet , newlib@sourceware.org, Takashi Yano , Marco Atzeri References: <20191109162804.1905160-1-bastien.bouclet@gmail.com> <20191118101153.GB3372@calimero.vinschen.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="JF+ytOk7PH04NsRm" Content-Disposition: inline In-Reply-To: <20191118101153.GB3372@calimero.vinschen.de> X-IsSubscribed: yes X-SW-Source: 2020/txt/msg00037.txt --JF+ytOk7PH04NsRm Content-Type: multipart/mixed; boundary="rZHzn+A9B7nBTGyj" Content-Disposition: inline --rZHzn+A9B7nBTGyj Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-length: 1230 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(-) >=20 > 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 --=20 Corinna Vinschen Cygwin Maintainer Red Hat --rZHzn+A9B7nBTGyj Content-Type: text/plain; charset=utf-8 Content-Disposition: attachment; filename="conftest.c" Content-length: 1462 #include # include 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 */ /* 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; } --rZHzn+A9B7nBTGyj Content-Type: text/plain; charset=utf-8 Content-Disposition: attachment; filename="conftest.txt" Content-length: 13 hello world --rZHzn+A9B7nBTGyj-- --JF+ytOk7PH04NsRm Content-Type: application/pgp-signature; name="signature.asc" Content-length: 833 -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEoVYPmneWZnwT6kwF9TYGna5ET6AFAl4xyKkACgkQ9TYGna5E T6D8uQ/+IQVtqqJvVcb3/tqw4bGSafjbvYDSDs7J43zMFPYeWswn6GjWlAcIpUJn aQ6tGfPrE9S0uB6zilz79Y2MgWvV+88cxsvDDNUxqvQZVtnIQoUqRANSkv4mPG34 rTZZmlNKOeW0oG1JhlUy/2JHPj2R12saVD6NYjxHTRsiM9e+UscOjmqb53cxhfli B+unoPZm3xARgkPDAcx8BkKSfO47mvvY0az2QhgdaLlqwVyHfJkC9RMzxHlMY5OY L/XBIkkyaDuEFZThwqJ7X67JQIs78NAkGCDKb3pV0pvf+/4smDk/qKpmHDnYI7KQ LqTehrNUNPZa6B2T7KePebAmG+IB+aux+rmEpcdRzxicjcHMLWprc1SpLy0ytjVm g0JYVVAHyEqQN8sH6PJ9+PDX+nFNM9kF1RjGkRBQZIp5i3tRbrZapNKHkssEQ8XZ fv0Lvbsw/5g8Z1j1GAKbbMZPBc59k3w8tgm0bf4MRPVeR1mwSBud8vBK7J2vc7No dnowifQB+Dn0kAv4tGbho7qfRUyYULbOL6zLaC9xp561eN2Wyl9horDlnDaxVDA3 ET8K5ZYn216hhjqzyzo7Rrk6wxS1v8U+rsdGa0/NDZsVcThPg5BZckeMmsLpqI0L OYkw7COKIG3JZzhbqZQok6SzTGG0RHeYb4UtnvSnAqA57buOXfc= =xgxV -----END PGP SIGNATURE----- --JF+ytOk7PH04NsRm--