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]

[v3] libstdc++/3126/2346



tested, trunk and branch....

2001-06-11  Benjamin Kosnik  <bkoz@redhat.com>

	libstdc++/3126
	* include/bits/basic_string.h (string::compare): Adjust signatures
	as per DR 5.
	* include/bits/basic_string.tcc: And here.

	libstdc++/2346
	* config/c_io_stdio.h: Remove whitespace.
	* include/bits/fstream.tcc (filebuf::open): Prevent resource leak
	if opening doesn't work.
	* testsuite/27_io/istream_seeks.cc (test03): Add regression.
	(test02): Add regression.
	* testsuite/27_io/istream_seeks-3.tst: New file.
	
Index: config/c_io_stdio.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/config/c_io_stdio.h,v
retrieving revision 1.10
diff -c -p -r1.10 c_io_stdio.h
*** c_io_stdio.h	2001/06/09 06:49:13	1.10
--- c_io_stdio.h	2001/06/12 01:57:52
*************** namespace std 
*** 92,104 ****
  }
  
  #endif // _CPP_IO_STDIO_H
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
--- 92,94 ----
Index: include/bits/basic_string.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/basic_string.h,v
retrieving revision 1.7
diff -c -p -r1.7 basic_string.h
*** basic_string.h	2001/03/04 21:34:00	1.7
--- basic_string.h	2001/06/12 01:57:55
*************** namespace std
*** 842,850 ****
        int 
        compare(const _CharT* __s) const;
  
        int 
        compare(size_type __pos, size_type __n1, const _CharT* __s, 
! 	      size_type __n2 = npos) const;
    };
  
  
--- 842,856 ----
        int 
        compare(const _CharT* __s) const;
  
+ #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
+ // 5. String::compare specification questionable
        int 
+       compare(size_type __pos, size_type __n1, const _CharT* __s) const;
+ 
+       int 
        compare(size_type __pos, size_type __n1, const _CharT* __s, 
! 	      size_type __n2) const;
! #endif
    };
  
  
Index: include/bits/basic_string.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/basic_string.tcc,v
retrieving revision 1.4
diff -c -p -r1.4 basic_string.tcc
*** basic_string.tcc	2001/03/15 08:46:23	1.4
--- basic_string.tcc	2001/06/12 01:57:58
*************** namespace std
*** 812,817 ****
--- 812,835 ----
    template<typename _CharT, typename _Traits, typename _Alloc>
      int
      basic_string <_CharT,_Traits,_Alloc>::
+     compare(size_type __pos, size_type __n1, const _CharT* __s) const
+     {
+       size_type __size = this->size();
+       if (__pos > __size)
+ 	__throw_out_of_range("basic_string::compare");
+       
+       size_type __osize = traits_type::length(__s);
+       size_type __rsize = min(__size - __pos, __n1);
+       size_type __len = min(__rsize, __osize);
+       int __r = traits_type::compare(_M_data() + __pos, __s, __len);
+       if (!__r)
+ 	__r = __rsize - __osize;
+       return __r;
+     }
+ 
+   template<typename _CharT, typename _Traits, typename _Alloc>
+     int
+     basic_string <_CharT,_Traits,_Alloc>::
      compare(size_type __pos, size_type __n1, const _CharT* __s, 
  	    size_type __n2) const
      {
*************** namespace std
*** 839,845 ****
        _Traits::copy(__buf, __str.data(), __bytes);
        __buf[__bytes] = _CharT();
      }
! 
! } // std::
  
! #endif /* _CPP_BITS_STRING_TCC */
--- 857,862 ----
        _Traits::copy(__buf, __str.data(), __bytes);
        __buf[__bytes] = _CharT();
      }
! } // namespace std
  
! #endif
Index: include/bits/fstream.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/fstream.tcc,v
retrieving revision 1.14
diff -c -p -r1.14 fstream.tcc
*** fstream.tcc	2001/05/22 18:48:19	1.14
--- fstream.tcc	2001/06/12 01:57:59
*************** namespace std
*** 161,166 ****
--- 161,168 ----
  		this->close();
  	      __ret = this;
  	    }
+ 	  else
+ 	    delete _M_file;
  	}
        return __ret;
      }
Index: testsuite/27_io/istream_seeks-3.tst
===================================================================
RCS file: istream_seeks-3.tst
diff -N istream_seeks-3.tst
*** /dev/null	Tue May  5 13:32:27 1998
--- istream_seeks-3.tst	Mon Jun 11 18:58:01 2001
***************
*** 0 ****
--- 1,10 ----
+ 0-0 lootpack, peanut butter wolf, rob swift, madlib, quasimoto
+ 0-1 lootpack, peanut butter wolf, rob swift, madlib, quasimoto
+ 0-2 lootpack, peanut butter wolf, rob swift, madlib, quasimoto
+ 0-3 lootpack, peanut butter wolf, rob swift, madlib, quasimoto
+ 0-4 lootpack, peanut butter wolf, rob swift, madlib, quasimoto
+ 0-5 lootpack, peanut butter wolf, rob swift, madlib, quasimoto
+ 0-6 lootpack, peanut butter wolf, rob swift, madlib, quasimoto
+ 0-7 lootpack, peanut butter wolf, rob swift, madlib, quasimoto
+ 0-8 lootpack, peanut butter wolf, rob swift, madlib, quasimoto
+ 0-9 lootpack, peanut butter wolf, rob swift, madlib, quasimoto
Index: testsuite/27_io/istream_seeks.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/27_io/istream_seeks.cc,v
retrieving revision 1.8
diff -c -p -r1.8 istream_seeks.cc
*** istream_seeks.cc	2001/06/11 19:20:20	1.8
--- istream_seeks.cc	2001/06/12 01:58:01
***************
*** 1,6 ****
  // 2000-06-29 bkoz
  
! // Copyright (C) 2000 Free Software Foundation
  //
  // 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,6 ----
  // 2000-06-29 bkoz
  
! // Copyright (C) 2000, 2001 Free Software Foundation
  //
  // 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
***************
*** 28,34 ****
  #include <fstream>
  #include <debug_assert.h>
  
- 
  bool test01()
  {
    using namespace std;
--- 28,33 ----
*************** bool test01()
*** 64,69 ****
--- 63,133 ----
    return test;
  }
  
+ const char* s = " lootpack, peanut butter wolf, rob swift, madlib, quasimoto";
+ const int times = 10;
+ 
+ void write_rewind(std::iostream& stream)
+ {
+   for (int j = 0; j < times; j++) 
+     {
+       bool test = true;
+       std::streampos begin = stream.tellg();
+       
+       for (int i = 0; i < times; ++i)
+ 	stream << j << '-' << i << s << '\n';
+       
+       stream.seekg(begin);
+       std::streampos end = stream.tellg(); 
+       std::streampos badpos = std::streampos(std::streambuf::off_type(-1));
+     }
+ }
+ 
+ void check_contents(std::iostream& stream)
+ {
+   bool test = true;
+ 
+   stream.clear();
+   stream.seekg(0, std::ios::beg);
+   int i = 0;
+   int loop = times * times + 2;
+   while (i < loop)
+     {
+       stream.ignore(80, '\n');
+       if (stream.good())
+ 	++i;
+       else
+ 	break;
+     }
+   VERIFY( i == times );
+ }
+ 
+ // fstream
+ // libstdc++/2346
+ void test02()
+ {	 
+   std::fstream ofstrm;
+   ofstrm.open("istream_seeks-3.txt", std::ios::out);
+   if (!ofstrm)
+     abort();
+   write_rewind(ofstrm);
+   ofstrm.close();
+ 
+   std::fstream ifstrm;
+   ifstrm.open("istream_seeks-3.txt", std::ios::in);
+   check_contents(ifstrm);
+   ifstrm.close();
+ }
+ 
+ // stringstream
+ // libstdc++/2346
+ void test03()
+ {	 
+   std::stringstream sstrm;
+ 
+   write_rewind(sstrm);
+   check_contents(sstrm);
+ }
+ 
  // fstreams
  void test04(void)
  {
*************** void test05(void)
*** 289,295 ****
--- 353,365 ----
  int main()
  {
    test01();
+ 
+   test02();
+   test03();
+ 
    test04();
    test05();
    return 0;
  }
+ 
+ 



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