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]

[Patch] Fix libstdc++/9320


Hi!

After a little reflection, this one too seems pretty obvious:
the size parameter passed to the __gnu_cxx::stdio_filebuf
constructors has nothing to do with the template parameter
dependent type int_type: it's just the size of the buffer.

This is also clear looking at the call points in ios.cc.

Tested x86-linux. Ok?

Paolo.

///////////
2003-02-08  Paolo Carlini  <pcarlini@unitus.it>

	PR libstdc++/9320
	* include/ext/stdio_filebuf.h
	(stdio_filebuf(int, std::ios_base::openmode, bool, int_type),
	stdio_filebuf(std::__c_file*, std::ios_base::openmode, int_type)):
	Change to take a __size parameter of type streamsize, not
	of type (template parameter dependent) int_type. 
	* src/ios.cc (ios_base::Init::_S_ios_create): Change type of
	size vars to streamsize.
	* testsuite/ext/stdio_filebuf.cc: Add from the PR.
diff -urN libstdc++-v3-orig/include/ext/stdio_filebuf.h libstdc++-v3/include/ext/stdio_filebuf.h
--- libstdc++-v3-orig/include/ext/stdio_filebuf.h	2003-01-16 21:30:26.000000000 +0100
+++ libstdc++-v3/include/ext/stdio_filebuf.h	2003-02-08 19:24:14.000000000 +0100
@@ -58,6 +58,7 @@
       typedef typename traits_type::int_type 		int_type;
       typedef typename traits_type::pos_type 		pos_type;
       typedef typename traits_type::off_type 		off_type;
+      typedef std::streamsize                           streamsize;
       
     protected:
       // Stack-based buffer for unbuffered input.
@@ -75,7 +76,7 @@
        *  file will be closed when the stdio_filebuf is closed/destroyed.
       */
       stdio_filebuf(int __fd, std::ios_base::openmode __mode, bool __del, 
-		    int_type __size);
+		    streamsize __size);
 
       /**
        *  @param  f  An open @c FILE*.
@@ -88,7 +89,7 @@
        *  stdio_filebuf is closed/destroyed.
       */
       stdio_filebuf(std::__c_file* __f, std::ios_base::openmode __mode, 
-		    int_type __size = static_cast<int_type>(BUFSIZ));
+		    streamsize __size = static_cast<streamsize>(BUFSIZ));
 
       /**
        *  Possibly closes the external data stream, in the case of the file
@@ -117,7 +118,7 @@
   template<typename _CharT, typename _Traits>
     stdio_filebuf<_CharT, _Traits>::
     stdio_filebuf(int __fd, std::ios_base::openmode __mode, bool __del, 
-		  int_type __size)
+		  streamsize __size)
     {
       this->_M_file.sys_open(__fd, __mode, __del);
       if (this->is_open())
@@ -142,7 +143,7 @@
   template<typename _CharT, typename _Traits>
     stdio_filebuf<_CharT, _Traits>::
     stdio_filebuf(std::__c_file* __f, std::ios_base::openmode __mode, 
-		  int_type __size)
+		  streamsize __size)
     {
       this->_M_file.sys_open(__f, __mode);
       if (this->is_open())
diff -urN libstdc++-v3-orig/src/ios.cc libstdc++-v3/src/ios.cc
--- libstdc++-v3-orig/src/ios.cc	2002-11-15 20:12:31.000000000 +0100
+++ libstdc++-v3/src/ios.cc	2003-02-08 20:36:02.000000000 +0100
@@ -159,11 +159,12 @@
   void
   ios_base::Init::_S_ios_create(bool __sync)
   {
-    int __out_size = __sync ? 0 : static_cast<int>(BUFSIZ);
+    streamsize __out_size = __sync ? 0 : static_cast<streamsize>(BUFSIZ);
 #ifdef _GLIBCPP_HAVE_ISATTY
-    int __in_size = (__sync || isatty (0)) ? 1 : static_cast<int>(BUFSIZ);
+    streamsize __in_size =
+      (__sync || isatty (0)) ? 1 : static_cast<streamsize>(BUFSIZ);
 #else
-    int __in_size = 1;
+    streamsize __in_size = 1;
 #endif
 
     // NB: The file globals.cc creates the four standard files
diff -urN libstdc++-v3-orig/testsuite/ext/stdio_filebuf.cc libstdc++-v3/testsuite/ext/stdio_filebuf.cc
--- libstdc++-v3-orig/testsuite/ext/stdio_filebuf.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/ext/stdio_filebuf.cc	2003-02-08 19:48:43.000000000 +0100
@@ -0,0 +1,83 @@
+// 2003-02-08  Paolo Carlini  <pcarlini@unitus.it>
+
+// Copyright (C) 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
+// 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.
+
+// stdio_filebuf.h
+
+#include <ext/stdio_filebuf.h>
+
+// { dg-do compile }
+
+// libstdc++/9320
+struct MyChar {};
+struct MyInt {};
+struct MyState {};
+
+struct MyTraits
+{
+  typedef MyChar char_type;
+  typedef MyInt int_type;
+  typedef std::streampos pos_type;
+  typedef std::streamoff off_type;
+  typedef MyState state_type;
+  
+  static void
+  assign(char_type&, const char_type&);
+
+  static bool
+  eq(const char_type&, const char_type&);
+
+  static bool
+  lt(const char_type&, const char_type&);
+
+  static int
+  compare(const char_type*, const char_type*, size_t);
+
+  static size_t
+  length(const char_type*);
+
+  static const char_type*
+  find(const char_type*, size_t, const char_type&);
+
+  static char_type*
+  move(char_type*, const char_type*, size_t);
+
+  static char_type*
+  copy(char_type*, const char_type*, size_t);
+  
+  static char_type*
+  assign(char_type*, size_t, char_type);
+
+  static char_type
+  to_char_type(const int_type&);
+  
+  static int_type
+  to_int_type(const char_type&);
+
+  static bool
+  eq_int_type(const int_type&, const int_type&);
+  
+  static int_type
+  eof();
+
+  static int_type
+  not_eof(const int_type&);
+};
+  
+template class __gnu_cxx::stdio_filebuf<MyChar, MyTraits>;

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