From: ljrittle Date: Tue, 12 Jun 2001 23:09:09 +0000 (+0000) Subject: libstdc++/2071 X-Git-Url: http://git.sourceforge.jp/view?p=pf3gnuchains%2Fgcc-fork.git;a=commitdiff_plain;h=2a793f18526a05291129d30cab5a446d4d4c0946 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@43278 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 977350914a3..5f3e3d7be81 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,37 @@ +2001-06-12 Loren J. Rittle + + 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. + 2001-06-12 Benjamin Kosnik * acinclude.m4 (GLIBCPP_CHECK_COMPILER_VERSION): Change to diff --git a/libstdc++-v3/config/basic_file_stdio.h b/libstdc++-v3/config/basic_file_stdio.h index 565bfea4d40..edf4d98baa9 100644 --- a/libstdc++-v3/config/basic_file_stdio.h +++ b/libstdc++-v3/config/basic_file_stdio.h @@ -91,6 +91,20 @@ namespace std return __ret; } + + template + _CharT + __basic_file<_CharT>::sys_getc() + { + return getc (_M_cfile); + } + + template + _CharT + __basic_file<_CharT>::sys_ungetc(_CharT __s) + { + return ungetc (__s, _M_cfile); + } template __basic_file<_CharT>* diff --git a/libstdc++-v3/config/os/bsd/freebsd/bits/os_defines.h b/libstdc++-v3/config/os/bsd/freebsd/bits/os_defines.h index 1cb71d149ec..3a6803f8f3d 100644 --- a/libstdc++-v3/config/os/bsd/freebsd/bits/os_defines.h +++ b/libstdc++-v3/config/os/bsd/freebsd/bits/os_defines.h @@ -35,6 +35,7 @@ /* System-specific #define, typedefs, corrections, etc, go here. This file will come before all others. */ +#define _GLIBCPP_AVOID_FSEEK 1 #endif diff --git a/libstdc++-v3/config/os/solaris/solaris2.5/bits/os_defines.h b/libstdc++-v3/config/os/solaris/solaris2.5/bits/os_defines.h index 4dd1fa21c46..5a756b4210d 100644 --- a/libstdc++-v3/config/os/solaris/solaris2.5/bits/os_defines.h +++ b/libstdc++-v3/config/os/solaris/solaris2.5/bits/os_defines.h @@ -1,4 +1,4 @@ -// Specific definitions for Solaris 2.6 -*- C++ -*- +// Specific definitions for Solaris 2.5 -*- C++ -*- // Copyright (C) 2000 Free Software Foundation, Inc. // @@ -33,6 +33,9 @@ /* System-specific #define, typedefs, corrections, etc, go here. This file will come before all others. */ + +#define _GLIBCPP_AVOID_FSEEK 1 + // These are typedefs which libio assumes are already in place (because // they really are, under Linux). #define __off_t off_t @@ -43,5 +46,3 @@ #define _G_USING_THUNKS 0 #endif - - diff --git a/libstdc++-v3/config/os/solaris/solaris2.6/bits/os_defines.h b/libstdc++-v3/config/os/solaris/solaris2.6/bits/os_defines.h index 4dd1fa21c46..961e29d55d0 100644 --- a/libstdc++-v3/config/os/solaris/solaris2.6/bits/os_defines.h +++ b/libstdc++-v3/config/os/solaris/solaris2.6/bits/os_defines.h @@ -33,6 +33,9 @@ /* System-specific #define, typedefs, corrections, etc, go here. This file will come before all others. */ + +#define _GLIBCPP_AVOID_FSEEK 1 + // These are typedefs which libio assumes are already in place (because // they really are, under Linux). #define __off_t off_t @@ -43,5 +46,3 @@ #define _G_USING_THUNKS 0 #endif - - diff --git a/libstdc++-v3/config/os/solaris/solaris2.7/bits/os_defines.h b/libstdc++-v3/config/os/solaris/solaris2.7/bits/os_defines.h index cb0afed3259..8ed386765f6 100644 --- a/libstdc++-v3/config/os/solaris/solaris2.7/bits/os_defines.h +++ b/libstdc++-v3/config/os/solaris/solaris2.7/bits/os_defines.h @@ -31,6 +31,11 @@ #ifndef _GLIBCPP_OS_DEFINES # define _GLIBCPP_OS_DEFINES +/* System-specific #define, typedefs, corrections, etc, go here. This + file will come before all others. */ + +#define _GLIBCPP_AVOID_FSEEK 1 + // These are typedefs which libio assumes are already in place (because // they really are, under Linux). #define __off_t off_t @@ -40,6 +45,4 @@ // Without this all the libio vtbls are offset wrongly. #define _G_USING_THUNKS 0 - #endif - diff --git a/libstdc++-v3/include/bits/basic_file.h b/libstdc++-v3/include/bits/basic_file.h index cc41d5bb71d..65081a0af10 100644 --- a/libstdc++-v3/include/bits/basic_file.h +++ b/libstdc++-v3/include/bits/basic_file.h @@ -147,6 +147,12 @@ namespace std __basic_file* sys_open(__c_file_type* __file, ios_base::openmode __mode); + _CharT + sys_getc(); + + _CharT + sys_ungetc(_CharT); + __basic_file* close(); diff --git a/libstdc++-v3/include/bits/fstream.tcc b/libstdc++-v3/include/bits/fstream.tcc index b201831f85b..7a41ba789f6 100644 --- a/libstdc++-v3/include/bits/fstream.tcc +++ b/libstdc++-v3/include/bits/fstream.tcc @@ -261,6 +261,10 @@ namespace std { if (__testout) _M_really_overflow(); +#if _GLIBCPP_AVOID_FSEEK + else if ((_M_in_cur - _M_in_beg) == 1) + _M_file->sys_getc(); +#endif else _M_file->seekoff(_M_in_cur - _M_in_beg, ios_base::cur, ios_base::in); @@ -276,12 +280,21 @@ namespace std if (__testout) _M_out_cur = _M_in_cur; __ret = traits_type::to_int_type(*_M_in_cur); +#if _GLIBCPP_AVOID_FSEEK + if (__size == 1) + _M_file->sys_ungetc(*_M_in_cur); + else + { +#endif streamoff __p = _M_file->seekoff(0 - __size, ios_base::cur, ios_base::in); if (__p == -1) { // XXX Something is wrong, do error checking. } +#if _GLIBCPP_AVOID_FSEEK + } +#endif } } } diff --git a/libstdc++-v3/porting.texi b/libstdc++-v3/porting.texi index 1315de3bbe5..87111e709b8 100644 --- a/libstdc++-v3/porting.texi +++ b/libstdc++-v3/porting.texi @@ -141,6 +141,19 @@ need to define. You will need to add them to the target. It will not work to simply define these macros in @file{os_defines.h}. +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.*. + Finally, you should bracket the entire file in an include-guard, like this: