stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject svn commit: r725458 - in /stdcxx/branches/4.3.x: include/streambuf.cc tests/regress/27.streambuf.sgetn.stdcxx-1026.cpp
Date Wed, 10 Dec 2008 22:08:13 GMT
Author: sebor
Date: Wed Dec 10 14:08:12 2008
New Revision: 725458

URL: http://svn.apache.org/viewvc?rev=725458&view=rev
Log:
2008-12-10  Martin Sebor  <sebor@apache.org>

	Merged revs 723461 and 723465 from 4.2.x.

	2008-12-04  Martin Sebor  <sebor@apache.org>

	STDCXX-1026
	* include/streambuf.cc (basic_streambuf::xsgetn): Removed
	assumption that empty get area implies empty pending sequence.
	* tests/regress/27.streambuf.sgetn.stdcxx-1026.cpp: New test.

	2008-12-04  Martin Sebor  <sebor@apache.org>

	* streambuf.cc (basic_streambuf::uflow): Reverted "_TYPENAME"
	to "typename" change inadvertently introduced in rev 723461.

Added:
    stdcxx/branches/4.3.x/tests/regress/27.streambuf.sgetn.stdcxx-1026.cpp   (with props)
Modified:
    stdcxx/branches/4.3.x/include/streambuf.cc

Modified: stdcxx/branches/4.3.x/include/streambuf.cc
URL: http://svn.apache.org/viewvc/stdcxx/branches/4.3.x/include/streambuf.cc?rev=725458&r1=725457&r2=725458&view=diff
==============================================================================
--- stdcxx/branches/4.3.x/include/streambuf.cc (original)
+++ stdcxx/branches/4.3.x/include/streambuf.cc Wed Dec 10 14:08:12 2008
@@ -23,7 +23,7 @@
  * implied.   See  the License  for  the  specific language  governing
  * permissions and limitations under the License.
  *
- * Copyright 1994-2006 Rogue Wave Software.
+ * Copyright 1994-2006 Rogue Wave Software, Inc.
  * 
  **************************************************************************/
 
@@ -90,23 +90,35 @@
         // number of characters available in get area
         streamsize __navail = egptr () - gptr ();
 
-        if (0 == __navail)
-            break;
-
-        if (__navail > __n)
-            __navail = __n;
-
-        // copy contents of get area to the destination buffer
-        traits_type::copy (__buf + __nget, gptr (), __navail);
-
-        // increment pointers and counts by the number of characters copied
-        gbump (__navail);
-        __n    -= __navail;
-        __nget += __navail;
-
-        // break out on underflow error
-        if (traits_type::eq_int_type (__c, traits_type::eof ()))
+        if (0 < __navail) {
+            if (__navail > __n)
+                __navail = __n;
+
+            // copy contents of get area to the destination buffer
+            traits_type::copy (__buf + __nget, gptr (), __navail);
+
+            // increment pointers and counts by the number of characters
+            // copied
+            gbump (__navail);
+            __n    -= __navail;
+            __nget += __navail;
+        }
+        else if (traits_type::eq_int_type (__c, traits_type::eof ())) {
+            // break out on underflow() failure (e.g., reaching EOF)
             break;
+        }
+        else {
+            // unbuffered mode: empty pending seuqence but non-EOF
+            // overflow() return value
+
+            // append character returned by underflow()
+            traits_type::assign (__buf [__nget],
+                                 traits_type::to_char_type (__c));
+
+            // avoid incrementing egptr() but adjust counters
+            --__n;
+            ++__nget;
+        }
     }
 
     return __nget;

Added: stdcxx/branches/4.3.x/tests/regress/27.streambuf.sgetn.stdcxx-1026.cpp
URL: http://svn.apache.org/viewvc/stdcxx/branches/4.3.x/tests/regress/27.streambuf.sgetn.stdcxx-1026.cpp?rev=725458&view=auto
==============================================================================
--- stdcxx/branches/4.3.x/tests/regress/27.streambuf.sgetn.stdcxx-1026.cpp (added)
+++ stdcxx/branches/4.3.x/tests/regress/27.streambuf.sgetn.stdcxx-1026.cpp Wed Dec 10 14:08:12
2008
@@ -0,0 +1,58 @@
+/************************************************************************
+ *
+ * 27.streambuf.sgetn.stdcxx-1026.cpp - regression test for STDCXX-1026
+ *
+ * http://issues.apache.org/jira/browse/STDCXX-1026
+ *
+ * $Id$
+ *
+ ***************************************************************************
+ *
+ * Licensed to the Apache Software  Foundation (ASF) under one or more
+ * contributor  license agreements.  See  the NOTICE  file distributed
+ * with  this  work  for  additional information  regarding  copyright
+ * ownership.   The ASF  licenses this  file to  you under  the Apache
+ * License, Version  2.0 (the  "License"); you may  not use  this file
+ * except in  compliance with the License.   You may obtain  a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the  License is distributed on an  "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY  KIND, either  express or
+ * implied.   See  the License  for  the  specific language  governing
+ * permissions and limitations under the License.
+ * 
+ **************************************************************************/
+
+#include <cassert>
+#include <istream>
+#include <streambuf>
+
+int main ()
+{
+    static int x = '0';
+
+    struct: std::streambuf {
+        // unbuffered, always successfully reads one character
+        int_type underflow () {
+            assert (gptr () == egptr ());
+            return x++;
+        }
+    } sb;
+
+    // "endless" stream that never reaches EOF
+    std::istream endless (&sb);
+
+    char s [4] = "";
+
+    endless.read (s, sizeof s);
+ 
+    // expect to find stream in good state (i.e., not EOF) and
+    // to have extracted as many characters as requested with
+    // just as many calls to underflow()
+    assert (endless.good ());
+    assert (sizeof s == endless.gcount ());
+    assert ('0' == s [0] && '1' == s [1] && '2' == s [2] && '3' ==
s [3]);
+}

Propchange: stdcxx/branches/4.3.x/tests/regress/27.streambuf.sgetn.stdcxx-1026.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: stdcxx/branches/4.3.x/tests/regress/27.streambuf.sgetn.stdcxx-1026.cpp
------------------------------------------------------------------------------
    svn:keywords = Id



Mime
View raw message