]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Remove getc and putc macros from the public stdio.h.
authorZack Weinberg <zackw@panix.com>
Mon, 5 Feb 2018 19:42:29 +0000 (14:42 -0500)
committerZack Weinberg <zackw@panix.com>
Tue, 6 Feb 2018 00:59:03 +0000 (19:59 -0500)
The getc and putc macros in the public stdio.h expand to call _IO_getc
and _IO_putc respectively.  As _IO_getc, fgetc, and getc are all aliases
for the same function, and _IO_putc, fputc, and putc are also all aliases
for the same function, the macros are pointless.  The C standard does
not require getc and putc to be macros, so let's just not have macros.
All four symbols are exported from libc.so at the same, ancient symbol
version, so there should be no risks for binary compatibility.  Similarly,
the getchar and putchar inlines in bits/stdio.h forward to getc and putc
instead of their _IO_ aliases.

As a change from longstanding historical practice, this does seem
like it might break _something_, so there is a note in NEWS, which
is also a convenient place to advise people that if they thought getc
and putc had reduced per-character overhead they should consider using
getc_unlocked and putc_unlocked instead.  (These are also not macros,
but when optimizing, they are inlines.)

* libio/stdio.h: Don't define getc or putc as macros.
* libio/bits/stdio.h (getchar, putchar): Use getc and putc,
not _IO_getc and _IO_putc.

ChangeLog
NEWS
libio/bits/stdio.h
libio/stdio.h

index ce1ae319440b329a7ebf59f7bb9cdf7e9d4aba11..ca221a4ebecaf63a78ed61e60f2ad2741f0e04ee 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2018-02-06  Zack Weinberg  <zackw@panix.com>
 
+       * libio/stdio.h: Don't define getc or putc as macros.
+       * libio/bits/stdio.h (getchar, putchar): Use getc and putc,
+       not _IO_getc and _IO_putc.
+
        * stdio-common/tstgetln.c: Don't redefine FILE, va_list, or BUFSIZ.
        * stdio-common/tstgetln.c: Don't redefine ssize_t.
 
diff --git a/NEWS b/NEWS
index 3ac57eca4eed957482af563717435e327845709a..06ae43d3f09bcf705808d4d022be65b5c70df0b2 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -13,7 +13,12 @@ Major new features:
 
 Deprecated and removed features, and other changes affecting compatibility:
 
-  [Add deprecations, removals and changes affecting compatibility here]
+ * The stdio.h functions 'getc' and 'putc' are no longer defined as macros.
+   This was never required by the C standard, and the macros just expanded
+   to call alternative names for the same functions.  If you hoped getc and
+   putc would provide performance improvements over fgetc and fputc, instead
+   investigate using (f)getc_unlocked and (f)putc_unlocked, and, if
+   necessary, flockfile and funlockfile.
 
 Changes to build and runtime requirements:
 
index d287083de16f03221f7cb416f4cc9be3ed4e07b0..eb42b22153cbb224793ce26ffc4ab49fe8f00699 100644 (file)
@@ -43,7 +43,7 @@ vprintf (const char *__restrict __fmt, _G_va_list __arg)
 __STDIO_INLINE int
 getchar (void)
 {
-  return _IO_getc (stdin);
+  return getc (stdin);
 }
 
 
@@ -78,7 +78,7 @@ getchar_unlocked (void)
 __STDIO_INLINE int
 putchar (int __c)
 {
-  return _IO_putc (__c, stdout);
+  return putc (__c, stdout);
 }
 
 
index 95bc902a82cec670050ca700dcc1def2059aedbf..33de3813bbde00f9be5f9dda73db00bf2b10e0d7 100644 (file)
@@ -483,10 +483,6 @@ extern int getc (FILE *__stream);
    marked with __THROW.  */
 extern int getchar (void);
 
-/* The C standard explicitly says this is a macro, so we always do the
-   optimization for it.  */
-#define getc(_fp) _IO_getc (_fp)
-
 #ifdef __USE_POSIX199506
 /* These are defined in POSIX.1:1996.
 
@@ -523,10 +519,6 @@ extern int putc (int __c, FILE *__stream);
    marked with __THROW.  */
 extern int putchar (int __c);
 
-/* The C standard explicitly says this can be a macro,
-   so we always do the optimization for it.  */
-#define putc(_ch, _fp) _IO_putc (_ch, _fp)
-
 #ifdef __USE_MISC
 /* Faster version when locking is not necessary.