From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 42677 invoked by alias); 13 Mar 2016 00:37:21 -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 42666 invoked by uid 89); 13 Mar 2016 00:37:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=AWL,BAYES_00,FROM_STARTS_WITH_NUMS,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 spammy=liberty, swear, puzzled, H*f:sk:11ca145 X-HELO: smtp-out-so.shaw.ca Received: from smtp-out-so.shaw.ca (HELO smtp-out-so.shaw.ca) (64.59.136.138) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Sun, 13 Mar 2016 00:37:19 +0000 Received: from kylheku.com ([24.85.175.81]) by shaw.ca with SMTP id eu1za8JgJabIFeu20agLxq; Sat, 12 Mar 2016 17:37:16 -0700 X-Authority-Analysis: v=2.1 cv=Daa30qZW c=1 sm=1 tr=0 a=WiYoHcCliNeVponEdG0Ckg==:117 a=WiYoHcCliNeVponEdG0Ckg==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=IkcTkHD0fZMA:10 a=SMorJkV_YP8A:10 a=7OsogOcEt9IA:10 a=oKoJVJBDYDjnGgtDEGcA:9 a=QEXdDO2ut3YA:10 Received: from www-data by kylheku.com with local (Exim 4.72) (envelope-from <920-082-4242@kylheku.com>) id 1aeu1x-00025R-RF for cygwin@cygwin.com; Sat, 12 Mar 2016 16:37:13 -0800 To: cygwin@cygwin.com Subject: Re: Problem with line buffering and getc function on 1.7.33. X-PHP-Originating-Script: 501:rcmail.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable Date: Sun, 13 Mar 2016 00:37:00 -0000 From: Kaz Kylheku <920-082-4242@kylheku.com> In-Reply-To: <20160312222921.GD3567@calimero.vinschen.de> References: <56E34346.9010000@gmail.com> <11ca145175d5b7d15db927c0c1f28b18@mail.kylheku.com> <20160312193946.GB3567@calimero.vinschen.de> <20160312222921.GD3567@calimero.vinschen.de> Message-ID: X-Sender: 920-082-4242@kylheku.com User-Agent: Roundcube Webmail/0.9.2 X-CMAE-Envelope: MS4wfDP9QAlzLyNOEPPn5ac4/ZTiPwPzb6vdqVsfIKsCeWGQXVW03+BhN+chY2WWMAzYofHGX8iYzws5Qg51Ww8E3oc2fl88hJi7qWztFH+6F3GwU8USJ6Xm O6bdueNdhWM6sCnwca2khHYDiimbHnuIukyheqLrpDSDu1gOB+uv2/WK X-IsSubscribed: yes X-SW-Source: 2016-03/txt/msg00191.txt.bz2 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: >> > >> > #include >> > >> > int main(void) >> > { >> > FILE *out =3D fopen("file", "w+"); >> > setvbuf(out, (char *) NULL, _IOLBF, 0); >> > getc(out); >> > clearerr(out); >> > fseek(out, 0, SEEK_SET); >> > putc('a', out); >> > putc('b', out); >> > putc('c', out); >> > putc('d', out); >> > putc('e', out); >> > putc('\n', out); >> > fclose(out); >> > return 0; >> > } >> > >> > The contents of file end up being "\n": one empty >> > line, instead of "abcde\n": >> > >> > $ cat file >> > >> > $ >>=20 >> Thanks for the testcase. I can reproduce the issue and I see where=20 >> the >> problem occurs, but I'm still puzzled. Comparing the code in our=20 >> 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=20 >> why >> and where newlib's actually different. Right now I don't see the >> difference. >=20 > 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. 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: (gdb) n 8 getc(out); (gdb) p *out $2 =3D {_p =3D 0x80039c28 "", _r =3D 0, _w =3D 0, _flags =3D -30575, _file = =3D 3,=20 _bf =3D { ^^^^^^^^^^^^^^^^ _base =3D 0x80039c28 "", _size =3D 1024}, _lbfsize =3D -1024, _data = =3D 0x0, _cookie =3D 0x80039a30, _read =3D 0x61164cb0 <__sread>, _write =3D 0x61164f30 <__swrite64>, _seek =3D 0x61164e50 <__sseek>, _close =3D 0x61164ea0 <__sclose>, _ub =3D {_base =3D 0x0, _size =3D 0}, = _up =3D=20 0x0, _ur =3D 0, _ubuf =3D "\000\000", _nbuf =3D "", _lb =3D {_base =3D 0x0, _= size =3D=20 0}, _blksize =3D 0, _flags2 =3D 0, _offset =3D 0, _seek64 =3D 0x61164ed0=20 <__sseek64>, _lock =3D 0x80039bf8, _mbstate =3D {__count =3D 0, __value =3D {__wch = =3D 0, __wchb =3D "\000\000\000"}}} (gdb) n 9 clearerr(out); (gdb) p *out $3 =3D {_p =3D 0x80039c28 "", _r =3D 0, _w =3D 0, _flags =3D -22347, _file = =3D 3,=20 _bf =3D { ^^^^^^^^^^^^^^^^^^ _base =3D 0x80039c28 "", _size =3D 1024}, _lbfsize =3D -1024, _data = =3D 0x0, _cookie =3D 0x80039a30, _read =3D 0x61164cb0 <__sread>, _write =3D 0x61164f30 <__swrite64>, _seek =3D 0x61164e50 <__sseek>, _close =3D 0x61164ea0 <__sclose>, _ub =3D {_base =3D 0x0, _size =3D 0}, = _up =3D=20 0x0, _ur =3D 0, _ubuf =3D "\000\000", _nbuf =3D "", _lb =3D {_base =3D 0x0, _= size =3D=20 0}, _blksize =3D 0, _flags2 =3D 0, _offset =3D 0, _seek64 =3D 0x61164ed0=20 <__sseek64>, _lock =3D 0x80039bf8, _mbstate =3D {__count =3D 0, __value =3D {__wch = =3D 0, __wchb =3D "\000\000\000"}}} -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple