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
This commit is contained in:
Loren J. Rittle 2001-06-12 23:09:09 +00:00 committed by Loren J. Rittle
parent 1d855e87fd
commit ddf1e65262
9 changed files with 93 additions and 7 deletions

View 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

View File

@ -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>*

View File

@ -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

View 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.
//
@ -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

View File

@ -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

View File

@ -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

View File

@ -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();

View File

@ -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
}
}
}

View 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}.
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: