From patchwork Wed Dec 26 22:23:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Eggert X-Patchwork-Id: 1018750 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-98780-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=cs.ucla.edu Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="xDWaDxWm"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43Q6vz0CDJz9s3l for ; Thu, 27 Dec 2018 09:24:30 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; q=dns; s=default; b=yPG ENolp/Qf92SZOoTWij3rl/yGoEKXILQu4mP+2AEPyhxgqd0gjXL9USTLOk1+iGnR hN8d55VuiekFusHse1Jbkqkxd8NeY4EnD5mA7wf2a+VJqOXKnQOTzZCGfh5M04nI Fl8EnVjuGrqnYS4cGvlHv6jbOEIp3hFagRZIHO+M= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; s=default; bh=trdgzV5FR Vwlb9/sjgVEVBj5jXs=; b=xDWaDxWmK6VfZF88hLjCrS+/apfYFFvyOrotv3seK n6LlSKUUs7TAMHEIa5QoYM1MONm2Oud9jumAfzHKGyVICKGvBjEbIyj3D2NA0Nku 7i0ZaaaOQzR8p2BSw31b927V/uZiHuCARQTv+mD+adNSCMqZFw2dlqa0/0yEErUo E0= Received: (qmail 93992 invoked by alias); 26 Dec 2018 22:24:07 -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 93911 invoked by uid 89); 26 Dec 2018 22:24:03 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.2 spammy=stores, 34, pure, codes X-HELO: zimbra.cs.ucla.edu From: Paul Eggert To: libc-alpha@sourceware.org Cc: Paul Eggert Subject: [PATCH] regex: simplify Gnulib port Date: Wed, 26 Dec 2018 14:23:54 -0800 Message-Id: <20181226222354.1860-1-eggert@cs.ucla.edu> MIME-Version: 1.0 This simplifies the code, by removing stuff intended for porting to Gnulib but no longer needed there. * posix/regcomp.c [!_LIBC]: No need to put #ifdef _LIBC around uses of libc_hidden_def, weak_alias. * posix/regcomp.c, posix/regexec.c: Use __restrict rather than _Restrict_ except for public-facing headers. * posix/regex_internal.h (attribute_hidden) [!_LIBC]: Remove; already defined elsewhere. * posix/regex.c, posix/regex_internal.h: Use __GNUC_PREREQ instead of rolling our own. * posix/regex_internal.h (__GNUC_PREREQ): Remove duplicate defn. --- ChangeLog | 15 +++++++++++++++ posix/regcomp.c | 16 ++-------------- posix/regex.c | 4 ++-- posix/regex_internal.h | 12 +----------- posix/regexec.c | 6 +++--- 5 files changed, 23 insertions(+), 30 deletions(-) diff --git a/ChangeLog b/ChangeLog index cb959e3789..0ca87317e6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2018-12-26 Paul Eggert + + regex: simplify Gnulib port + This simplifies the code, by removing stuff intended for porting + to Gnulib but no longer needed there. + * posix/regcomp.c [!_LIBC]: No need to put #ifdef _LIBC around + uses of libc_hidden_def, weak_alias. + * posix/regcomp.c, posix/regexec.c: Use __restrict rather than + _Restrict_ except for public-facing headers. + * posix/regex_internal.h (attribute_hidden) [!_LIBC]: + Remove; already defined elsewhere. + * posix/regex.c, posix/regex_internal.h: + Use __GNUC_PREREQ instead of rolling our own. + * posix/regex_internal.h (__GNUC_PREREQ): Remove duplicate defn. + 2018-12-26 H.J. Lu * sysdeps/x86_64/fpu/s_sincosf.S: Removed. diff --git a/posix/regcomp.c b/posix/regcomp.c index 3ede12bfc2..e03900ab0c 100644 --- a/posix/regcomp.c +++ b/posix/regcomp.c @@ -233,9 +233,7 @@ re_compile_pattern (const char *pattern, size_t length, return NULL; return gettext (__re_error_msgid + __re_error_msgid_idx[(int) ret]); } -#ifdef _LIBC weak_alias (__re_compile_pattern, re_compile_pattern) -#endif /* Set by 're_set_syntax' to the current regexp syntax to recognize. Can also be assigned to arbitrarily: each pattern buffer stores its own @@ -260,9 +258,7 @@ re_set_syntax (reg_syntax_t syntax) re_syntax_options = syntax; return ret; } -#ifdef _LIBC weak_alias (__re_set_syntax, re_set_syntax) -#endif int re_compile_fastmap (struct re_pattern_buffer *bufp) @@ -281,9 +277,7 @@ re_compile_fastmap (struct re_pattern_buffer *bufp) bufp->fastmap_accurate = 1; return 0; } -#ifdef _LIBC weak_alias (__re_compile_fastmap, re_compile_fastmap) -#endif static inline void __attribute__ ((always_inline)) @@ -464,7 +458,7 @@ re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state, the return codes and their meanings.) */ int -regcomp (regex_t *_Restrict_ preg, const char *_Restrict_ pattern, int cflags) +regcomp (regex_t *__restrict preg, const char *__restrict pattern, int cflags) { reg_errcode_t ret; reg_syntax_t syntax = ((cflags & REG_EXTENDED) ? RE_SYNTAX_POSIX_EXTENDED @@ -515,16 +509,14 @@ regcomp (regex_t *_Restrict_ preg, const char *_Restrict_ pattern, int cflags) return (int) ret; } -#ifdef _LIBC libc_hidden_def (__regcomp) weak_alias (__regcomp, regcomp) -#endif /* Returns a message corresponding to an error code, ERRCODE, returned from either regcomp or regexec. We don't use PREG here. */ size_t -regerror (int errcode, const regex_t *_Restrict_ preg, char *_Restrict_ errbuf, +regerror (int errcode, const regex_t *__restrict preg, char *__restrict errbuf, size_t errbuf_size) { const char *msg; @@ -555,9 +547,7 @@ regerror (int errcode, const regex_t *_Restrict_ preg, char *_Restrict_ errbuf, return msg_size; } -#ifdef _LIBC weak_alias (__regerror, regerror) -#endif #ifdef RE_ENABLE_I18N @@ -657,10 +647,8 @@ regfree (regex_t *preg) re_free (preg->translate); preg->translate = NULL; } -#ifdef _LIBC libc_hidden_def (__regfree) weak_alias (__regfree, regfree) -#endif /* Entry points compatible with 4.2 BSD regex library. We don't define them unless specifically requested. */ diff --git a/posix/regex.c b/posix/regex.c index a80e740c68..9d2071d3c5 100644 --- a/posix/regex.c +++ b/posix/regex.c @@ -20,10 +20,10 @@ #ifndef _LIBC # include -# if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__ +# if __GNUC_PREREQ (4, 6) # pragma GCC diagnostic ignored "-Wsuggest-attribute=pure" # endif -# if (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) || 4 < __GNUC__ +# if __GNUC_PREREQ (4, 3) # pragma GCC diagnostic ignored "-Wold-style-definition" # pragma GCC diagnostic ignored "-Wtype-limits" # endif diff --git a/posix/regex_internal.h b/posix/regex_internal.h index f4b2702868..c7df419334 100644 --- a/posix/regex_internal.h +++ b/posix/regex_internal.h @@ -144,10 +144,9 @@ # define __mbrtowc mbrtowc # define __wcrtomb wcrtomb # define __regfree regfree -# define attribute_hidden #endif /* not _LIBC */ -#if __GNUC__ < 3 + (__GNUC_MINOR__ < 1) +#if !__GNUC_PREREQ (3, 1) # define __attribute__(arg) #endif @@ -868,15 +867,6 @@ re_string_elem_size_at (const re_string_t *pstr, Idx idx) } #endif /* RE_ENABLE_I18N */ -#ifndef __GNUC_PREREQ -# if defined __GNUC__ && defined __GNUC_MINOR__ -# define __GNUC_PREREQ(maj, min) \ - ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) -# else -# define __GNUC_PREREQ(maj, min) 0 -# endif -#endif - #if __GNUC_PREREQ (3,4) # undef __attribute_warn_unused_result__ # define __attribute_warn_unused_result__ \ diff --git a/posix/regexec.c b/posix/regexec.c index ecb430d302..d89c949f6c 100644 --- a/posix/regexec.c +++ b/posix/regexec.c @@ -189,7 +189,7 @@ static reg_errcode_t extend_buffers (re_match_context_t *mctx, int min_len); We return 0 if we find a match and REG_NOMATCH if not. */ int -regexec (const regex_t *_Restrict_ preg, const char *_Restrict_ string, +regexec (const regex_t *__restrict preg, const char *__restrict string, size_t nmatch, regmatch_t pmatch[], int eflags) { reg_errcode_t err; @@ -232,8 +232,8 @@ __typeof__ (__regexec) __compat_regexec; int attribute_compat_text_section -__compat_regexec (const regex_t *_Restrict_ preg, - const char *_Restrict_ string, size_t nmatch, +__compat_regexec (const regex_t *__restrict preg, + const char *__restrict string, size_t nmatch, regmatch_t pmatch[], int eflags) { return regexec (preg, string, nmatch, pmatch,