This is the mail archive of the gcc-bugs@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]
Other format: [Raw text]

RE: libstdc++/9875: filebuf doesn't handle codecvt::encoding() > 1


> >>    The underflow bits are still missing, however. Are you
> >>    willing to provide some tests for it too?
> >>    
> >>
> >Will do.
> >
> Thanks Pétur.
> By the way, I would appreciate also some actual ;) tests for 
> overflow, 
> since those
> present in the PR didn't really lead to overflow for the default 8192 
> 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 != _M_out_beg
which only happens when switching modes, and the seekoff in
_M_underflow_common only happens when _M_in_cur != _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();
	
	int written = 0;
	for (int i = 0; i < BUFSIZ; ++i)
		written += fb2.sputn(L"abc", 3);

	fb2.close();

	wfilebuf fb3;
	fb3.pubimbue(loc);
	fb3.open("tmp", ios_base::in);

	for (int j = 0; j < BUFSIZ; ++j)
	{
		wchar_t buf[] = L"xxx\n";
		int n = fb3.sgetn(buf, 3);
		assert(n == 3);
		fputws(buf, stderr);
		assert(!wmemcmp(buf, L"abc", 3));
	}
	
	fb3.close();
}

class Buf : public std::wfilebuf
{
public:
	int_type pub_underflow()
		{ return underflow(); }
};

void test5()
{
	using namespace std;

	// underflow
	const wchar_t* strlit = 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 = 0; i < 10; ++i)
	{
		assert(fb2.pub_underflow() == strlit[i]);
		fb2.sbumpc();
	}

	fb2.close();
}


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