public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: bkoz@gcc.gnu.org
To: bkoz@gcc.gnu.org, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org,
	tony.oliver@mci.co.uk
Subject: Re: libstdc++/6746: ifstream::readsome() always returns zero
Date: Thu, 04 Jul 2002 17:39:00 -0000	[thread overview]
Message-ID: <20020705003954.29304.qmail@sources.redhat.com> (raw)

Synopsis: ifstream::readsome() always returns zero

State-Changed-From-To: analyzed->open
State-Changed-By: bkoz
State-Changed-When: Thu Jul  4 17:39:53 2002
State-Changed-Why:
    It looks like I am not going to be able to fix this before I leave. I'll resume looking at it after I get back, say July 23 rd ish...
    
    In sum, it looks like the patch to libstdc++/3647 was wrong.  At this point, rdbuf()->in_avail() is returning 0 for newly opened istreams (that are not empty.). This is incorrect.
    
    I suspect that the way to solve this is to set _M_buf and friends to real values instead of indeterminate values in filebuf's ctors. I did work up a partial solution to this based on this approach, but cannot find it at the moment.
    
    Here's another testcase for this
    
    #include <fstream>
    #include <sstream>
    #include <iostream>
    
    void test01()
    {
      using namespace std;
      streamsize sum = 0;
      istringstream iss("shamma shamma");
      
      // test01
      size_t i = iss.rdbuf()->in_avail();
      cout << i << endl;
    
      // test02
      size_t max = 0;
      while (iss.good() && max < 10)
        {
          char buf[1024];
          streamsize gotten = iss.readsome(buf, sizeof buf);
          sum += gotten;
          cout << gotten << " (" << sum << ")" << endl;
          ++max;
        }
    }
    
    void test02()
    {
      using namespace std;
      streamsize sum = 0;
      ifstream ifs(__FILE__);
      
      // test01
      size_t i = ifs.rdbuf()->in_avail();
      cout << i << endl;
    
      // test02
      size_t max = 0;
      while (ifs.good() && max < 10)
        {
          char buf[1024];
          streamsize gotten = ifs.readsome(buf, sizeof buf);
          sum += gotten;
          cout << gotten << " (" << sum << ")" << endl;
          ++max;
        }
    }
    
    int main()
    {
      test01();
      test02();
      return 0;
    }

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6746


             reply	other threads:[~2002-07-05  0:39 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-04 17:39 bkoz [this message]
  -- strict thread matches above, loose matches on Subject: below --
2002-11-23  6:06 bkoz
2002-11-19 12:32 bkoz
2002-05-29  8:56 bkoz
2002-05-26  4:16 Paolo Carlini
2002-05-20 13:39 paolo
2002-05-20 10:57 paolo
2002-05-20 10:16 tony.oliver

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=20020705003954.29304.qmail@sources.redhat.com \
    --to=bkoz@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    --cc=gcc-gnats@gcc.gnu.org \
    --cc=gcc-prs@gcc.gnu.org \
    --cc=tony.oliver@mci.co.uk \
    /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).