This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Patch for: libstdc++/2071 (applied with approval to 3.0 branch and mainline)
- To: libstdc++ at gcc dot gnu dot org
- Subject: Patch for: libstdc++/2071 (applied with approval to 3.0 branch and mainline)
- From: Loren James Rittle <rittle at latour dot rsch dot comm dot mot dot com>
- Date: Tue, 12 Jun 2001 18:19:25 -0500 (CDT)
- CC: gcc-patches at gcc dot gnu dot org
- Reply-to: rittle at labs dot mot dot com
See the log for libstdc++/2071 for details and URL references to past
e-mail traffic. This is the "infamous" interactive cin bug.
2001-06-12 Loren J. Rittle <ljrittle@acm.org>
> libstdc++/2071
> * porting.texi: Add documentation about libstdc++-v3-specific
> macros that are currently included in os_defines.h files.
>
> * config/basic_file_stdio.h (sys_getc): New method.
> (sys_ungetc): New method.
> * include/bits/basic_file.h: (sys_getc): New method signature.
> (sys_ungetc): New method signature.
>
> * include/bits/fstream.tcc (underflow): Add conditional code
> paths which avoid using short seeks on streams (especially
> useful when the stream might be interactive or a pipe). At
> the moment, this alternate path only avoids seeking when the
> ``buffer size'' of underflow() is 1 since the C standard only
> guarantees buffer space for one ungetc (this technique could
> be extended since *-*-solaris* supports buffering for 4 calls
> to ungetc and *-*-*bsd* supports buffering limited only by
> memory resources). Also, _GLIBCPP_AVOID_FSEEK must be defined
> in a port's os_defines.h file for this alternate path to even
> be considered. As a bonus, the idiom of using getc/ungetc
> requires no system calls whereas fseek maps to one or two
> system call(s) on many platforms.
>
> * config/os/bsd/freebsd/bits/os_defines.h (_GLIBCPP_AVOID_FSEEK):
> Define it.
> * config/os/solaris/solaris2.5/bits/os_defines.h
> (_GLIBCPP_AVOID_FSEEK): Likewise.
> * config/os/solaris/solaris2.6/bits/os_defines.h
> (_GLIBCPP_AVOID_FSEEK): Likewise.
> * config/os/solaris/solaris2.7/bits/os_defines.h
> (_GLIBCPP_AVOID_FSEEK): Likewise.
Index: libstdc++-v3/porting.texi
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/porting.texi,v
retrieving revision 1.6
diff -r1.6 porting.texi
143a144,156
> At this time, there are two libstdc++-v3-specific macros which may be
> defined. @code{_G_USING_THUNKS} may be defined to 0 to express that the
> port doesn't use thunks (although it is unclear that this is still
> useful since libio support isn't currently working and the g++ v3 ABI
> invalidates the assumption that some ports don't use thunks).
> @code{_GLIBCPP_AVOID_FSEEK} may be defined if seeking on an interactive
> stream (or one hooked to a pipe) is not allowed by the OS. In this
> case, getc()/ungetc() will be used at some key locations in the library
> implementation instead of fseek(). Currently, the code path to avoid
> fseek() is only enabled when the seek size is 1 character away from the
> current stream position. This is known to improve *-unknown-freebsd*
> and sparc-sun-solaris2.*.
>
Index: libstdc++-v3/config/basic_file_stdio.h
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/config/basic_file_stdio.h,v
retrieving revision 1.3
diff -r1.3 basic_file_stdio.h
93a94,107
>
> template<typename _CharT>
> _CharT
> __basic_file<_CharT>::sys_getc()
> {
> return getc (_M_cfile);
> }
>
> template<typename _CharT>
> _CharT
> __basic_file<_CharT>::sys_ungetc(_CharT __s)
> {
> return ungetc (__s, _M_cfile);
> }
Index: libstdc++-v3/config/os/bsd/freebsd/bits/os_defines.h
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/config/os/bsd/freebsd/bits/os_defines.h,v
retrieving revision 1.1
diff -r1.1 os_defines.h
37a38
> #define _GLIBCPP_AVOID_FSEEK 1
Index: libstdc++-v3/config/os/solaris/solaris2.5/bits/os_defines.h
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/config/os/solaris/solaris2.5/bits/os_defines.h,v
retrieving revision 1.5
diff -r1.5 os_defines.h
1c1
< // Specific definitions for Solaris 2.6 -*- C++ -*-
---
> // Specific definitions for Solaris 2.5 -*- C++ -*-
35a36,38
>
> #define _GLIBCPP_AVOID_FSEEK 1
>
46,47d48
<
<
Index: libstdc++-v3/config/os/solaris/solaris2.6/bits/os_defines.h
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/config/os/solaris/solaris2.6/bits/os_defines.h,v
retrieving revision 1.5
diff -r1.5 os_defines.h
35a36,38
>
> #define _GLIBCPP_AVOID_FSEEK 1
>
46,47d48
<
<
Index: libstdc++-v3/config/os/solaris/solaris2.7/bits/os_defines.h
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/config/os/solaris/solaris2.7/bits/os_defines.h,v
retrieving revision 1.7
diff -r1.7 os_defines.h
33a34,38
> /* System-specific #define, typedefs, corrections, etc, go here. This
> file will come before all others. */
>
> #define _GLIBCPP_AVOID_FSEEK 1
>
43d47
<
45d48
<
Index: libstdc++-v3/include/bits/basic_file.h
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/include/bits/basic_file.h,v
retrieving revision 1.8
diff -r1.8 basic_file.h
149a150,155
> _CharT
> sys_getc();
>
> _CharT
> sys_ungetc(_CharT);
>
Index: libstdc++-v3/include/bits/fstream.tcc
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/include/bits/fstream.tcc,v
retrieving revision 1.14
diff -r1.14 fstream.tcc
263a264,267
> #if _GLIBCPP_AVOID_FSEEK
> else if ((_M_in_cur - _M_in_beg) == 1)
> _M_file->sys_getc();
> #endif
278a283,288
> #if _GLIBCPP_AVOID_FSEEK
> if (__size == 1)
> _M_file->sys_ungetc(*_M_in_cur);
> else
> {
> #endif
284a295,297
> #if _GLIBCPP_AVOID_FSEEK
> }
> #endif