This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

libstdc++/6746


tested x86/linux

2002-11-11  Benjamin Kosnik  <bkoz@redhat.com>
 
        PR libstdc++/6746
        * include/bits/fstream.tcc (filebuf::open): Set input pointers.
	* config/io/basic_file_stdio.cc (__basic_file::_M_open_mode): Set
	__p_mode as well.
	(__basic_file::open): Set to non-block for input.
	* testsuite/27_io/istream_unformatted.cc (test12): Add.
	(test13): Same.


Index: config/io/basic_file_stdio.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/config/io/basic_file_stdio.cc,v
retrieving revision 1.5
diff -c -p -r1.5 basic_file_stdio.cc
*** config/io/basic_file_stdio.cc	30 Apr 2002 19:04:34 -0000	1.5
--- config/io/basic_file_stdio.cc	11 Nov 2002 23:16:02 -0000
***************
*** 32,37 ****
--- 32,38 ----
  //
  
  #include <bits/basic_file.h>
+ #include <fcntl.h>
  
  namespace std 
  {
*************** namespace std 
*** 43,50 ****
    { this->close(); }
        
    void 
!   __basic_file<char>::_M_open_mode(ios_base::openmode __mode, int&, int&, 
! 				   char* __c_mode)
    {  
      bool __testb = __mode & ios_base::binary;
      bool __testi = __mode & ios_base::in;
--- 44,51 ----
    { this->close(); }
        
    void 
!   __basic_file<char>::_M_open_mode(ios_base::openmode __mode, int& __p_mode, 
! 				   int&, char* __c_mode)
    {  
      bool __testb = __mode & ios_base::binary;
      bool __testi = __mode & ios_base::in;
*************** namespace std 
*** 52,69 ****
      bool __testt = __mode & ios_base::trunc;
      bool __testa = __mode & ios_base::app;
        
      if (!__testi && __testo && !__testt && !__testa)
!       strcpy(__c_mode, "w");
      if (!__testi && __testo && !__testt && __testa)
!       strcpy(__c_mode, "a");
      if (!__testi && __testo && __testt && !__testa)
!       strcpy(__c_mode, "w");
      if (__testi && !__testo && !__testt && !__testa)
!       strcpy(__c_mode, "r");
      if (__testi && __testo && !__testt && !__testa)
!       strcpy(__c_mode, "r+");
      if (__testi && __testo && __testt && !__testa)
!       strcpy(__c_mode, "w+");
      if (__testb)
        strcat(__c_mode, "b");
    }
--- 53,91 ----
      bool __testt = __mode & ios_base::trunc;
      bool __testa = __mode & ios_base::app;
        
+     // Set __c_mode for use in fopen.
+     // Set __p_mode for use in open.
      if (!__testi && __testo && !__testt && !__testa)
!       {
! 	strcpy(__c_mode, "w");
! 	__p_mode = (O_WRONLY | O_CREAT);
!       }
      if (!__testi && __testo && !__testt && __testa)
!       {
! 	strcpy(__c_mode, "a");
! 	__p_mode |=  O_WRONLY | O_CREAT | O_APPEND;
!       }
      if (!__testi && __testo && __testt && !__testa)
!       {
! 	strcpy(__c_mode, "w");
! 	__p_mode |=  O_WRONLY | O_CREAT | O_TRUNC;
!       }
! 
      if (__testi && !__testo && !__testt && !__testa)
!       {
! 	strcpy(__c_mode, "r");
! 	__p_mode |=  O_RDONLY | O_NONBLOCK;
!       }
      if (__testi && __testo && !__testt && !__testa)
!       {
! 	strcpy(__c_mode, "r+");
! 	__p_mode |=  O_RDWR | O_CREAT;
!       }
      if (__testi && __testo && __testt && !__testa)
!       {
! 	strcpy(__c_mode, "w+");
! 	__p_mode |=  O_RDWR | O_CREAT | O_TRUNC;
!       }
      if (__testb)
        strcat(__c_mode, "b");
    }
*************** namespace std 
*** 128,133 ****
--- 150,160 ----
  	if ((_M_cfile = fopen(__name, __c_mode)))
  	  {
  	    _M_cfile_created = true;
+ 
+ 	    // Set input to nonblocking for fifos.
+ 	    if (__mode & ios_base::in)
+ 	      fcntl(this->fd(), F_SETFL, O_NONBLOCK);
+ 
  	    __ret = this;
  	  }
        }
Index: include/bits/fstream.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/fstream.tcc,v
retrieving revision 1.41
diff -c -p -r1.41 fstream.tcc
*** include/bits/fstream.tcc	1 Nov 2002 17:30:35 -0000	1.41
--- include/bits/fstream.tcc	11 Nov 2002 23:16:02 -0000
*************** namespace std
*** 90,100 ****
--- 90,110 ----
  	    {
  	      _M_allocate_internal_buffer();
  	      _M_mode = __mode;
+ 
+ 	      // Setup initial position of buffer.
  	      _M_set_indeterminate();
  
+ 	      // Set input buffer to something real.
+ 	      // NB: Must open in non-blocking way to do this, or must
+ 	      // set the initial position in a different manner than
+ 	      // using underflow.
+  	      if (__mode & ios_base::in && _M_buf_allocated)
+  		this->underflow();
+ 	      
  	      if ((__mode & ios_base::ate)
  		  && this->seekoff(0, ios_base::end, __mode) < 0)
  		this->close();
+ 
  	      __ret = this;
  	    }
  	}
Index: testsuite/27_io/istream_unformatted.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/27_io/istream_unformatted.cc,v
retrieving revision 1.19
diff -c -p -r1.19 istream_unformatted.cc
*** testsuite/27_io/istream_unformatted.cc	5 Nov 2002 23:46:22 -0000	1.19
--- testsuite/27_io/istream_unformatted.cc	11 Nov 2002 23:16:04 -0000
*************** void test11()
*** 569,575 ****
    VERIFY(istr.rdstate() == ios_base::goodbit);
  }
  
! 
  int 
  main()
  {
--- 569,622 ----
    VERIFY(istr.rdstate() == ios_base::goodbit);
  }
  
! // libstdc++/6746   
! void test12()
! {
!   using namespace std;
!   bool test = true;
!   streamsize sum = 0;
!   istringstream iss("shamma shamma");
!       
!   // test01
!   size_t i = iss.rdbuf()->in_avail();
!   VERIFY( i != 0 );
!     
!   // test02
!   streamsize extracted;
!   do
!     {
!       char buf[1024];
!       extracted = iss.readsome(buf, sizeof buf);
!       sum += extracted;
!     }
!   while (iss.good() && extracted);
!   VERIFY( sum != 0 );  
! }
!     
! // libstdc++/6746   
! void test13()
! {
!   using namespace std;
!   bool test = true;
!   streamsize sum = 0;
!   ifstream ifs("istream_unformatted-1.tst");
!       
!   // test01
!   size_t i = ifs.rdbuf()->in_avail();
!   VERIFY( i != 0 );
!     
!   // test02
!   streamsize extracted;
!   do
!     {
!       char buf[1024];
!       extracted = ifs.readsome(buf, sizeof buf);
!       sum += extracted;
!     }
!   while (ifs.good() && extracted);
!   VERIFY( sum != 0 );  
! }
!  
  int 
  main()
  {
*************** main()
*** 584,588 ****
--- 631,639 ----
    test09();
    test10();
    test11();
+ 
+   test12();
+   test13();
+ 
    return 0;
  }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]