libstdc++/9875: filebuf doesn't handle codecvt::encoding() > 1
Pétur Runólfsson
peturr02@ru.is
Mon Mar 3 18:46:00 GMT 2003
The following reply was made to PR libstdc++/9875; it has been noted by GNATS.
From: =?iso-8859-1?Q?P=E9tur_Run=F3lfsson?= <peturr02@ru.is>
To: "Paolo Carlini" <pcarlini@unitus.it>
Cc: <paolo@gcc.gnu.org>,
<gcc-bugs@gcc.gnu.org>,
<gcc-gnats@gcc.gnu.org>
Subject: RE: libstdc++/9875: filebuf doesn't handle codecvt::encoding() > 1
Date: Mon, 3 Mar 2003 18:38:27 -0000
> >> The underflow bits are still missing, however. Are you
> >> willing to provide some tests for it too?
> >> =20
> >>
> >Will do.
> >
> Thanks P=E9tur.
> By the way, I would appreciate also some actual ;) tests for=20
> overflow,=20
> since those
> present in the PR didn't really lead to overflow for the default 8192=20
> chars wide buffer.
> (temporarily I have added some using setbuf to shorten the buffer)
These are a bit hairy, but that is by design. The seekoff in
_M_really_overflow is only called when _M_filepos !=3D _M_out_beg
which only happens when switching modes, and the seekoff in
_M_underflow_common only happens when _M_in_cur !=3D _M_filepos,
which never happens when underflow is called from any public
members of streambuf or filebuf.
Petur
void test4()
{
using namespace std;
// overflow
locale loc (locale::classic(), new Cvt);
wfilebuf fb1;
fb1.pubimbue(loc);
fb1.open("tmp", ios_base::out | ios_base::trunc);
fb1.sputn(L"0123456789", 10);
fb1.close();
wfilebuf fb2;
fb2.pubimbue(loc);
fb2.open("tmp", ios_base::in | ios_base::out);
fb2.sgetc();
=09
int written =3D 0;
for (int i =3D 0; i < BUFSIZ; ++i)
written +=3D fb2.sputn(L"abc", 3);
fb2.close();
wfilebuf fb3;
fb3.pubimbue(loc);
fb3.open("tmp", ios_base::in);
for (int j =3D 0; j < BUFSIZ; ++j)
{
wchar_t buf[] =3D L"xxx\n";
int n =3D fb3.sgetn(buf, 3);
assert(n =3D=3D 3);
fputws(buf, stderr);
assert(!wmemcmp(buf, L"abc", 3));
}
=09
fb3.close();
}
class Buf : public std::wfilebuf
{
public:
int_type pub_underflow()
{ return underflow(); }
};
void test5()
{
using namespace std;
// underflow
const wchar_t* strlit =3D L"0123456789";
locale loc (locale::classic(), new Cvt);
wfilebuf fb1;
fb1.pubimbue(loc);
fb1.open("tmp", ios_base::out | ios_base::trunc);
fb1.sputn(strlit, 10);
fb1.close();
Buf fb2;
fb2.pubimbue(loc);
fb2.open("tmp", ios_base::in);
for (int i =3D 0; i < 10; ++i)
{
assert(fb2.pub_underflow() =3D=3D strlit[i]);
fb2.sbumpc();
}
fb2.close();
}
More information about the Gcc-prs
mailing list