diff options
author | Zack Weinberg <zackw@panix.com> | 2017-04-20 11:21:30 -0400 |
---|---|---|
committer | Zack Weinberg <zackw@panix.com> | 2017-06-20 20:33:19 -0400 |
commit | bdf5e4f8bdd50e276b9ed77181087312da849ec2 (patch) | |
tree | 63af5c5367e087dfc0e334ef4f1032d8ffea5c78 /libio/bits/stdio.h | |
parent | df1fabcb39fddbe0a26a0d3f2cefba541d78cb25 (diff) | |
download | glibc-zack/headers-cleanups.tar.gz |
Don't install libio.h or _G_config.h.zack/headers-cleanups
This is an experimental patch which removes libio.h (and _G_config.h)
from the set of application-exposed headers. After this change, the
public stdio.h does not define any symbols whose names begin with _G_
nor _IO_, except that when optimizing, the guts of struct _IO_FILE and
three of the flag constants are visible (see bits/stdio.h and
bits/types/FILE_internals.h). There is a small amount of code
duplication in bits/stdio.h, of macro bodies from libio.h that are no
longer available. A number of internal .c files that were manually
doing PLT bypass for flockfile/funlockfile can now rely on
include/stdio.h to do it for them.
It passes the testsuite on x86_64-linux, but it needs a great deal of
additional testing; in particular I'm almost certain I broke the
support for old-format (GLIBC_2.0) struct _IO_FILE, which is
configured out on this target. Testing this properly would require
someone to get their hands on _really_ old binaries, compiled against
glibc 2.0, possibly statically-linked-but-using-NSS. Unfortunately,
libc.so cannot be expected to be binary identical.
However, this should be ready to feed into archive rebuilds to find
out what applications break.
Substantial clean-ups to the libio implementation are possible if this
sticks, but I haven't done 'em; this is intended to be minimal.
* libio/Makefile: Don't install libio.h or _G_config.h. Do install
bits/types/FILE_internals.h, bits/types/cookie_io_functions_t.h,
and bits/types/__fpos_t.h.
* libio/stdio.h: Don't include libio.h. Get __gnuc_va_list
directly from stdarg.h, __fpos_t and __fpos64_t from
bits/types/__fpos_t.h, and the cookie types from
bits/types/cookie_io_functions_t.h. Change all uses of
_G_va_list, _G_fpos_t, _G_fpos64_t, _IO_FILE,
_IO_cookie_io_functions_t, and _IO_ssize_t to __gnuc_va_list,
__fpos_t, __fpos64_t, FILE, cookie_io_functions_t, and __ssize_t
respectively.
Do not define getc nor putc as macros.
Define BUFSIZ as literal 8192.
* libio/bits/types/FILE_internals.h: New header. Provide complete
definition of struct _IO_FILE (the complete version) here.
Duplicate definitions of _IO_EOF_SEEN, _IO_ERR_SEEN, and _IO_USER_LOCK
here, with value assertions if they are already defined.
* libio/bits/types/__fpos_t.h: New header. Define __fpos_t and
__fpos64_t here.
* libio/bits/types/cookie_io_functions_t.h: New header. Define
cookie_read_function_t, cookie_write_function_t,
cookie_seek_function_t, cookie_close_function_t, and
cookie_io_functions_t here.
* libio/libio.h: Include features.h first thing, then error out if
either _LIBC or __USE_GNU is not defined, or if _ISOMAC is
defined. Inline all of _G_config.h except _G_HAVE_MREMAP here.
Get definitions of __mbstate_t, __fpos_t, __fpos64_t, struct
_IO_FILE, and the cookie-related types from the relevant
bits/types headers. Get definition of NULL from stddef.h.
Make all #ifdef _LIBC and #if __GNUC__ >= (2,3) blocks
unconditional. Remove all #if 0 and #ifdef __cplusplus blocks.
Change all uses of _G_va_list, _G_fpos_t, and _G_fpos64_t to
__gnuc_va_list, __fpos_t, __fpos64_t respectively. Provide
definitions of _STDIO_USES_IOSTREAM, __HAVE_COLUMN,
_IO_file_flags, __io_read_fn, __io_write_fn, __io_seek_fn,
__io_close_fn, _IO_cookie_io_functions_t for the sake of the
implementation. When _IO_USE_OLD_IO_FILE is defined, define
struct _IO_FILE_old.
* libio/libioP.h: When _IO_USE_OLD_IO_FILE is defined, define
struct _IO_FILE_old_plus. Only declare _IO_old_file_init_internal
when _IO_USE_OLD_IO_FILE is defined, and have it take an
argument of type struct _IO_FILE_old_plus.
* libio/oldfileops.c: Change all uses of _IO_FILE to _IO_FILE_old,
_IO_FILE_plus to _IO_FILE_old_plus, _IO_FILE_complete to _IO_FILE,
and _IO_FILE_complete_plus to _IO_FILE_plus. Then adjust types
to match caller/callee's expectations.
* libio/oldiofdopen.c, libio/oldiofopen.c, libio/oldiopopen.c
* libio/oldstdfiles.c: Likewise.
* sysdeps/generic/_G_config.h, sysdeps/unix/sysv/linux/_G_config.h:
Only provide definition or non-definition of _G_HAVE_MREMAP.
* sysdeps/ieee754/ldbl-opt/nldbl-iovfscanf.c: Delete file.
* sysdeps/ieee754/ldbl-opt/Makefile (libnldbl-calls): Remove iovfscanf.
* sysdeps/ieee754/ldbl-opt/nldbl-compat.c: Define
__nldbl__IO_vsprintf as alias to __nldbl_vsprintf instead of
the other way around.
* sysdeps/ieee754/ldbl-opt/nldbl-compat.h:
Change all uses of _G_va_list to __gnuc_va_list. Remove
NLDBL_DECL for _IO_vfscanf.
* sysdeps/ieee754/ldbl-opt/nldbl-fscanf.c
* sysdeps/ieee754/ldbl-opt/nldbl-scanf.c
* sysdeps/ieee754/ldbl-opt/nldbl-vfscanf.c
* sysdeps/ieee754/ldbl-opt/nldbl-vscanf.c:
Use __nldbl_vfscanf, not __nldbl__IO_vfscanf.
* libio/bits/stdio.h: Add multiple-inclusion guard. Include
bits/types/FILE_internals.h. Declare __uflow and __overflow here.
Remove redundant __USE_EXTERN_INLINES ifdef. Change all uses of
_G_va_list to __gnuc_va_list and _IO_ssize_t to __ssize_t.
(getchar): Use getc, not _IO_getc.
(__getc_unlocked, __putc_unlocked): New inlines, duplicating the
bodies of _IO_getc_unlocked and _IO_putc_unlocked.
(fgetc_unlocked, getc_unlocked, getchar_unlocked, fread_unlocked):
Use __getc_unlocked.
(fputc_unlocked, putc_unlocked, putchar_unlocked, fwrite_unlocked):
Use __putc_unlocked.
(feof_unlocked): Duplicate the body of _IO_feof_unlocked here.
(ferror_unlocked): Duplicate the body of _IO_ferror_unlocked here.
* libio/bits/stdio2.h: Change all uses of _G_va_list to __gnuc_va_list.
(fread_unlocked): Use __getc_unlocked.
* libio/bits/types/FILE.h, libio/bits/types/__FILE.h: Explain in
comments why the name _IO_FILE is used.
* include/stdio.h: Change all uses of _G_va_list to __gnuc_va_list,
_IO_ssize_t to __size_t, _IO_FILE to FILE, and _IO_fpos_t to __fpos_t.
When IS_IN (libc), redirect flockfile and funlockfile to
__flockfile and __funlockfile respectively.
When _IO_MTSAFE_IO and not _ISOMAC, include stdio-lock.h before
stdio.h proper.
* include/stdio_ext.h: Include bits/types/FILE_internals.h for the
sake of the inline definition of __fsetlocking.
* include/libio.h: Adjust #ifdef nest to activate multiple-include
optimization.
* include/bits/types/FILE_internals.h, include/bits/types/__fpos_t.h
* include/bits/types/cookie_io_functions_t.h: New trivial wrappers.
* include/bits/stdio.h: New wrapper; mark __uflow and __overflow
as hidden for intra-libc callers.
* csu/init.c: Include libio.h, not _G_config.h.
* grp/fgetgrent_r.c, grp/putgrent.c, gshadow/fgetsgent_r.c
* gshadow/putsgent.c, misc/getpass.c, misc/getttyent.c
* misc/mntent_r.c, posix/getopt.c, pwd/fgetpwent_r.c
* shadow/fgetspent_r.c, shadow/putspent.c:
Don't include libio/iolibio.h. Don't redefine flockfile or
funlockfile. Don't use _IO_flockfile or _IO_funlockfile.
* libio/__fbufsize.c, libio/__flbf.c, libio/__fpending.c
* libio/__freadable.c, libio/__freading.c, libio/__fwritable.c
* libio/__fwriting.c, malloc/malloc.c: Include libio.h.
* misc/err.c: Include libio.h. Don't redefine flockfile or funlockfile.
* stdio-common/tstgetln.c: Include sys/types.h. Don't redefine ssize_t.
* conform/data/stdio.h-data: va_list may be defined as __gnuc_va_list,
not _G_va_list.
* benchtests/strcoll-inputs/filelist#en_US.UTF-8: Remove _G_config.h.
Diffstat (limited to 'libio/bits/stdio.h')
-rw-r--r-- | libio/bits/stdio.h | 71 |
1 files changed, 50 insertions, 21 deletions
diff --git a/libio/bits/stdio.h b/libio/bits/stdio.h index 21ad2fb20c..ad77b04a4f 100644 --- a/libio/bits/stdio.h +++ b/libio/bits/stdio.h @@ -16,24 +16,30 @@ License along with the GNU C Library; if not, see <http://www.gnu.org/licenses/>. */ +#ifndef _BITS_STDIO_H +#define _BITS_STDIO_H 1 + #ifndef _STDIO_H # error "Never include <bits/stdio.h> directly; use <stdio.h> instead." #endif +#include <bits/types/FILE_internals.h> + +extern int __uflow (FILE *); +extern int __overflow (FILE *, int); + #ifndef __extern_inline # define __STDIO_INLINE inline #else # define __STDIO_INLINE __extern_inline #endif - -#ifdef __USE_EXTERN_INLINES /* For -D_FORTIFY_SOURCE{,=2} bits/stdio2.h will define a different inline. */ # if !(__USE_FORTIFY_LEVEL > 0 && defined __fortify_function) /* Write formatted output to stdout from argument list ARG. */ __STDIO_INLINE int -vprintf (const char *__restrict __fmt, _G_va_list __arg) +vprintf (const char *__restrict __fmt, __gnuc_va_list __arg) { return vfprintf (stdout, __fmt, __arg); } @@ -43,8 +49,22 @@ vprintf (const char *__restrict __fmt, _G_va_list __arg) __STDIO_INLINE int getchar (void) { - return _IO_getc (stdin); + return getc (stdin); +} + +#if defined __USE_MISC || defined __USE_POSIX +__STDIO_INLINE int +__getc_unlocked (FILE *__fp) +{ + char __c; + + if (__glibc_unlikely (__fp->_IO_read_ptr >= __fp->_IO_read_end)) + return __uflow (__fp); + + __c = *__fp->_IO_read_ptr++; + return (unsigned char) __c; } +#endif # ifdef __USE_MISC @@ -52,24 +72,23 @@ getchar (void) __STDIO_INLINE int fgetc_unlocked (FILE *__fp) { - return _IO_getc_unlocked (__fp); + return __getc_unlocked (__fp); } # endif /* misc */ - # ifdef __USE_POSIX /* This is defined in POSIX.1:1996. */ __STDIO_INLINE int getc_unlocked (FILE *__fp) { - return _IO_getc_unlocked (__fp); + return __getc_unlocked (__fp); } /* This is defined in POSIX.1:1996. */ __STDIO_INLINE int getchar_unlocked (void) { - return _IO_getc_unlocked (stdin); + return __getc_unlocked (stdin); } # endif /* POSIX */ @@ -78,16 +97,28 @@ getchar_unlocked (void) __STDIO_INLINE int putchar (int __c) { - return _IO_putc (__c, stdout); + return putc (__c, stdout); } +#if defined __USE_MISC || defined __USE_POSIX +__STDIO_INLINE int +__putc_unlocked (int __c, FILE *__stream) +{ + unsigned char __cc = __c; + if (__glibc_unlikely (__stream->_IO_write_ptr >= __stream->_IO_write_end)) + return __overflow (__stream, __cc); + + *__stream->_IO_write_ptr++ = __cc; + return __cc; +} +#endif # ifdef __USE_MISC /* Faster version when locking is not necessary. */ __STDIO_INLINE int fputc_unlocked (int __c, FILE *__stream) { - return _IO_putc_unlocked (__c, __stream); + return __putc_unlocked (__c, __stream); } # endif /* misc */ @@ -97,21 +128,21 @@ fputc_unlocked (int __c, FILE *__stream) __STDIO_INLINE int putc_unlocked (int __c, FILE *__stream) { - return _IO_putc_unlocked (__c, __stream); + return __putc_unlocked (__c, __stream); } /* This is defined in POSIX.1:1996. */ __STDIO_INLINE int putchar_unlocked (int __c) { - return _IO_putc_unlocked (__c, stdout); + return __putc_unlocked (__c, stdout); } # endif /* POSIX */ # ifdef __USE_GNU /* Like `getdelim', but reads up to a newline. */ -__STDIO_INLINE _IO_ssize_t +__STDIO_INLINE __ssize_t getline (char **__lineptr, size_t *__n, FILE *__stream) { return __getdelim (__lineptr, __n, '\n', __stream); @@ -124,20 +155,17 @@ getline (char **__lineptr, size_t *__n, FILE *__stream) __STDIO_INLINE int __NTH (feof_unlocked (FILE *__stream)) { - return _IO_feof_unlocked (__stream); + return (__stream->_flags & _IO_EOF_SEEN) != 0; } /* Faster versions when locking is not required. */ __STDIO_INLINE int __NTH (ferror_unlocked (FILE *__stream)) { - return _IO_ferror_unlocked (__stream); + return (__stream->_flags & _IO_ERR_SEEN) != 0; } # endif /* misc */ -#endif /* Use extern inlines. */ - - #if defined __USE_MISC && defined __GNUC__ && defined __OPTIMIZE__ \ && !defined __cplusplus /* Perform some simple optimizations. */ @@ -151,7 +179,7 @@ __NTH (ferror_unlocked (FILE *__stream)) for (__cnt = (size_t) (size) * (size_t) (n); \ __cnt > 0; --__cnt) \ { \ - int __c = _IO_getc_unlocked (__stream); \ + int __c = __getc_unlocked (__stream); \ if (__c == EOF) \ break; \ *__ptr++ = __c; \ @@ -174,7 +202,7 @@ __NTH (ferror_unlocked (FILE *__stream)) size_t __cnt; \ for (__cnt = (size_t) (size) * (size_t) (n); \ __cnt > 0; --__cnt) \ - if (_IO_putc_unlocked (*__ptr++, __stream) == EOF) \ + if (__putc_unlocked (*__ptr++, __stream) == EOF) \ break; \ ((size_t) (size) * (size_t) (n) - __cnt) \ / (size_t) (size); }) \ @@ -186,5 +214,6 @@ __NTH (ferror_unlocked (FILE *__stream)) : fwrite_unlocked (ptr, size, n, stream)))) #endif -/* Define helper macro. */ #undef __STDIO_INLINE + +#endif /* bits/stdio.h */ |