Author: sebor Date: Thu Dec 4 13:55:23 2008 New Revision: 723461 URL: http://svn.apache.org/viewvc?rev=723461&view=rev Log: 2008-12-04 Martin Sebor <[EMAIL PROTECTED]>
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. Added: stdcxx/branches/4.2.x/tests/regress/27.streambuf.sgetn.stdcxx-1026.cpp (with props) Modified: stdcxx/branches/4.2.x/include/streambuf.cc Modified: stdcxx/branches/4.2.x/include/streambuf.cc URL: http://svn.apache.org/viewvc/stdcxx/branches/4.2.x/include/streambuf.cc?rev=723461&r1=723460&r2=723461&view=diff ============================================================================== --- stdcxx/branches/4.2.x/include/streambuf.cc (original) +++ stdcxx/branches/4.2.x/include/streambuf.cc Thu Dec 4 13:55:23 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. * **************************************************************************/ @@ -34,6 +34,7 @@ template <class _CharT, class _Traits> basic_streambuf<_CharT, _Traits>:: basic_streambuf (ios_base::openmode __mode /* = ios_base::in | ios_base::out */) + _THROWS (()) : _C_buffer (0), _C_bufsize (0), _C_state (__mode), @@ -49,7 +50,7 @@ template <class _CharT, class _Traits> -_TYPENAME basic_streambuf<_CharT, _Traits>::int_type +typename basic_streambuf<_CharT, _Traits>::int_type basic_streambuf<_CharT, _Traits>:: uflow () { @@ -90,23 +91,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.2.x/tests/regress/27.streambuf.sgetn.stdcxx-1026.cpp URL: http://svn.apache.org/viewvc/stdcxx/branches/4.2.x/tests/regress/27.streambuf.sgetn.stdcxx-1026.cpp?rev=723461&view=auto ============================================================================== --- stdcxx/branches/4.2.x/tests/regress/27.streambuf.sgetn.stdcxx-1026.cpp (added) +++ stdcxx/branches/4.2.x/tests/regress/27.streambuf.sgetn.stdcxx-1026.cpp Thu Dec 4 13:55:23 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.2.x/tests/regress/27.streambuf.sgetn.stdcxx-1026.cpp ------------------------------------------------------------------------------ svn:eol-style = native Propchange: stdcxx/branches/4.2.x/tests/regress/27.streambuf.sgetn.stdcxx-1026.cpp ------------------------------------------------------------------------------ svn:keywords = Id