This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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]

[v3] remove non-standard basic_filebuf members, fd, FILE filebufs



This patch is posted for discussion only. I'm curious to see what
other people think.

In std::basic_filebuf, there's a non-standard constructor that takes a
FILE* as an argument. The non-standard constructor has, in previous
incarnations, taken a file descriptor as an argument. It also has an
unmangled, non-standard member function fd().

This patch removes both items from basic_filebuf, the assorted hacks
to streamline allocations for unbuffered streams, and provides two new
derived filebufs, one taking a FILE*, the other a file
descriptor. Both seem to be useful, both seem to have uses, and there
have been requests for both on a regular basis. Slight modifications
to __basic_file were necessary. 

Also, I added the enc_filebuf.h that I used to do encoding-variable
filebufs. I plan on adding tests and documentation for this in the
near future.

I think derivation is really the way to go with respect to wringing
additional functionality out of streambufs and filebufs in
particular. Using derivation instead of non-standard ctors clarifies
what is non-standard behavior, while at the same time removing clutter
from base classes. 

Thoughts?

-benjamin

tested x86/linux

2002-04-26  Benjamin Kosnik  <bkoz@redhat.com>

	* include/ext/fd_filebuf.h: New file.
	* include/ext/file_filebuf.h: New file.	
	* include/ext/enc_filebuf.h: New file.	
	* config/io/basic_file_stdio.h (__basic_file::sys_open): Add fd ctor.
	* config/io/basic_file_stdio.cc: Same.	
	* include/bits/fstream.tcc (filebuf::_M_allocate_internal_buffer):
	Remove _M_unbuf hacks.
	(filebuf::_M_destroy_internal_buffer): Same.
	(filebuf::filebuf(cfile, openmode, int_type): Remove definition.
	(filebuf::fd): Remove.
	* include/std/std_fstream.h (filebuf::_M_unbuf): Remove.
	(filebuf::filebuf(__c_file*, openmode, int_type)): Remove.
	(filebuf::fd): Remove.	
	* src/ios.cc (ios_base::_S_ios_create): Change to use specialized
	filebufs.
	(ios_base::_S_ios_destroy): Same.
	* src/misc-inst.cc (file_filebuf<char>): Add instantiation.
	* include/Makefile.am (ext_headers): Add fd_filebuf.h, file_filebuf.h.
	* include/Makefile.in: Regenerate.

Index: config/io/basic_file_stdio.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/config/io/basic_file_stdio.cc,v
retrieving revision 1.3
diff -c -p -r1.3 basic_file_stdio.cc
*** config/io/basic_file_stdio.cc	16 Apr 2002 00:45:14 -0000	1.3
--- config/io/basic_file_stdio.cc	27 Apr 2002 04:34:04 -0000
*************** namespace std 
*** 74,91 ****
      __basic_file* __ret = NULL;
      if (!this->is_open() && __file)
        {
! 	_M_cfile = __file;
! 	_M_cfile_created = false;
  	__ret = this;
        }
      return __ret;
    }
  
    char
!   __basic_file<char>::sys_getc() { return getc (_M_cfile); }
    
    char
!   __basic_file<char>::sys_ungetc(char __s) { return ungetc (__s, _M_cfile); }
    
    __basic_file<char>* 
    __basic_file<char>::open(const char* __name, ios_base::openmode __mode, 
--- 74,116 ----
      __basic_file* __ret = NULL;
      if (!this->is_open() && __file)
        {
!  	_M_cfile = __file;
!  	_M_cfile_created = false;
!   	__ret = this;
!       }
!     return __ret;
!   }
!   
!   __basic_file<char>*
!   __basic_file<char>::sys_open(int __fd, ios_base::openmode __mode, 
! 			       bool __del) 
!   {
!     __basic_file* __ret = NULL;
!     int __p_mode = 0;
!     int __rw_mode = 0;
!     char __c_mode[4];
!     
!     _M_open_mode(__mode, __p_mode, __rw_mode, __c_mode);
!     if (!this->is_open() && (_M_cfile = fdopen(__fd, __c_mode)))
!       {
! 	// Iff __del is true, then close will fclose the fd.
! 	_M_cfile_created = __del;
! 
! 	if (__fd == 0)
! 	  setvbuf(_M_cfile, reinterpret_cast<char*>(NULL), _IONBF, 0);
! 
  	__ret = this;
        }
      return __ret;
    }
  
    char
!   __basic_file<char>::sys_getc() 
!   { return getc(_M_cfile); }
    
    char
!   __basic_file<char>::sys_ungetc(char __s) 
!   { return ungetc(__s, _M_cfile); }
    
    __basic_file<char>* 
    __basic_file<char>::open(const char* __name, ios_base::openmode __mode, 
*************** namespace std 
*** 110,119 ****
    }
    
    bool 
!   __basic_file<char>::is_open() const { return _M_cfile != 0; }
    
    int 
!   __basic_file<char>::fd() { return fileno(_M_cfile) ; }
    
    __basic_file<char>* 
    __basic_file<char>::close()
--- 135,146 ----
    }
    
    bool 
!   __basic_file<char>::is_open() const 
!   { return _M_cfile != 0; }
    
    int 
!   __basic_file<char>::fd() 
!   { return fileno(_M_cfile) ; }
    
    __basic_file<char>* 
    __basic_file<char>::close()
*************** namespace std 
*** 155,159 ****
    }
    
    int 
!   __basic_file<char>::sync() { return fflush(_M_cfile); }
  }  // namespace std
--- 182,187 ----
    }
    
    int 
!   __basic_file<char>::sync() 
!   { return fflush(_M_cfile); }
  }  // namespace std
Index: config/io/basic_file_stdio.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/config/io/basic_file_stdio.h,v
retrieving revision 1.4
diff -c -p -r1.4 basic_file_stdio.h
*** config/io/basic_file_stdio.h	16 Apr 2002 00:45:14 -0000	1.4
--- config/io/basic_file_stdio.h	27 Apr 2002 04:34:04 -0000
*************** namespace std 
*** 70,76 ****
        open(const char* __name, ios_base::openmode __mode, int __prot = 0664);
  
        __basic_file*
!       sys_open(__c_file* __file, ios_base::openmode __mode);
  
        char
        sys_getc();
--- 70,79 ----
        open(const char* __name, ios_base::openmode __mode, int __prot = 0664);
  
        __basic_file*
!       sys_open(__c_file* __file, ios_base::openmode);
! 
!       __basic_file*
!       sys_open(int __fd, ios_base::openmode __mode, bool __del);
  
        char
        sys_getc();
Index: include/Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/Makefile.am,v
retrieving revision 1.34
diff -c -p -r1.34 Makefile.am
*** include/Makefile.am	2 Apr 2002 12:57:22 -0000	1.34
--- include/Makefile.am	27 Apr 2002 04:34:05 -0000
*************** ext_srcdir = ${glibcpp_srcdir}/include/e
*** 143,148 ****
--- 143,151 ----
  ext_builddir = ./ext
  ext_headers = \
  	${ext_srcdir}/algorithm \
+ 	${ext_srcdir}/enc_filebuf.h \
+ 	${ext_srcdir}/fd_filebuf.h \
+ 	${ext_srcdir}/file_filebuf.h \
  	${ext_srcdir}/functional \
  	${ext_srcdir}/hash_map \
  	${ext_srcdir}/hash_set \
Index: include/bits/fstream.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/fstream.tcc,v
retrieving revision 1.33
diff -c -p -r1.33 fstream.tcc
*** include/bits/fstream.tcc	24 Apr 2002 00:33:27 -0000	1.33
--- include/bits/fstream.tcc	27 Apr 2002 04:34:07 -0000
*************** namespace std
*** 48,66 ****
  	{
  	  _M_buf_size = _M_buf_size_opt;
  
! 	  if (_M_buf_size != 1)
  	    {
! 	      // Allocate internal buffer.
! 	      try { _M_buf = new char_type[_M_buf_size]; }
! 	      catch(...) 
! 		{
! 		  delete [] _M_buf;
! 		  __throw_exception_again;
! 		}
! 	      _M_buf_allocated = true;
  	    }
! 	  else
! 	    _M_buf = _M_unbuf;
  	}
      }
  
--- 48,61 ----
  	{
  	  _M_buf_size = _M_buf_size_opt;
  
! 	  // Allocate internal buffer.
! 	  try { _M_buf = new char_type[_M_buf_size]; }
! 	  catch(...) 
  	    {
! 	      delete [] _M_buf;
! 	      __throw_exception_again;
  	    }
! 	  _M_buf_allocated = true;
  	}
      }
  
*************** namespace std
*** 78,128 ****
  	  this->setg(NULL, NULL, NULL);
  	  this->setp(NULL, NULL);
  	}
-       else
- 	{
- 	  if (_M_buf == _M_unbuf)
- 	    {
- 	      _M_buf = NULL;
- 	      this->setg(NULL, NULL, NULL);
- 	      this->setp(NULL, NULL);
- 	    }
- 	}
      }
  
    template<typename _CharT, typename _Traits>
      basic_filebuf<_CharT, _Traits>::
!     basic_filebuf() 
!     : __streambuf_type(), _M_file(&_M_lock), _M_state_cur(__state_type()), 
!     _M_state_beg(__state_type()), _M_buf_allocated(false), 
!     _M_last_overflowed(false)
      { _M_buf_unified = true; }
- 
-   template<typename _CharT, typename _Traits>
-     basic_filebuf<_CharT, _Traits>::
-     basic_filebuf(__c_file* __f, ios_base::openmode __mode, int_type __s)
-     : __streambuf_type(),  _M_file(&_M_lock), _M_state_cur(__state_type()), 
-     _M_state_beg(__state_type()), _M_buf_allocated(false), 
-     _M_last_overflowed(false)
-     {
-       _M_buf_unified = true; 
-       _M_file.sys_open(__f, __mode);
-       if (this->is_open())
- 	{
- 	  _M_mode = __mode;
- 	  if (__s)
- 	    {
- 	      _M_buf_size_opt = __s;
- 	      _M_allocate_internal_buffer();
- 	      _M_set_indeterminate();
- 	    }
- 	}
-     }
- 
-   template<typename _CharT, typename _Traits>
-     int
-     basic_filebuf<_CharT, _Traits>::
-     fd()
-     { return _M_file.fd(); }
  
    template<typename _CharT, typename _Traits>
      typename basic_filebuf<_CharT, _Traits>::__filebuf_type* 
--- 73,86 ----
  	  this->setg(NULL, NULL, NULL);
  	  this->setp(NULL, NULL);
  	}
      }
  
    template<typename _CharT, typename _Traits>
      basic_filebuf<_CharT, _Traits>::
!     basic_filebuf() : __streambuf_type(), _M_file(&_M_lock), 
!     _M_state_cur(__state_type()), _M_state_beg(__state_type()), 
!     _M_buf_allocated(false), _M_last_overflowed(false)
      { _M_buf_unified = true; }
  
    template<typename _CharT, typename _Traits>
      typename basic_filebuf<_CharT, _Traits>::__filebuf_type* 
Index: include/ext/enc_filebuf.h
===================================================================
RCS file: include/ext/enc_filebuf.h
diff -N include/ext/enc_filebuf.h
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- include/ext/enc_filebuf.h	27 Apr 2002 04:34:10 -0000
***************
*** 0 ****
--- 1,60 ----
+ // __enc_traits layer for filebuf -*- C++ -*-
+ 
+ // 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.
+ 
+ #include <fstream>
+ #include <locale>
+ 
+ namespace __gnu_cxx
+ {
+   // Custom traits type with __enc_traits for state type, all other bits
+   // equivalent to the required char_traits instantiations.
+   template<typename _CharT>
+     struct enc_char_traits: public std::char_traits<_CharT>
+     {
+       typedef std::__enc_traits	state_type;
+     };
+ 
+   template<typename _CharT>
+     class enc_filebuf
+     : public std::basic_filebuf<_CharT, enc_char_traits<_CharT> >
+     {
+     public:
+       typedef typename enc_char_traits<_CharT>::state_type state_type;
+       
+       enc_filebuf(state_type& __state)
+       : std::basic_filebuf<_CharT, enc_char_traits<_CharT> >()
+       { 
+ 	// Set state type to something useful.
+ 	// Something more than copyconstructible is needed here, so
+ 	// require copyconstructible + assignment operator.
+ 	_M_state_cur = __state;
+ 	_M_state_cur._M_init();
+       };
+     };
+ } // namespace __gnu_cxx
Index: include/ext/fd_filebuf.h
===================================================================
RCS file: include/ext/fd_filebuf.h
diff -N include/ext/fd_filebuf.h
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- include/ext/fd_filebuf.h	27 Apr 2002 04:34:10 -0000
***************
*** 0 ****
--- 1,87 ----
+ // File descriptor layer for filebuf -*- C++ -*-
+ 
+ // 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.
+ 
+ #include <fstream>
+ 
+ namespace __gnu_cxx
+ {
+   template<typename _CharT, typename _Traits = std::char_traits<_CharT> >
+     class fd_filebuf : public std::basic_filebuf<_CharT, _Traits>
+     {
+     public:
+       // Types:
+       typedef _CharT                     	        char_type;
+       typedef _Traits                    	        traits_type;
+       typedef typename traits_type::int_type 		int_type;
+       typedef typename traits_type::pos_type 		pos_type;
+       typedef typename traits_type::off_type 		off_type;
+       
+     protected:
+       // Stack-based buffer for unbuffered input.
+       char_type			_M_unbuf[4];
+       
+     public:
+       fd_filebuf(int __fd, std::ios_base::openmode __mode, bool __del, 
+ 		 int_type __size);
+ 
+       virtual
+       ~fd_filebuf();
+ 
+       int
+       fd()
+       { return _M_file.fd(); }
+     };
+ 
+   template<typename _CharT, typename _Traits>
+     fd_filebuf<_CharT, _Traits>::~fd_filebuf()
+     { }
+ 
+   template<typename _CharT, typename _Traits>
+     fd_filebuf<_CharT, _Traits>::
+     fd_filebuf(int __fd, std::ios_base::openmode __mode, bool __del, 
+ 	       int_type __size)
+     {
+       _M_file.sys_open(__fd, __mode, __del);
+       if (this->is_open())
+ 	{
+ 	  _M_mode = __mode;
+ 	  _M_buf_size_opt = __size;
+ 	  
+ 	  if (__size > 0 && __size < 4)
+ 	    {
+ 	      _M_buf = _M_unbuf;
+ 	      _M_buf_size = __size;
+ 	    }
+ 	  else
+ 	    _M_allocate_internal_buffer();
+ 	  
+ 	  _M_set_indeterminate();
+ 	}
+     }
+ } // namespace __gnu_cxx
Index: include/ext/file_filebuf.h
===================================================================
RCS file: include/ext/file_filebuf.h
diff -N include/ext/file_filebuf.h
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- include/ext/file_filebuf.h	27 Apr 2002 04:34:10 -0000
***************
*** 0 ****
--- 1,87 ----
+ // FILE layer for filebuf -*- C++ -*-
+ 
+ // 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.
+ 
+ #include <fstream>
+ 
+ namespace __gnu_cxx
+ {
+   template<typename _CharT, typename _Traits = std::char_traits<_CharT> >
+     class file_filebuf : public std::basic_filebuf<_CharT, _Traits>
+     {
+     public:
+       // Types:
+       typedef _CharT                     	        char_type;
+       typedef _Traits                    	        traits_type;
+       typedef typename traits_type::int_type 		int_type;
+       typedef typename traits_type::pos_type 		pos_type;
+       typedef typename traits_type::off_type 		off_type;
+       
+     protected:
+       // Stack-based buffer for unbuffered input.
+       char_type			_M_unbuf[4];
+       
+     public:
+       file_filebuf(std::__c_file* __f, std::ios_base::openmode __mode, 
+ 		   int_type __size = static_cast<int_type>(BUFSIZ));
+ 
+       virtual
+       ~file_filebuf();
+ 
+       int
+       fd()
+       { return _M_file.fd(); }
+     };
+ 
+   template<typename _CharT, typename _Traits>
+     file_filebuf<_CharT, _Traits>::~file_filebuf()
+     { }
+ 
+   template<typename _CharT, typename _Traits>
+     file_filebuf<_CharT, _Traits>::
+     file_filebuf(std::__c_file* __f, std::ios_base::openmode __mode, 
+ 		 int_type __size)
+     {
+       _M_file.sys_open(__f, __mode);
+       if (this->is_open())
+ 	{
+ 	  _M_mode = __mode;
+ 	  _M_buf_size_opt = __size;
+ 	  
+ 	  if (__size > 0 && __size < 4)
+ 	    {
+ 	      _M_buf = _M_unbuf;
+ 	      _M_buf_size = __size;
+ 	    }
+ 	  else
+ 	    _M_allocate_internal_buffer();
+ 	  
+ 	  _M_set_indeterminate();
+ 	}
+     }
+ } // namespace __gnu_cxx
Index: include/std/std_fstream.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/std/std_fstream.h,v
retrieving revision 1.11
diff -c -p -r1.11 std_fstream.h
*** include/std/std_fstream.h	24 Apr 2002 00:33:25 -0000	1.11
--- include/std/std_fstream.h	27 Apr 2002 04:34:11 -0000
*************** namespace std
*** 87,95 ****
        // Set iff _M_buf is allocated memory from _M_allocate_internal_buffer..
        bool			_M_buf_allocated;
        
-       // Stack-based buffer for unbuffered input.
-       char_type			_M_unbuf[4];
- 
        // XXX Needed?
        bool			_M_last_overflowed;
  
--- 87,92 ----
*************** namespace std
*** 100,113 ****
      public:
        // Constructors/destructor:
        basic_filebuf();
- 
-       // Non-standard ctor:
-       basic_filebuf(__c_file* __f, ios_base::openmode __mode,
- 		    int_type __s = static_cast<int_type>(BUFSIZ));
- 
-       // Non-standard member:
-       int
-       fd();
  
        virtual
        ~basic_filebuf()
--- 97,102 ----
Index: src/globals.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/src/globals.cc,v
retrieving revision 1.7
diff -c -p -r1.7 globals.cc
*** src/globals.cc	16 Apr 2002 00:45:32 -0000	1.7
--- src/globals.cc	27 Apr 2002 04:34:11 -0000
***************
*** 31,36 ****
--- 31,37 ----
  #include <istream>
  #include <ostream>
  #include <locale>
+ #include <ext/file_filebuf.h>
  
  // On AIX, and perhaps other systems, library initialization order is
  // not guaranteed.  For example, the static initializers for the main
*************** namespace std 
*** 176,183 ****
    fake_ostream cerr;
    fake_ostream clog;
  
!   typedef char fake_filebuf[sizeof(filebuf)]
!   __attribute__ ((aligned(__alignof__(filebuf))));
    fake_filebuf buf_cout;
    fake_filebuf buf_cin;
    fake_filebuf buf_cerr;
--- 177,184 ----
    fake_ostream cerr;
    fake_ostream clog;
  
!   typedef char fake_filebuf[sizeof(__gnu_cxx::file_filebuf<char>)]
!   __attribute__ ((aligned(__alignof__(__gnu_cxx::file_filebuf<char>))));
    fake_filebuf buf_cout;
    fake_filebuf buf_cin;
    fake_filebuf buf_cerr;
*************** namespace std 
*** 192,199 ****
    fake_wostream wcerr;
    fake_wostream wclog;
  
!   typedef char fake_wfilebuf[sizeof(wfilebuf)]
!   __attribute__ ((aligned(__alignof__(wfilebuf))));
    fake_wfilebuf buf_wcout;
    fake_wfilebuf buf_wcin;
    fake_wfilebuf buf_wcerr;
--- 193,200 ----
    fake_wostream wcerr;
    fake_wostream wclog;
  
!   typedef char fake_wfilebuf[sizeof(__gnu_cxx::file_filebuf<wchar_t>)]
!   __attribute__ ((aligned(__alignof__(__gnu_cxx::file_filebuf<wchar_t>))));
    fake_wfilebuf buf_wcout;
    fake_wfilebuf buf_wcin;
    fake_wfilebuf buf_wcerr;
Index: src/ios.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/src/ios.cc,v
retrieving revision 1.28
diff -c -p -r1.28 ios.cc
*** src/ios.cc	22 Apr 2002 20:28:05 -0000	1.28
--- src/ios.cc	27 Apr 2002 04:34:14 -0000
***************
*** 36,43 ****
  #include <ostream>
  #include <istream>
  #include <fstream>
- 
  #include <bits/atomicity.h>
  
  namespace std 
  {
--- 36,43 ----
  #include <ostream>
  #include <istream>
  #include <fstream>
  #include <bits/atomicity.h>
+ #include <ext/file_filebuf.h>
  
  namespace std 
  {
*************** namespace std 
*** 46,63 ****
    extern ostream cout;
    extern ostream cerr;
    extern ostream clog;
!   extern filebuf buf_cout;
!   extern filebuf buf_cin;
!   extern filebuf buf_cerr;
  
  #ifdef _GLIBCPP_USE_WCHAR_T
    extern wistream wcin;
    extern wostream wcout;
    extern wostream wcerr;
    extern wostream wclog;
!   extern wfilebuf buf_wcout;
!   extern wfilebuf buf_wcin;
!   extern wfilebuf buf_wcerr;
  #endif
  
    // Definitions for static const data members of __ios_flags.
--- 46,66 ----
    extern ostream cout;
    extern ostream cerr;
    extern ostream clog;
! 
!   using __gnu_cxx::file_filebuf;
!   extern file_filebuf<char> buf_cout;
!   extern file_filebuf<char> buf_cin;
!   extern file_filebuf<char> buf_cerr;
  
  #ifdef _GLIBCPP_USE_WCHAR_T
    extern wistream wcin;
    extern wostream wcout;
    extern wostream wcerr;
    extern wostream wclog;
! 
!   extern file_filebuf<wchar_t> buf_wcout;
!   extern file_filebuf<wchar_t> buf_wcin;
!   extern file_filebuf<wchar_t> buf_wcerr;
  #endif
  
    // Definitions for static const data members of __ios_flags.
*************** namespace std 
*** 147,161 ****
    void
    ios_base::Init::_S_ios_create(bool __sync)
    {
!     int __out_bufsize = __sync ? 0 : static_cast<int>(BUFSIZ);
!     int __in_bufsize = __sync ? 1 : static_cast<int>(BUFSIZ);
  
      // NB: The file globals.cc creates the four standard files
      // with NULL buffers. At this point, we swap out the dummy NULL
      // [io]stream objects and buffers with the real deal.
!     new (&buf_cout) filebuf(stdout, ios_base::out, __out_bufsize);
!     new (&buf_cin) filebuf(stdin, ios_base::in, __in_bufsize);
!     new (&buf_cerr) filebuf(stderr, ios_base::out, __out_bufsize);
      new (&cout) ostream(&buf_cout);
      new (&cin) istream(&buf_cin);
      new (&cerr) ostream(&buf_cerr);
--- 150,164 ----
    void
    ios_base::Init::_S_ios_create(bool __sync)
    {
!     int __out_size = __sync ? 0 : static_cast<int>(BUFSIZ);
!     int __in_size = __sync ? 1 : static_cast<int>(BUFSIZ);
  
      // NB: The file globals.cc creates the four standard files
      // with NULL buffers. At this point, we swap out the dummy NULL
      // [io]stream objects and buffers with the real deal.
!     new (&buf_cout) file_filebuf<char>(stdout, ios_base::out, __out_size);
!     new (&buf_cin) file_filebuf<char>(stdin, ios_base::in, __in_size);
!     new (&buf_cerr) file_filebuf<char>(stderr, ios_base::out, __out_size);
      new (&cout) ostream(&buf_cout);
      new (&cin) istream(&buf_cin);
      new (&cerr) ostream(&buf_cerr);
*************** namespace std 
*** 164,172 ****
      cerr.flags(ios_base::unitbuf);
      
  #ifdef _GLIBCPP_USE_WCHAR_T
!     new (&buf_wcout) wfilebuf(stdout, ios_base::out, __out_bufsize);
!     new (&buf_wcin) wfilebuf(stdin, ios_base::in, __in_bufsize);
!     new (&buf_wcerr) wfilebuf(stderr, ios_base::out, __out_bufsize);
      new (&wcout) wostream(&buf_wcout);
      new (&wcin) wistream(&buf_wcin);
      new (&wcerr) wostream(&buf_wcerr);
--- 167,175 ----
      cerr.flags(ios_base::unitbuf);
      
  #ifdef _GLIBCPP_USE_WCHAR_T
!     new (&buf_wcout) file_filebuf<wchar_t>(stdout, ios_base::out, __out_size);
!     new (&buf_wcin) file_filebuf<wchar_t>(stdin, ios_base::in, __in_size);
!     new (&buf_wcerr) file_filebuf<wchar_t>(stderr, ios_base::out, __out_size);
      new (&wcout) wostream(&buf_wcout);
      new (&wcin) wistream(&buf_wcin);
      new (&wcerr) wostream(&buf_wcerr);
*************** namespace std 
*** 182,194 ****
      // Explicitly call dtors to free any memory that is dynamically
      // allocated by filebuf ctor or member functions, but don't
      // deallocate all memory by calling operator delete.
!     buf_cout.~filebuf();
!     buf_cin.~filebuf();
!     buf_cerr.~filebuf();
  #ifdef _GLIBCPP_USE_WCHAR_T
!     buf_wcout.~wfilebuf();
!     buf_wcin.~wfilebuf();
!     buf_wcerr.~wfilebuf();
  #endif
    }
  
--- 185,198 ----
      // Explicitly call dtors to free any memory that is dynamically
      // allocated by filebuf ctor or member functions, but don't
      // deallocate all memory by calling operator delete.
!     buf_cout.~file_filebuf();
!     buf_cin.~file_filebuf();
!     buf_cerr.~file_filebuf();
! 
  #ifdef _GLIBCPP_USE_WCHAR_T
!     buf_wcout.~file_filebuf();
!     buf_wcin.~file_filebuf();
!     buf_wcerr.~file_filebuf();
  #endif
    }
  
Index: src/misc-inst.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/src/misc-inst.cc,v
retrieving revision 1.15
diff -c -p -r1.15 misc-inst.cc
*** src/misc-inst.cc	16 Feb 2002 00:19:13 -0000	1.15
--- src/misc-inst.cc	27 Apr 2002 04:34:14 -0000
***************
*** 44,49 ****
--- 44,50 ----
  #include <istream>
  #include <ostream>
  #include <iomanip>
+ #include <ext/file_filebuf.h>
  
  // NB: Unnecessary if the .h headers already include these.
  #ifndef  _GLIBCPP_FULLY_COMPLIANT_HEADERS
*************** namespace std
*** 263,267 ****
--- 264,274 ----
      streamsize
      __copy_streambufs(basic_ios<wchar_t>&, basic_streambuf<wchar_t>*,
  		      basic_streambuf<wchar_t>*); 
+ #endif
+   
+   using __gnu_cxx::file_filebuf;
+   template class file_filebuf<char>;
+ #ifdef _GLIBCPP_USE_WCHAR_T
+   template class file_filebuf<wchar_t>;
  #endif
  } //std
Index: testsuite/27_io/filebuf_members.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/27_io/filebuf_members.cc,v
retrieving revision 1.15
diff -c -p -r1.15 filebuf_members.cc
*** testsuite/27_io/filebuf_members.cc	16 Apr 2002 00:45:36 -0000	1.15
--- testsuite/27_io/filebuf_members.cc	27 Apr 2002 04:34:14 -0000
***************
*** 30,35 ****
--- 30,36 ----
  #include <fcntl.h>
  #include <sys/types.h>
  #include <sys/stat.h>
+ #include <ext/file_filebuf.h>
  #include <testsuite_hooks.h>
  
  const char name_01[] = "filebuf_members-1.tst";
*************** void test_02()
*** 89,95 ****
    FILE* f2 = fopen(name_01, "r");
    VERIFY( f2 != NULL );
    {
!     std::filebuf fb(f2, std::ios_base::in, 512);
    }
    close_num = fclose(f2);
    VERIFY( close_num == 0 );
--- 90,96 ----
    FILE* f2 = fopen(name_01, "r");
    VERIFY( f2 != NULL );
    {
!     __gnu_cxx::file_filebuf<char> fb(f2, std::ios_base::in, 512);
    }
    close_num = fclose(f2);
    VERIFY( close_num == 0 );
*************** void test_03()
*** 115,121 ****
    VERIFY( first_fd != -1 );
    FILE* first_file = ::fdopen(first_fd, "r");
    VERIFY( first_file != NULL );
!   std::filebuf fb (first_file, std::ios_base::in);
  
    int second_fd = fb.fd();
  
--- 116,122 ----
    VERIFY( first_fd != -1 );
    FILE* first_file = ::fdopen(first_fd, "r");
    VERIFY( first_file != NULL );
!   __gnu_cxx::file_filebuf<char> fb(first_file, std::ios_base::in);
  
    int second_fd = fb.fd();
  


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