aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoren J. Rittle <ljrittle@acm.org>2001-06-12 23:09:09 +0000
committerLoren J. Rittle <ljrittle@gcc.gnu.org>2001-06-12 23:09:09 +0000
commitddf1e65262a1843776d525cfa32fb5138e24951e (patch)
treec1c7768a7c3fa4e6421e9078340dd04bd57fa444
parent1d855e87fd1e2a8c68d86128616f4c2170800544 (diff)
downloadgcc-ddf1e65262a1843776d525cfa32fb5138e24951e.zip
gcc-ddf1e65262a1843776d525cfa32fb5138e24951e.tar.gz
gcc-ddf1e65262a1843776d525cfa32fb5138e24951e.tar.bz2
porting.texi: Add documentation about libstdc++-v3-specific macros that are currently...
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. From-SVN: r43278
-rw-r--r--libstdc++-v3/ChangeLog34
-rw-r--r--libstdc++-v3/config/basic_file_stdio.h14
-rw-r--r--libstdc++-v3/config/os/bsd/freebsd/bits/os_defines.h1
-rw-r--r--libstdc++-v3/config/os/solaris/solaris2.5/bits/os_defines.h7
-rw-r--r--libstdc++-v3/config/os/solaris/solaris2.6/bits/os_defines.h5
-rw-r--r--libstdc++-v3/config/os/solaris/solaris2.7/bits/os_defines.h7
-rw-r--r--libstdc++-v3/include/bits/basic_file.h6
-rw-r--r--libstdc++-v3/include/bits/fstream.tcc13
-rw-r--r--libstdc++-v3/porting.texi13
9 files changed, 93 insertions, 7 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 9773509..5f3e3d7 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -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
diff --git a/libstdc++-v3/config/basic_file_stdio.h b/libstdc++-v3/config/basic_file_stdio.h
index 565bfea..edf4d98 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<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>*
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 1cb71d1..3a6803f 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 4dd1fa2..5a756b4 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 4dd1fa2..961e29d 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 cb0afed..8ed3867 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 cc41d5b..65081a0 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 b201831..7a41ba7 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 1315de3..87111e7 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: