mkcheck.in (static_fail): Remove S_FLAG decoration on output.
2001-05-21 Benjamin Kosnik <bkoz@redhat.com> * mkcheck.in (static_fail): Remove S_FLAG decoration on output. * include/bits/std_sstream.h (stringbuf::setbuf): Require both arguments to be non-null. * include/bits/fstream.tcc (filebuf::_M_allocate_buffers): Only try allocations if allocated size is greater than zero. (filebuf::_M_filebuf_init): Change to (filebuf::_M_allocate_file): Which is what it does now. (filebuf::_M_allocate_bufers): Change to (filebuf::_M_allocate_internal_buffer): This, and create (filebuf::_M_allocate_pback_buffer): New. (filebuf::_M_destroy_internal_buffer): New. (filebuf::_M_buf_allocated): New data member. (filebuf::setbuf): Use new logic, allow use of external buffer. * testsuite/27_io/stringbuf_virtuals.cc: New file. * testsuite/27_io/filebuf_virtuals.cc: New file. From-SVN: r42458
This commit is contained in:
parent
14fc34261e
commit
990101f973
@ -1,3 +1,22 @@
|
|||||||
|
2001-05-21 Benjamin Kosnik <bkoz@redhat.com>
|
||||||
|
|
||||||
|
* mkcheck.in (static_fail): Remove S_FLAG decoration on output.
|
||||||
|
|
||||||
|
* include/bits/std_sstream.h (stringbuf::setbuf): Require both
|
||||||
|
arguments to be non-null.
|
||||||
|
* include/bits/fstream.tcc (filebuf::_M_allocate_buffers): Only
|
||||||
|
try allocations if allocated size is greater than zero.
|
||||||
|
(filebuf::_M_filebuf_init): Change to
|
||||||
|
(filebuf::_M_allocate_file): Which is what it does now.
|
||||||
|
(filebuf::_M_allocate_bufers): Change to
|
||||||
|
(filebuf::_M_allocate_internal_buffer): This, and create
|
||||||
|
(filebuf::_M_allocate_pback_buffer): New.
|
||||||
|
(filebuf::_M_destroy_internal_buffer): New.
|
||||||
|
(filebuf::_M_buf_allocated): New data member.
|
||||||
|
(filebuf::setbuf): Use new logic, allow use of external buffer.
|
||||||
|
* testsuite/27_io/stringbuf_virtuals.cc: New file.
|
||||||
|
* testsuite/27_io/filebuf_virtuals.cc: New file.
|
||||||
|
|
||||||
2001-05-21 Stephen M. Webb <stephen@bregmasoft.com>
|
2001-05-21 Stephen M. Webb <stephen@bregmasoft.com>
|
||||||
|
|
||||||
* include/c_std/bits/std_cstring.h (memchr): Define "C" functions to
|
* include/c_std/bits/std_cstring.h (memchr): Define "C" functions to
|
||||||
|
@ -39,7 +39,7 @@ namespace std
|
|||||||
template<typename _CharT, typename _Traits>
|
template<typename _CharT, typename _Traits>
|
||||||
void
|
void
|
||||||
basic_filebuf<_CharT, _Traits>::
|
basic_filebuf<_CharT, _Traits>::
|
||||||
_M_filebuf_init()
|
_M_allocate_file()
|
||||||
{
|
{
|
||||||
if (!_M_file)
|
if (!_M_file)
|
||||||
{
|
{
|
||||||
@ -57,11 +57,12 @@ namespace std
|
|||||||
template<typename _CharT, typename _Traits>
|
template<typename _CharT, typename _Traits>
|
||||||
void
|
void
|
||||||
basic_filebuf<_CharT, _Traits>::
|
basic_filebuf<_CharT, _Traits>::
|
||||||
_M_allocate_buffers()
|
_M_allocate_internal_buffer()
|
||||||
{
|
{
|
||||||
if (!_M_buf)
|
if (!_M_buf && _M_buf_size_opt)
|
||||||
{
|
{
|
||||||
_M_buf_size = _M_buf_size_opt;
|
_M_buf_size = _M_buf_size_opt;
|
||||||
|
|
||||||
// Allocate internal buffer.
|
// Allocate internal buffer.
|
||||||
try { _M_buf = new char_type[_M_buf_size]; }
|
try { _M_buf = new char_type[_M_buf_size]; }
|
||||||
catch(...)
|
catch(...)
|
||||||
@ -69,7 +70,33 @@ namespace std
|
|||||||
delete [] _M_buf;
|
delete [] _M_buf;
|
||||||
__throw_exception_again;
|
__throw_exception_again;
|
||||||
}
|
}
|
||||||
|
_M_buf_allocated = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Both close and setbuf need to deallocate internal buffers, if it exists.
|
||||||
|
template<typename _CharT, typename _Traits>
|
||||||
|
void
|
||||||
|
basic_filebuf<_CharT, _Traits>::
|
||||||
|
_M_destroy_internal_buffer()
|
||||||
|
{
|
||||||
|
if (_M_buf_allocated)
|
||||||
|
{
|
||||||
|
delete [] _M_buf;
|
||||||
|
_M_buf = NULL;
|
||||||
|
_M_buf_allocated = false;
|
||||||
|
this->setg(NULL, NULL, NULL);
|
||||||
|
this->setp(NULL, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename _CharT, typename _Traits>
|
||||||
|
void
|
||||||
|
basic_filebuf<_CharT, _Traits>::
|
||||||
|
_M_allocate_pback_buffer()
|
||||||
|
{
|
||||||
|
if (!_M_pback && _M_pback_size)
|
||||||
|
{
|
||||||
// Allocate pback buffer.
|
// Allocate pback buffer.
|
||||||
try
|
try
|
||||||
{ _M_pback = new char_type[_M_pback_size]; }
|
{ _M_pback = new char_type[_M_pback_size]; }
|
||||||
@ -85,16 +112,18 @@ namespace std
|
|||||||
basic_filebuf<_CharT, _Traits>::
|
basic_filebuf<_CharT, _Traits>::
|
||||||
basic_filebuf()
|
basic_filebuf()
|
||||||
: __streambuf_type(), _M_file(NULL), _M_state_cur(__state_type()),
|
: __streambuf_type(), _M_file(NULL), _M_state_cur(__state_type()),
|
||||||
_M_state_beg(__state_type()), _M_last_overflowed(false)
|
_M_state_beg(__state_type()), _M_buf_allocated(false),
|
||||||
|
_M_last_overflowed(false)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
template<typename _CharT, typename _Traits>
|
template<typename _CharT, typename _Traits>
|
||||||
basic_filebuf<_CharT, _Traits>::
|
basic_filebuf<_CharT, _Traits>::
|
||||||
basic_filebuf(__c_file_type* __f, ios_base::openmode __mode, int_type __s)
|
basic_filebuf(__c_file_type* __f, ios_base::openmode __mode, int_type __s)
|
||||||
: __streambuf_type(), _M_file(NULL), _M_state_cur(__state_type()),
|
: __streambuf_type(), _M_file(NULL), _M_state_cur(__state_type()),
|
||||||
_M_state_beg(__state_type()), _M_last_overflowed(false)
|
_M_state_beg(__state_type()), _M_buf_allocated(false),
|
||||||
|
_M_last_overflowed(false)
|
||||||
{
|
{
|
||||||
_M_filebuf_init();
|
_M_allocate_file();
|
||||||
_M_file->sys_open(__f, __mode);
|
_M_file->sys_open(__f, __mode);
|
||||||
if (this->is_open())
|
if (this->is_open())
|
||||||
{
|
{
|
||||||
@ -102,9 +131,10 @@ namespace std
|
|||||||
if (__s)
|
if (__s)
|
||||||
{
|
{
|
||||||
_M_buf_size_opt = __s;
|
_M_buf_size_opt = __s;
|
||||||
_M_allocate_buffers();
|
_M_allocate_internal_buffer();
|
||||||
_M_set_indeterminate();
|
_M_set_indeterminate();
|
||||||
}
|
}
|
||||||
|
_M_allocate_pback_buffer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,11 +146,12 @@ namespace std
|
|||||||
__filebuf_type *__ret = NULL;
|
__filebuf_type *__ret = NULL;
|
||||||
if (!this->is_open())
|
if (!this->is_open())
|
||||||
{
|
{
|
||||||
_M_filebuf_init();
|
_M_allocate_file();
|
||||||
_M_file->open(__s, __mode);
|
_M_file->open(__s, __mode);
|
||||||
if (this->is_open())
|
if (this->is_open())
|
||||||
{
|
{
|
||||||
_M_allocate_buffers();
|
_M_allocate_internal_buffer();
|
||||||
|
_M_allocate_pback_buffer();
|
||||||
_M_mode = __mode;
|
_M_mode = __mode;
|
||||||
|
|
||||||
// For time being, set both (in/out) sets of pointers.
|
// For time being, set both (in/out) sets of pointers.
|
||||||
@ -159,14 +190,12 @@ namespace std
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
_M_mode = ios_base::openmode(0);
|
_M_mode = ios_base::openmode(0);
|
||||||
if (_M_buf)
|
_M_destroy_internal_buffer();
|
||||||
|
|
||||||
|
if (_M_pback)
|
||||||
{
|
{
|
||||||
delete [] _M_buf;
|
|
||||||
_M_buf = NULL;
|
|
||||||
delete [] _M_pback;
|
delete [] _M_pback;
|
||||||
_M_pback = NULL;
|
_M_pback = NULL;
|
||||||
this->setg(NULL, NULL, NULL);
|
|
||||||
this->setp(NULL, NULL);
|
|
||||||
}
|
}
|
||||||
__ret = this;
|
__ret = this;
|
||||||
}
|
}
|
||||||
@ -432,6 +461,34 @@ namespace std
|
|||||||
return __ret;
|
return __ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename _CharT, typename _Traits>
|
||||||
|
basic_filebuf<_CharT, _Traits>::__streambuf_type*
|
||||||
|
basic_filebuf<_CharT, _Traits>::
|
||||||
|
setbuf(char_type* __s, streamsize __n)
|
||||||
|
{
|
||||||
|
if (!this->is_open() && __s == 0 && __n == 0)
|
||||||
|
_M_buf_size_opt = 0;
|
||||||
|
else if (__s && __n)
|
||||||
|
{
|
||||||
|
// This is implementation-defined behavior, and assumes
|
||||||
|
// that an external char_type array of length (__s + __n)
|
||||||
|
// exists and has been pre-allocated. If this is not the
|
||||||
|
// case, things will quickly blow up.
|
||||||
|
// Step 1: Destroy the current internal array.
|
||||||
|
_M_destroy_internal_buffer();
|
||||||
|
|
||||||
|
// Step 2: Use the external array.
|
||||||
|
_M_buf = __s;
|
||||||
|
_M_buf_size_opt = _M_buf_size = __n;
|
||||||
|
_M_set_indeterminate();
|
||||||
|
|
||||||
|
// Step 3: Make sure a pback buffer is allocated.
|
||||||
|
_M_allocate_pback_buffer();
|
||||||
|
}
|
||||||
|
_M_last_overflowed = false;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename _CharT, typename _Traits>
|
template<typename _CharT, typename _Traits>
|
||||||
basic_filebuf<_CharT, _Traits>::pos_type
|
basic_filebuf<_CharT, _Traits>::pos_type
|
||||||
basic_filebuf<_CharT, _Traits>::
|
basic_filebuf<_CharT, _Traits>::
|
||||||
|
@ -78,6 +78,9 @@ namespace std
|
|||||||
// MT lock inherited from libio or other low-level io library.
|
// MT lock inherited from libio or other low-level io library.
|
||||||
__c_lock _M_lock;
|
__c_lock _M_lock;
|
||||||
|
|
||||||
|
// Set iff _M_buf is allocated memory from _M_allocate_internal_buffer..
|
||||||
|
bool _M_buf_allocated;
|
||||||
|
|
||||||
// XXX Needed?
|
// XXX Needed?
|
||||||
bool _M_last_overflowed;
|
bool _M_last_overflowed;
|
||||||
|
|
||||||
@ -107,13 +110,18 @@ namespace std
|
|||||||
close(void);
|
close(void);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Allocate up pback and internal buffers.
|
|
||||||
void
|
void
|
||||||
_M_allocate_buffers();
|
_M_allocate_internal_buffer();
|
||||||
|
|
||||||
|
void
|
||||||
|
_M_destroy_internal_buffer();
|
||||||
|
|
||||||
|
void
|
||||||
|
_M_allocate_pback_buffer();
|
||||||
|
|
||||||
// Create __file_type object and initialize it properly.
|
// Create __file_type object and initialize it properly.
|
||||||
void
|
void
|
||||||
_M_filebuf_init();
|
_M_allocate_file();
|
||||||
|
|
||||||
// Overridden virtual functions:
|
// Overridden virtual functions:
|
||||||
virtual streamsize
|
virtual streamsize
|
||||||
@ -151,16 +159,7 @@ namespace std
|
|||||||
_M_really_overflow(int_type __c = _Traits::eof());
|
_M_really_overflow(int_type __c = _Traits::eof());
|
||||||
|
|
||||||
virtual __streambuf_type*
|
virtual __streambuf_type*
|
||||||
setbuf(char_type* __s, streamsize __n)
|
setbuf(char_type* __s, streamsize __n);
|
||||||
{
|
|
||||||
if (!this->is_open() && __s == 0 && __n == 0)
|
|
||||||
{
|
|
||||||
_M_buf_size = 0;
|
|
||||||
_M_buf_size_opt = 0;
|
|
||||||
}
|
|
||||||
_M_last_overflowed = false;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual pos_type
|
virtual pos_type
|
||||||
seekoff(off_type __off, ios_base::seekdir __way,
|
seekoff(off_type __off, ios_base::seekdir __way,
|
||||||
|
@ -143,7 +143,7 @@ namespace std
|
|||||||
virtual __streambuf_type*
|
virtual __streambuf_type*
|
||||||
setbuf(char_type* __s, streamsize __n)
|
setbuf(char_type* __s, streamsize __n)
|
||||||
{
|
{
|
||||||
if (__n)
|
if (__s && __n)
|
||||||
{
|
{
|
||||||
_M_string = __string_type(__s, __n);
|
_M_string = __string_type(__s, __n);
|
||||||
_M_really_sync(0, 0);
|
_M_really_sync(0, 0);
|
||||||
|
@ -393,8 +393,7 @@ test_file()
|
|||||||
|
|
||||||
printf "%s\t" "$RESULT"
|
printf "%s\t" "$RESULT"
|
||||||
printf "%-2s %d\t%.3f\t%s\t%s\t%s\t%s %s\n" \
|
printf "%-2s %d\t%.3f\t%s\t%s\t%s\t%s %s\n" \
|
||||||
"$RESULT" $C_TIME $E_TIME $TEXT $DATA $SIZE $NAME "$S_FLAG" \
|
"$RESULT" $C_TIME $E_TIME $TEXT $DATA $SIZE $NAME >> $RESULTS_FILE
|
||||||
>> $RESULTS_FILE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setup_size_command
|
setup_size_command
|
||||||
|
62
libstdc++-v3/testsuite/27_io/filebuf_virtuals.cc
Normal file
62
libstdc++-v3/testsuite/27_io/filebuf_virtuals.cc
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com>
|
||||||
|
|
||||||
|
// Copyright (C) 2001 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.
|
||||||
|
|
||||||
|
// 27.8.1.4 Overridden virtual functions
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
#include <debug_assert.h>
|
||||||
|
|
||||||
|
void test01()
|
||||||
|
{
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
bool test = true;
|
||||||
|
char buf[512];
|
||||||
|
const char* strlit = "how to tell a story and other essays: mark twain";
|
||||||
|
const size_t strlitsize = strlen(strlit);
|
||||||
|
filebuf fbuf01;
|
||||||
|
|
||||||
|
fbuf01.pubsetbuf(buf, 512);
|
||||||
|
fbuf01.sputn(strlit, strlitsize);
|
||||||
|
VERIFY( strncmp(strlit, buf, strlitsize) != 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
void test02()
|
||||||
|
{
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
bool test = true;
|
||||||
|
char buf[512];
|
||||||
|
const char* strlit = "how to tell a story and other essays: mark twain";
|
||||||
|
const size_t strlitsize = strlen(strlit);
|
||||||
|
filebuf fbuf01;
|
||||||
|
fbuf01.open("tmp", ios_base::out);
|
||||||
|
|
||||||
|
fbuf01.pubsetbuf(buf, strlitsize);
|
||||||
|
fbuf01.sputn(strlit, strlitsize);
|
||||||
|
VERIFY( strncmp(strlit, buf, strlitsize) == 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
main()
|
||||||
|
{
|
||||||
|
test01();
|
||||||
|
test02();
|
||||||
|
return 0;
|
||||||
|
}
|
46
libstdc++-v3/testsuite/27_io/stringbuf_virtuals.cc
Normal file
46
libstdc++-v3/testsuite/27_io/stringbuf_virtuals.cc
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com>
|
||||||
|
|
||||||
|
// Copyright (C) 2001 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.
|
||||||
|
|
||||||
|
// 27.7.1.3 Overridden virtual functions
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
#include <debug_assert.h>
|
||||||
|
|
||||||
|
void test01()
|
||||||
|
{
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
bool test = true;
|
||||||
|
char buf[512];
|
||||||
|
const char* strlit = "how to tell a story and other essays: mark twain";
|
||||||
|
const size_t strlitsize = strlen(strlit);
|
||||||
|
stringbuf sbuf(ios_base::out);
|
||||||
|
|
||||||
|
sbuf.pubsetbuf(buf, strlitsize);
|
||||||
|
sbuf.sputn(strlit, strlitsize);
|
||||||
|
VERIFY( strncmp(strlit, buf, strlitsize) != 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test01();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user