Commit e6705174 by Benjamin Kosnik Committed by Benjamin Kosnik

fstream.tcc (filebuf::close()): Fix close for input streams.


2002-01-25  Benjamin Kosnik  <bkoz@redhat.com>

	* include/bits/fstream.tcc (filebuf::close()): Fix close for input
	streams.
	(filebuf::_M_really_overflow): Match indeterminate and sync calls.
	* testsuite/27_io/filebuf.cc: Compile only.
	* testsuite/27_io/filebuf_members.cc: Move tests to here.
	* testsuite/27_io/filebuf_virtuals.cc: And here.
	Revert sungetc, sync changes for expected values.
	* testsuite/27_io/filebuf-*: Move to...
	* testsuite/27_io/filebuf_virtuals-*: ...here.
	* testsuite/27_io/istream.cc: Compile only, activate.
	* testsuite/27_io/ostream.cc: Same.
	* testsuite/27_io/iostream.cc: New.
	* testsuite/27_io/iostream_members.cc: New.

From-SVN: r49236
parent 751551d5
2002-01-25 Benjamin Kosnik <bkoz@redhat.com>
* include/bits/fstream.tcc (filebuf::close()): Fix close for input
streams.
(filebuf::_M_really_overflow): Match indeterminate and sync calls.
* testsuite/27_io/filebuf.cc: Compile only.
* testsuite/27_io/filebuf_members.cc: Move tests to here.
* testsuite/27_io/filebuf_virtuals.cc: And here.
Revert sungetc, sync changes for expected values.
* testsuite/27_io/filebuf-*: Move to...
* testsuite/27_io/filebuf_virtuals-*: ...here.
* testsuite/27_io/istream.cc: Compile only, activate.
* testsuite/27_io/ostream.cc: Same.
* testsuite/27_io/iostream.cc: New.
* testsuite/27_io/iostream_members.cc: New.
2002-01-25 David Billinghurst <David.Billinghurst@riotinto.com> 2002-01-25 David Billinghurst <David.Billinghurst@riotinto.com>
* testsuite/thread/pthread1.cc: Enable on cygwin. * testsuite/thread/pthread1.cc: Enable on cygwin.
......
// File based streams -*- C++ -*- // File based streams -*- C++ -*-
// Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc. // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
// Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the // software; you can redistribute it and/or modify it under the
...@@ -181,31 +182,31 @@ namespace std ...@@ -181,31 +182,31 @@ namespace std
__filebuf_type *__ret = NULL; __filebuf_type *__ret = NULL;
if (this->is_open()) if (this->is_open())
{ {
const int_type __eof = traits_type::eof();
bool __testput = _M_out_cur && _M_out_beg < _M_out_end; bool __testput = _M_out_cur && _M_out_beg < _M_out_end;
if (__testput if (__testput && _M_really_overflow(__eof) == __eof)
&& _M_really_overflow(traits_type::eof()) != traits_type::eof()) return __ret;
{
// NB: Do this here so that re-opened filebufs will be cool...
_M_mode = ios_base::openmode(0);
_M_destroy_internal_buffer();
_M_pback_destroy();
if (_M_pback)
{
delete [] _M_pback;
_M_pback = NULL;
}
// NB: Do this here so that re-opened filebufs will be cool...
_M_mode = ios_base::openmode(0);
_M_destroy_internal_buffer();
_M_pback_destroy();
if (_M_pback)
{
delete [] _M_pback;
_M_pback = NULL;
}
#if 0 #if 0
// XXX not done // XXX not done
if (_M_last_overflowed) if (_M_last_overflowed)
{ {
_M_output_unshift(); _M_output_unshift();
_M_really_overflow(traits_type::eof()); _M_really_overflow(__eof);
} }
#endif #endif
__ret = this; __ret = this;
}
} }
// Can actually allocate this file as part of an open and never // Can actually allocate this file as part of an open and never
...@@ -429,11 +430,11 @@ namespace std ...@@ -429,11 +430,11 @@ namespace std
// NB: Need this so that external byte sequence reflects // NB: Need this so that external byte sequence reflects
// internal buffer. // internal buffer.
if (__len == __plen) if (__len == __plen && !_M_file->sync())
_M_set_indeterminate(); {
_M_set_indeterminate();
if (!_M_file->sync()) __ret = traits_type::not_eof(__c);
__ret = traits_type::not_eof(__c); }
#else #else
// Part one: Allocate temporary conversion buffer on // Part one: Allocate temporary conversion buffer on
// stack. Convert internal buffer plus __c (ie, // stack. Convert internal buffer plus __c (ie,
...@@ -609,3 +610,8 @@ namespace std ...@@ -609,3 +610,8 @@ namespace std
#endif // _CPP_BITS_FSTREAM_TCC #endif // _CPP_BITS_FSTREAM_TCC
// Copyright (C) 2001 Free Software Foundation, Inc. // Copyright (C) 2001, 2002 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the // software; you can redistribute it and/or modify it under the
...@@ -32,21 +32,55 @@ ...@@ -32,21 +32,55 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
// verify that std::filebuf doesn't close files that it didn't open const char name_01[] = "filebuf_members-1.tst";
const char name_02[] = "filebuf_members-1.txt";
// Test member functions.
void test_01()
{
bool test = true;
const char* name_03 = "filebuf_members-3"; // empty file, need to create
std::filebuf fb_01; // in
std::filebuf fb_02; // out
std::filebuf fb_03; // in | out
// bool is_open()
VERIFY( !fb_01.is_open() );
VERIFY( !fb_02.is_open() );
VERIFY( !fb_03.is_open() );
// filebuf_type* open(const char* __s, ios_base::openmode __mode)
fb_01.open(name_01, std::ios_base::in | std::ios_base::ate);
fb_02.open(name_02, std::ios_base::in | std::ios_base::out
| std::ios_base::trunc);
// Try to open two different files without closing the first:
// Should keep the old file attached, and disregard attempt to overthrow.
fb_02.open(name_03, std::ios_base::in | std::ios_base::out);
fb_03.open(name_03, std::ios_base::out | std::ios_base::trunc);
VERIFY( fb_01.is_open() );
VERIFY( fb_02.is_open() );
VERIFY( fb_03.is_open() );
// filebuf_type* close()
fb_01.close();
fb_02.close();
fb_03.close();
VERIFY( !fb_01.is_open() );
VERIFY( !fb_02.is_open() );
VERIFY( !fb_03.is_open() );
}
// Verify that std::filebuf doesn't close files that it didn't open
// when using the following std::filebuf ctor: // when using the following std::filebuf ctor:
// //
// std::filebuf(__c_file_type* __f, // std::filebuf(__c_file_type* __f,
// ios_base::openmode __mode, // ios_base::openmode __mode,
// int_type __s); // int_type __s);
// //
// thanks to "George T. Talbot" <george@moberg.com> for uncovering // Thanks to "George T. Talbot" <george@moberg.com> for uncovering
// this bug/situation. // this bug/situation.
void test_02()
const char name_01[] = "filebuf_members-1.tst";
const char name_02[] = "filebuf_members-1.txt";
int
test_01()
{ {
bool test = true; bool test = true;
int close_num; int close_num;
...@@ -72,17 +106,9 @@ test_01() ...@@ -72,17 +106,9 @@ test_01()
} }
close_num = fclose(f); close_num = fclose(f);
VERIFY( close_num == 0 ); VERIFY( close_num == 0 );
#ifdef DEBUG_ASSERT
assert(test);
#endif
return test;
} }
int void test_03()
test_02()
{ {
bool test = true; bool test = true;
int first_fd = ::open(name_01, O_RDONLY); int first_fd = ::open(name_01, O_RDONLY);
...@@ -93,19 +119,13 @@ test_02() ...@@ -93,19 +119,13 @@ test_02()
int second_fd = fb.fd(); int second_fd = fb.fd();
test = first_fd == second_fd; VERIFY( first_fd == second_fd );
#ifdef DEBUG_ASSERT
assert(test);
#endif
return test;
} }
// libstdc++/2913, libstdc++/4879 // libstdc++/2913, libstdc++/4879
// John Fardo <jfardo@laurelnetworks.com>, Brad Garcia <garsh@attbi.com> // John Fardo <jfardo@laurelnetworks.com>, Brad Garcia <garsh@attbi.com>
void void
test_03() test_04()
{ {
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
...@@ -159,7 +179,9 @@ main() ...@@ -159,7 +179,9 @@ main()
{ {
test_01(); test_01();
test_02(); test_02();
test_03(); test_03();
test_04();
return 0; return 0;
} }
// 2002-01-08 bkoz
// Copyright (C) 2002 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
// 27.6.1.5 - Template class basic_iostream
// NB: This file is for testing iostream with NO OTHER INCLUDES.
// { dg-do compile }
#include <istream>
namespace test
{
using namespace std;
typedef short type_t;
template class basic_iostream<type_t, char_traits<type_t> >;
} // test
int main()
{
return 0;
}
// 2002-01-08 bkoz
// Copyright (C) 2002 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
// 27.6.1.5 - Template class basic_iostream
// NB: This file is for testing iostream with NO OTHER INCLUDES.
#include <iostream>
// libstdc++/3647
void test07()
{
// Should not block.
std::cout << std::cin.rdbuf()->in_avail() << std::endl;
}
int main()
{
test07();
return 0;
}
// 1999-09-20 bkoz // 1999-09-20 bkoz
// Copyright (C) 1999, 2000 Free Software Foundation, Inc. // Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the // software; you can redistribute it and/or modify it under the
...@@ -32,26 +32,16 @@ ...@@ -32,26 +32,16 @@
#include <istream> #include <istream>
namespace test { // { dg-do compile }
#if 0 namespace test
// XXX Should work, but doesn't. {
using namespace std; using namespace std;
typedef short type_t; typedef short type_t;
template class basic_istream<type_t, char_traits<type_t> >; template class basic_istream<type_t, char_traits<type_t> >;
template
const ctype<type_t>&
use_facet<ctype<type_t> >(const locale&);
typedef istreambuf_iterator<type_t, char_traits<type_t> > traits_t;
template
const num_get<type_t, traits_t>&
use_facet<num_get<type_t, traits_t> >(const locale&);
#endif
} // test } // test
int main() { int main()
{
return 0; return 0;
} }
// 1999-09-20 bkoz // 1999-09-20 bkoz
// Copyright (C) 1999, 2000 Free Software Foundation, Inc. // Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the // software; you can redistribute it and/or modify it under the
...@@ -32,17 +32,16 @@ ...@@ -32,17 +32,16 @@
#include <ostream> #include <ostream>
namespace test { // { dg-do compile }
#if 0 namespace test
// XXX Should work, but doesn't. {
using namespace std; using namespace std;
typedef short type_t; typedef short type_t;
template class basic_ostream<type_t, char_traits<type_t> >; template class basic_ostream<type_t, char_traits<type_t> >;
#endif
} // test } // test
int main() { int main()
{
return 0; return 0;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment