public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Kaz Kylheku <920-082-4242@kylheku.com>
To: cygwin@cygwin.com
Subject: Re: Problem with line buffering and getc function on 1.7.33.
Date: Sun, 13 Mar 2016 00:37:00 -0000	[thread overview]
Message-ID: <ebae78105462dee607c99bc191f797fc@mail.kylheku.com> (raw)
In-Reply-To: <20160312222921.GD3567@calimero.vinschen.de>

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 <stdio.h>
>> >
>> > int main(void)
>> > {
>> >   FILE *out = 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
>> >
>> >   $
>> 
>> 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.


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 = {_p = 0x80039c28 "", _r = 0, _w = 0, _flags = -30575, _file = 3, 
_bf = {
                                           ^^^^^^^^^^^^^^^^

     _base = 0x80039c28 "", _size = 1024}, _lbfsize = -1024, _data = 0x0,
   _cookie = 0x80039a30, _read = 0x61164cb0 <__sread>,
   _write = 0x61164f30 <__swrite64>, _seek = 0x61164e50 <__sseek>,
   _close = 0x61164ea0 <__sclose>, _ub = {_base = 0x0, _size = 0}, _up = 
0x0,
   _ur = 0, _ubuf = "\000\000", _nbuf = "", _lb = {_base = 0x0, _size = 
0},
   _blksize = 0, _flags2 = 0, _offset = 0, _seek64 = 0x61164ed0 
<__sseek64>,
   _lock = 0x80039bf8, _mbstate = {__count = 0, __value = {__wch = 0,
       __wchb = "\000\000\000"}}}
(gdb) n
9         clearerr(out);
(gdb) p *out
$3 = {_p = 0x80039c28 "", _r = 0, _w = 0, _flags = -22347, _file = 3, 
_bf = {
                                          ^^^^^^^^^^^^^^^^^^

     _base = 0x80039c28 "", _size = 1024}, _lbfsize = -1024, _data = 0x0,
   _cookie = 0x80039a30, _read = 0x61164cb0 <__sread>,
   _write = 0x61164f30 <__swrite64>, _seek = 0x61164e50 <__sseek>,
   _close = 0x61164ea0 <__sclose>, _ub = {_base = 0x0, _size = 0}, _up = 
0x0,
   _ur = 0, _ubuf = "\000\000", _nbuf = "", _lb = {_base = 0x0, _size = 
0},
   _blksize = 0, _flags2 = 0, _offset = 0, _seek64 = 0x61164ed0 
<__sseek64>,
   _lock = 0x80039bf8, _mbstate = {__count = 0, __value = {__wch = 0,
       __wchb = "\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

  reply	other threads:[~2016-03-13  0:37 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-11 21:57 Kaz Kylheku
2016-03-11 22:14 ` Marco Atzeri
2016-03-12  0:05   ` Kaz Kylheku
2016-03-12 19:39     ` Corinna Vinschen
2016-03-12 22:29       ` Corinna Vinschen
2016-03-13  0:37         ` Kaz Kylheku [this message]
2016-03-13 10:47           ` Corinna Vinschen
2016-03-13  0:41         ` Kaz Kylheku
2016-03-13 11:06           ` Corinna Vinschen
2016-03-13 11:37             ` Corinna Vinschen
  -- strict thread matches above, loose matches on Subject: below --
2016-03-11 19:17 Kaz Kylheku
2016-03-11 20:09 ` Yaakov Selkowitz

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=ebae78105462dee607c99bc191f797fc@mail.kylheku.com \
    --to=920-082-4242@kylheku.com \
    --cc=cygwin@cygwin.com \
    /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).