This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[PATCH] Fix libstdc++/9964
- From: Pétur Runólfsson <peturr02 at ru dot is>
- To: <libstdc++ at gcc dot gnu dot org>
- Cc: <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 13 Mar 2003 09:15:53 -0000
- Subject: [PATCH] Fix libstdc++/9964
Hi,
This fixes PR libstdc++/9964, which is a regression from gcc 2.95.3.
Tested on linux on x86.
Petur
2003-03-13 Petur Runolfsson <peturr02 at ru dot is>
PR libstdc++/9964
* include/bits/fstream.tcc (basic_filebuf::close):
Always close file, even when write fails.
* testsuite/27_io/filebuf_members.cc (test_07): New test.
Index: libstdc++-v3/include/bits/fstream.tcc
===================================================================
RCS file: /home/petur/cvsroot/gcc/libstdc++-v3/include/bits/fstream.tcc,v
retrieving revision 1.1.1.4
diff -c -3 -p -r1.1.1.4 fstream.tcc
*** libstdc++-v3/include/bits/fstream.tcc 12 Mar 2003 22:29:33 -0000 1.1.1.4
--- libstdc++-v3/include/bits/fstream.tcc 13 Mar 2003 00:22:14 -0000
*************** namespace std
*** 122,136 ****
basic_filebuf<_CharT, _Traits>::
close()
{
! __filebuf_type *__ret = NULL;
! if (this->is_open())
{
const int_type __eof = traits_type::eof();
bool __testput = this->_M_out_cur
&& this->_M_out_beg < this->_M_out_lim;
if (__testput
&& traits_type::eq_int_type(_M_really_overflow(__eof), __eof))
! return __ret;
// NB: Do this here so that re-opened filebufs will be cool...
this->_M_mode = ios_base::openmode(0);
--- 122,138 ----
basic_filebuf<_CharT, _Traits>::
close()
{
! __filebuf_type* __ret = this;
! if (!this->is_open())
! __ret = NULL;
! else
{
const int_type __eof = traits_type::eof();
bool __testput = this->_M_out_cur
&& this->_M_out_beg < this->_M_out_lim;
if (__testput
&& traits_type::eq_int_type(_M_really_overflow(__eof), __eof))
! __ret = NULL;
// NB: Do this here so that re-opened filebufs will be cool...
this->_M_mode = ios_base::openmode(0);
*************** namespace std
*** 146,153 ****
}
#endif
! if (_M_file.close())
! __ret = this;
}
_M_last_overflowed = false;
--- 148,155 ----
}
#endif
! if (!_M_file.close())
! __ret = NULL;
}
_M_last_overflowed = false;
Index: libstdc++-v3/testsuite/27_io/filebuf_members.cc
===================================================================
RCS file: /home/petur/cvsroot/gcc/libstdc++-v3/testsuite/27_io/filebuf_members.cc,v
retrieving revision 1.1.1.1
diff -c -3 -p -r1.1.1.1 filebuf_members.cc
*** libstdc++-v3/testsuite/27_io/filebuf_members.cc 15 Feb 2003 18:16:22 -0000 1.1.1.1
--- libstdc++-v3/testsuite/27_io/filebuf_members.cc 13 Mar 2003 00:04:26 -0000
***************
*** 1,4 ****
! // Copyright (C) 2001, 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
--- 1,4 ----
! // Copyright (C) 2001, 2002, 2003 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
*************** void test_06()
*** 217,222 ****
--- 217,260 ----
VERIFY( r == NULL );
}
+ // libstdc++/9964
+ void test_07()
+ {
+ using namespace std;
+ bool test = true;
+
+ const char* name = "zzz";
+
+ signal(SIGPIPE, SIG_IGN);
+
+ unlink(name);
+ mkfifo(name, S_IRWXU);
+
+ int child = fork();
+ VERIFY( child != -1 );
+
+ if (child == 0)
+ {
+ filebuf fbin;
+ fbin.open(name, ios_base::in);
+ sleep(1);
+ fbin.close();
+ exit(0);
+ }
+
+ filebuf fb;
+ filebuf* ret = fb.open(name, ios_base::out | ios_base::trunc);
+ VERIFY( ret != NULL );
+ VERIFY( fb.is_open() );
+
+ sleep(2);
+ fb.sputc('a');
+
+ ret = fb.close();
+ VERIFY( ret == NULL );
+ VERIFY( !fb.is_open() );
+ }
+
int
main()
{
*************** main()
*** 226,231 ****
--- 264,270 ----
test_04();
test_05();
test_06();
+ test_07();
return 0;
}