From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3827 invoked by alias); 13 Mar 2016 10:47:16 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 3819 invoked by uid 89); 13 Mar 2016 10:47:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-96.6 required=5.0 tests=BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_PBL,RDNS_DYNAMIC,USER_IN_WHITELIST autolearn=no version=3.3.2 spammy=H*i:sk:ebae781, H*f:sk:ebae781, HX-Envelope-From:sk:corinna, Hx-languages-length:2261 X-HELO: calimero.vinschen.de Received: from ipbcc0d020.dynamic.kabel-deutschland.de (HELO calimero.vinschen.de) (188.192.208.32) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 13 Mar 2016 10:47:14 +0000 Received: by calimero.vinschen.de (Postfix, from userid 500) id 3A570A8053A; Sun, 13 Mar 2016 11:47:12 +0100 (CET) Date: Sun, 13 Mar 2016 10:47:00 -0000 From: Corinna Vinschen To: cygwin@cygwin.com Subject: Re: Problem with line buffering and getc function on 1.7.33. Message-ID: <20160313104712.GC25791@calimero.vinschen.de> Reply-To: cygwin@cygwin.com Mail-Followup-To: cygwin@cygwin.com References: <56E34346.9010000@gmail.com> <11ca145175d5b7d15db927c0c1f28b18@mail.kylheku.com> <20160312193946.GB3567@calimero.vinschen.de> <20160312222921.GD3567@calimero.vinschen.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="bg08WKrSYDhXBjb5" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-SW-Source: 2016-03/txt/msg00198.txt.bz2 --bg08WKrSYDhXBjb5 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-length: 2277 On Mar 12 16:37, Kaz Kylheku wrote: > On 12.03.2016 14:29, Corinna Vinschen wrote: > >On Mar 12 20:39, Corinna Vinschen wrote: > >>On Mar 11 16:05, Kaz Kylheku wrote: > >>> We can reproduce the problem with just file streams using > >>> a much simpler program: > >>> [...] > >>> The contents of file end up being "\n": one empty > >>> line, instead of "abcde\n": > >>> > >>> $ cat file > >>> > >>> $ > >> > >>Thanks for the testcase. I can reproduce the issue and I see where the > >>problem occurs, but I'm still puzzled. Comparing the code in our newlib > >>C library with its BSD counterparts, I could swear the same behaviour > >>happens on OpenBSD as well. If not (which needs testing), I wonder why > >>and where newlib's actually different. Right now I don't see the > >>difference. > > > >I do now. Basically it's setvbuf screwing up the internal flags in the > >FILE structure. I took the liberty to update newlib's setvbuf to the > >OpenBSD version locally and I'm going to apply my patches to newlib > >soon. I'll provide a new 2.5.0 test release of Cygwin with this patch > >tomorrow or early next week. >=20 >=20 > Indeed, I thought it would have something to do with the > stream->_flags, because when I single-stepped over the getc(stream) > line (necessary for the problem to repro, IIRC) the only apparent state > change in the stream was to the _flags member: The actual problem was that setvbuf set the _lbfsize member to -bufsize in the _IOLBF case indiscriminately. This in turn leads to __sputc_r doing the wrong thing: if (--_p->_w >=3D 0 || (_p->_w >=3D _p->_lbfsize && (char)_c !=3D '\n')) return (*_p->_p++ =3D _c); else return (__swbuf_r(_ptr, _c, _p)); Note the check for _p->_w >=3D _p->_lbfsize. By setting _lbfsize in setvbuf, what happens is that the first branch is called for all chars up to the first \n. However, the *first* call to __sputc_r is supposed to call __swbuf_r anyway, otherwise bookkeeping is broken. And that's the major difference to the OpenBSD setvbuf; it only sets fp->_lbfsize to -bufsize if we're already writing (__SWR flag is set). Corinna --=20 Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Maintainer cygwin AT cygwin DOT com Red Hat --bg08WKrSYDhXBjb5 Content-Type: application/pgp-signature; name="signature.asc" Content-length: 819 -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJW5UUwAAoJEPU2Bp2uRE+gG3cP/0clqnKWXso9bLKcv3hCZ+xn QybqDtz6G/whVe/cgMHMS3euVM2p/Sl7vQGltobBOGtxEtRd+hxUYlDgnfNaCSJ+ OUP3re7Vkw5sKRuraOtgDyxDbbQZxt+uJVHjwW2/XCYla3P+eatKerqgoXKP/irM dhkd4CaNaO/WePC1ARBSlMxcDDMoyAqxyu3HMgryWvE9lP7mHVeYL3YNogxSMTM7 DVq1yvaRM27c3uvgZD4w1nyi/jSGcfz00l2DBcpGqAD8LY51Q79czDWgo2mDN0h4 rCQ3DeoHkfDY3a5/yXaLx72x1Tswh8jio4jbdMwKWuCY2oOzZ0KnFwtpeFHfqSoE lQyqWUWMM6pueBLaiJi9zNCBVKL/er+HqG8lQ6U5EaP+jmns79OEeFJRvX4QM61A fHulzO/JloNzjdwtvWnprFnS/II0QDA3D5XFFbPo+yDKBhmSny1hdiOvsLq15Jl5 Z2I0xF7sM6Tle5t88MpKCCKecv4US/2kWZpiWnk2X4XPF4rFEaRxPXx3WXX92iaf MJtV8mVv+2otg7OFOSQs6fqDwODi/HTJ2vKs4Xb3Z8Ggx4BRvRKLsT7k9kQOckpQ I/nJWCJL0n5bOfJGOxUvQP/ty4U4yII2/OVjav1WerkNIJ9E3o5/CEUC5xUiV60G ps+6LlPYL5UP7s2KtL6p =4PKV -----END PGP SIGNATURE----- --bg08WKrSYDhXBjb5--