public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: libstdc++/9423: filebuf::pubsetbuf(0, 0) doesn't turn off buffering if called after open
@ 2003-04-14 17:03 bkoz
  0 siblings, 0 replies; 4+ messages in thread
From: bkoz @ 2003-04-14 17:03 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, paolo, peturr02

Synopsis: filebuf::pubsetbuf(0, 0) doesn't turn off buffering if called after open

State-Changed-From-To: analyzed->feedback
State-Changed-By: bkoz
State-Changed-When: Mon Apr 14 17:03:41 2003
State-Changed-Why:
    
    This is not a bug. 
    
    In 27.8.1.3 - Member functions [lib.filebuf.members], p 10
    
    basic_streambuf* setbuf(char_type* s, int n);
    
    -10- Effects: If setbuf(0,0) is called on a stream before any I/O has occured on that stream, the stream becomes unbuffered. Otherwise the results are implementation-defined. "Unbuffered" means that pbase() and pptr() always return null and output to the file should appear as soon as possible.
    
    Note the use of "any" before I/O. Open certainly counts in this regard. Although the standard is not as explicitly detailed as perhaps desired, gcc-2.95, icc-7.x, gcc-3.x seem to all agree on the current behavior. I also think it makes the most sense.
    
    I believe the documentation, as you pointed out, is wrong. The following change should be made:
    
       std::ofstream    os ("/foo/bar/baz");
       std::ifstream    is ("/qux/quux/quuux");
    
    to
    
       std::ofstream    os;
       std::ifstream    is;
    
    Also, I believe the Paolo, in proposing a change for this, has found some cleanups that still apply. 
    
         basic_filebuf<_CharT, _Traits>::
         setbuf(char_type* __s, streamsize __n)
         {
    -      if (!this->is_open() && __s == 0 && __n == 0)
    -	this->_M_buf_size = 0;
    +      if (__s == 0 && __n == 0)
    
    !is_open too
    
    +	{
    +	  this->_M_buf_size = 0;
    
    space before comment
    
    +	  // If setbuf(0, 0) is called before the first I/O
    +	  // operation, is guaranteed to work, even if is_open()
    +	  // is true. In that case, however, we destroy the
    +	  // current internal array.
    +	  if (this->is_open())
    +	    {
    +	      _M_destroy_internal_buffer();
    +	      _M_set_indeterminate();
    +	    }
    +	}
    
    all this no longer applies
    
           else if (__s && __n)
     	{
     	  // This is implementation-defined behavior, and assumes
    @@ -428,8 +439,6 @@
     	  // Step 2: Use the external array.
     	  this->_M_buf = __s;
     	  this->_M_buf_size = __n;
    -	  // Consistently set the end of buffer pointer.
    -	  this->_M_out_end = this->_M_buf + this->_M_buf_size;
    
    this is still ok
    
     	  _M_set_indeterminate();
     	}

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: libstdc++/9423: filebuf::pubsetbuf(0, 0) doesn't turn off buffering if called after open
@ 2003-04-15 22:46 paolo
  0 siblings, 0 replies; 4+ messages in thread
From: paolo @ 2003-04-15 22:46 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, paolo, peturr02

Synopsis: filebuf::pubsetbuf(0, 0) doesn't turn off buffering if called after open

State-Changed-From-To: feedback->closed
State-Changed-By: paolo
State-Changed-When: Tue Apr 15 22:46:29 2003
State-Changed-Why:
    Docs updated for 3.3 and 3.4.

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: libstdc++/9423: filebuf::pubsetbuf(0, 0) doesn't turn off buffering if called after open
@ 2003-03-02 18:39 paolo
  0 siblings, 0 replies; 4+ messages in thread
From: paolo @ 2003-03-02 18:39 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, nobody, paolo, peturr02

Synopsis: filebuf::pubsetbuf(0, 0) doesn't turn off buffering if called after open

Responsible-Changed-From-To: unassigned->paolo
Responsible-Changed-By: paolo
Responsible-Changed-When: Sun Mar  2 18:39:15 2003
Responsible-Changed-Why:
    Patching.
State-Changed-From-To: open->analyzed
State-Changed-By: paolo
State-Changed-When: Sun Mar  2 18:39:15 2003
State-Changed-Why:
    Confirmed. Should be rather easy to fix changing
    basic_filebuf::setbuf to _M_destroy_internal_buffer() even
    if this->is_open().

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* libstdc++/9423: filebuf::pubsetbuf(0, 0) doesn't turn off buffering if called after open
@ 2003-01-23 18:56 peturr02
  0 siblings, 0 replies; 4+ messages in thread
From: peturr02 @ 2003-01-23 18:56 UTC (permalink / raw)
  To: gcc-gnats


>Number:         9423
>Category:       libstdc++
>Synopsis:       filebuf::pubsetbuf(0, 0) doesn't turn off buffering if called after open
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Jan 23 18:56:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     peturr02@ru.is
>Release:        gcc-3.2.1
>Organization:
>Environment:
Red Hat Linux 8.0
>Description:
Given a filebuf fb, calling fb.pubsetbuf(0, 0) doesn't turn off buffering (as determined by fb.pptr()), if pubsetbuf is called after fb.open().

pubsetbuf(0, 0) is only guaranteed to work if called before the first I/O operation - I don't think open qualifies as an I/O operation.

In any case, this is at worst implementation defined behaviour, and the documentation at
http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html
states that this should work.
>How-To-Repeat:
See attachment.
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="setbufbug2.cc"
Content-Disposition: inline; filename="setbufbug2.cc"

#include <fstream>
using namespace std;

class Derived_filebuf : public filebuf
{
public:
	bool is_unbuffered() const
		{
			return pptr() == NULL && epptr() == NULL;
		}
};

int main()
{
	Derived_filebuf dfb;
	dfb.open("tmp", ios_base::out);
	dfb.pubsetbuf(0, 0);
	assert(dfb.is_unbuffered());
	return 0;
}


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-04-15 22:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-04-14 17:03 libstdc++/9423: filebuf::pubsetbuf(0, 0) doesn't turn off buffering if called after open bkoz
  -- strict thread matches above, loose matches on Subject: below --
2003-04-15 22:46 paolo
2003-03-02 18:39 paolo
2003-01-23 18:56 peturr02

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).