OSDN Git Service

libstdc++/2071
authorljrittle <ljrittle@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 12 Jun 2001 23:09:09 +0000 (23:09 +0000)
committerljrittle <ljrittle@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 12 Jun 2001 23:09:09 +0000 (23:09 +0000)
* 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

libstdc++-v3/ChangeLog
libstdc++-v3/config/basic_file_stdio.h
libstdc++-v3/config/os/bsd/freebsd/bits/os_defines.h
libstdc++-v3/config/os/solaris/solaris2.5/bits/os_defines.h
libstdc++-v3/config/os/solaris/solaris2.6/bits/os_defines.h
libstdc++-v3/config/os/solaris/solaris2.7/bits/os_defines.h
libstdc++-v3/include/bits/basic_file.h
libstdc++-v3/include/bits/fstream.tcc
libstdc++-v3/porting.texi

index 9773509..5f3e3d7 100644 (file)
@@ -1,3 +1,37 @@
+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.
+
 2001-06-12   Benjamin Kosnik  <bkoz@redhat.com>
 
        * acinclude.m4 (GLIBCPP_CHECK_COMPILER_VERSION): Change to
 2001-06-12   Benjamin Kosnik  <bkoz@redhat.com>
 
        * acinclude.m4 (GLIBCPP_CHECK_COMPILER_VERSION): Change to
index 565bfea..edf4d98 100644 (file)
@@ -91,6 +91,20 @@ namespace std
 
       return __ret;
     }
 
       return __ret;
     }
+
+  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);
+    }
   
   template<typename _CharT>
     __basic_file<_CharT>* 
   
   template<typename _CharT>
     __basic_file<_CharT>* 
index 1cb71d1..3a6803f 100644 (file)
@@ -35,6 +35,7 @@
 /* System-specific #define, typedefs, corrections, etc, go here.  This
    file will come before all others. */
 
 /* System-specific #define, typedefs, corrections, etc, go here.  This
    file will come before all others. */
 
+#define _GLIBCPP_AVOID_FSEEK 1
 
 #endif
 
 
 #endif
 
index 4dd1fa2..5a756b4 100644 (file)
@@ -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.
 //
 
 // 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. */
 
 /* 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
 // 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
 #define _G_USING_THUNKS 0
 
 #endif
-
-
index 4dd1fa2..961e29d 100644 (file)
@@ -33,6 +33,9 @@
 
 /* System-specific #define, typedefs, corrections, etc, go here.  This
    file will come before all others. */
 
 /* 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
 // 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
 #define _G_USING_THUNKS 0
 
 #endif
-
-
index cb0afed..8ed3867 100644 (file)
 #ifndef _GLIBCPP_OS_DEFINES
 #  define _GLIBCPP_OS_DEFINES
 
 #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
 // 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
 
 // Without this all the libio vtbls are offset wrongly.
 #define _G_USING_THUNKS 0
 
-
 #endif
 #endif
-
index cc41d5b..65081a0 100644 (file)
@@ -147,6 +147,12 @@ namespace std
       __basic_file*
       sys_open(__c_file_type* __file, ios_base::openmode __mode);
 
       __basic_file*
       sys_open(__c_file_type* __file, ios_base::openmode __mode);
 
+      _CharT
+      sys_getc();
+
+      _CharT
+      sys_ungetc(_CharT);
+
       __basic_file* 
       close(); 
 
       __basic_file* 
       close(); 
 
index b201831..7a41ba7 100644 (file)
@@ -261,6 +261,10 @@ namespace std
            {
              if (__testout)
                _M_really_overflow();
            {
              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);
              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 (__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.
                    }
                  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
                }          
            }
        }
                }          
            }
        }
index 1315de3..87111e7 100644 (file)
@@ -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}.
 
 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:
 
 Finally, you should bracket the entire file in an include-guard, like
 this: