From patchwork Mon Feb 5 23:34:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zack Weinberg X-Patchwork-Id: 25828 Received: (qmail 79508 invoked by alias); 5 Feb 2018 23:35:04 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 79379 invoked by uid 89); 5 Feb 2018 23:35:04 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=risks X-HELO: mailbackend.panix.com From: Zack Weinberg To: libc-alpha@sourceware.org Cc: fweimer@redhat.com, joseph@codesourcery.com Subject: [PATCH v2 2/5] Remove getc and putc macros from the public stdio.h. Date: Mon, 5 Feb 2018 18:34:57 -0500 Message-Id: <48dd1f0e9d32e9a96f6c712e828efc3d5b1bb189.1517872307.git.zackw@panix.com> In-Reply-To: References: MIME-Version: 1.0 In-Reply-To: References: 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.) This patch changes installed stripped libraries, since several of the ancillary libraries and programs use getc and/or putc, so they formerly referenced _IO_getc / _IO_putc. * 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. --- NEWS | 7 +++++++ libio/bits/stdio.h | 4 ++-- libio/stdio.h | 8 -------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/NEWS b/NEWS index 3ac57eca4ee..eceab2b2be2 100644 --- a/NEWS +++ b/NEWS @@ -15,6 +15,13 @@ 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: [Add changes to build and runtime requirements here] diff --git a/libio/bits/stdio.h b/libio/bits/stdio.h index d287083de16..eb42b22153c 100644 --- a/libio/bits/stdio.h +++ b/libio/bits/stdio.h @@ -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); } diff --git a/libio/stdio.h b/libio/stdio.h index 95bc902a82c..33de3813bbd 100644 --- a/libio/stdio.h +++ b/libio/stdio.h @@ -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.