From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michal Nazarewicz Newsgroups: gmane.emacs.bugs Subject: bug#24100: [PATCH 3/4] Get rid of re_set_whitespace_regexp Date: Thu, 28 Jul 2016 20:07:16 +0200 Message-ID: <1469729237-14208-3-git-send-email-mina86@mina86.com> References: <1469729237-14208-1-git-send-email-mina86@mina86.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1469729315 22248 80.91.229.3 (28 Jul 2016 18:08:35 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 28 Jul 2016 18:08:35 +0000 (UTC) To: 24100@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Jul 28 20:08:27 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1bSpjP-00014v-9V for geb-bug-gnu-emacs@m.gmane.org; Thu, 28 Jul 2016 20:08:27 +0200 Original-Received: from localhost ([::1]:54953 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bSpjJ-0005Td-1S for geb-bug-gnu-emacs@m.gmane.org; Thu, 28 Jul 2016 14:08:21 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:37385) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bSpj5-0005NZ-N0 for bug-gnu-emacs@gnu.org; Thu, 28 Jul 2016 14:08:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bSpj1-0007sK-Dp for bug-gnu-emacs@gnu.org; Thu, 28 Jul 2016 14:08:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:52276) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bSpj1-0007sG-9w for bug-gnu-emacs@gnu.org; Thu, 28 Jul 2016 14:08:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bSpj1-0007kn-6U for bug-gnu-emacs@gnu.org; Thu, 28 Jul 2016 14:08:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Michal Nazarewicz Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 28 Jul 2016 18:08:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 24100 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 24100-submit@debbugs.gnu.org id=B24100.146972925129745 (code B ref 24100); Thu, 28 Jul 2016 18:08:03 +0000 Original-Received: (at 24100) by debbugs.gnu.org; 28 Jul 2016 18:07:31 +0000 Original-Received: from localhost ([127.0.0.1]:49569 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bSpiV-0007jg-IO for submit@debbugs.gnu.org; Thu, 28 Jul 2016 14:07:31 -0400 Original-Received: from mail-wm0-f45.google.com ([74.125.82.45]:36137) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bSpiS-0007iw-U0 for 24100@debbugs.gnu.org; Thu, 28 Jul 2016 14:07:29 -0400 Original-Received: by mail-wm0-f45.google.com with SMTP id q128so261785230wma.1 for <24100@debbugs.gnu.org>; Thu, 28 Jul 2016 11:07:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CWMMvrr25/mZNTihyDo/a20j2ujVM7uIJfJ+wERzWGI=; b=EVMhoG+gph2puAD07S4l0A1hb4yEb6oNUPiAVjdPeDVGwB8Rls/JVqmW5v6tEzB7iG Pu8H+q1GwTXdOk2dNCJ7jwd5S38ohx/Xd/ibdl3aL/lgs828zzctwL98NyGHYX4VSbnr 1XbxklhPraeirUHd9mqvfEnD4PX0Rkq0J/krCZj0+2PDLbzuuHqH9205ogGVbJNYAZVj TcesZb+4s5Ck3FhNVOnXLbtv2P/GmlcZrc+jgmWOtQddJYlmMgXqjt6CVPI9h9fEBhCW kQwbFpRRHSEKgMiJ+uMBofF5Vqnlb+U7fbddfZlKOA3Ucq42jhOFlp0birVShvRFM4aD xUVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=CWMMvrr25/mZNTihyDo/a20j2ujVM7uIJfJ+wERzWGI=; b=gSP4LQ7g4ehCUvjf9GOXZuvZdpJrjhEAdpDlzWjJ9ZLhfHyRVPiKxr8LTl9cuKpNMF +WLzVMfPfK+I7hap0jxgJ5Z5cDgk+oazIldK3maBClHChdOxX56OxE4a1FixcKN7yOpE 8KGhy6E4CU5924sHKWsBdcbhfDB3E66o48COVHZVjs6IPkNTVyPrJ29gPV1weFd++c8d 759ST9kOZvoifHzl1D0CewGPs/JKrxXu2/S06jBv3aZzjguH4Qp3EQ59HdNmplt5MOu2 CEsZTUcoXaX5r23DE3oGhVRxWHaGVqG2X1NRa5WeIyxY6xJAE7O57ixQnR+zQDCdvkWB WXFQ== X-Gm-Message-State: AEkooutjNfhhQ3AjKDEvYkeXWFf3XuHWiC9f2uc+Ja1h+1OJlvomT2R+6xcFampNmWI0Ce2D X-Received: by 10.28.193.8 with SMTP id r8mr38619475wmf.13.1469729242202; Thu, 28 Jul 2016 11:07:22 -0700 (PDT) Original-Received: from mpn.zrh.corp.google.com ([2620:0:105f:301:7557:b5f1:c9d7:d894]) by smtp.gmail.com with ESMTPSA id q4sm12651853wjk.24.2016.07.28.11.07.19 for <24100@debbugs.gnu.org> (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Jul 2016 11:07:20 -0700 (PDT) Original-Received: by mpn.zrh.corp.google.com (Postfix, from userid 126942) id C07521E35E4; Thu, 28 Jul 2016 20:07:18 +0200 (CEST) X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 In-Reply-To: <1469729237-14208-1-git-send-email-mina86@mina86.com> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:121641 Archived-At: * src/regex.h (re_set_whitespace_regexp): Delete. (re_compile_pattern): Add whitespace_regexp argument #ifdef emacs. * src/regex.c (re_set_whitespace_regexp, whitespace_regexp): Delete. (regex_compile): Add whitespace_regexp argument #ifdef emacs and wrap whitespace_regexp-related code in an #ifdef emacs so it’s compiled out unless building Emacs. (re_compile_pattern): Pass whitespace_regexp argument to regex_compile * src/search.c (compile_pattern_1): Don’t use re_set_whitespace_regexp, pass the regex as argument to re_compile_pattern instead. --- src/regex.c | 39 ++++++++++++++++++++++++--------------- src/regex.h | 3 +-- src/search.c | 13 +++++-------- 3 files changed, 30 insertions(+), 25 deletions(-) diff --git a/src/regex.c b/src/regex.c index 4edc064..c32a62f 100644 --- a/src/regex.c +++ b/src/regex.c @@ -1177,16 +1177,6 @@ re_set_syntax (reg_syntax_t syntax) WEAK_ALIAS (__re_set_syntax, re_set_syntax) #endif - -/* Regexp to use to replace spaces, or NULL meaning don't. */ -static const_re_char *whitespace_regexp; - -void -re_set_whitespace_regexp (const char *regexp) -{ - whitespace_regexp = (const_re_char *) regexp; -} -WEAK_ALIAS (__re_set_syntax, re_set_syntax) /* This table gives an error message for each of the error codes listed in regex.h. Obviously the order here has to be same as there. @@ -1569,6 +1559,9 @@ do { \ static reg_errcode_t regex_compile (re_char *pattern, size_t size, reg_syntax_t syntax, +#ifdef emacs + const char *whitespace_regexp, +#endif struct re_pattern_buffer *bufp); static void store_op1 (re_opcode_t op, unsigned char *loc, int arg); static void store_op2 (re_opcode_t op, unsigned char *loc, int arg1, int arg2); @@ -2398,6 +2391,9 @@ static boolean group_in_compile_stack (compile_stack_type compile_stack, /* `regex_compile' compiles PATTERN (of length SIZE) according to SYNTAX. Returns one of error codes defined in `regex.h', or zero for success. + If WHITESPACE_REGEXP is given (only #ifdef emacs), it is used instead of + a space character in PATTERN. + Assumes the `allocated' (and perhaps `buffer') and `translate' fields are set in BUFP on entry. @@ -2431,6 +2427,9 @@ do { \ static reg_errcode_t regex_compile (const_re_char *pattern, size_t size, reg_syntax_t syntax, +#ifdef emacs + const char *whitespace_regexp, +#endif struct re_pattern_buffer *bufp) { /* We fetch characters from PATTERN here. */ @@ -2483,6 +2482,7 @@ regex_compile (const_re_char *pattern, size_t size, reg_syntax_t syntax, /* If the object matched can contain multibyte characters. */ const boolean multibyte = RE_MULTIBYTE_P (bufp); +#ifdef emacs /* Nonzero if we have pushed down into a subpattern. */ int in_subpattern = 0; @@ -2491,6 +2491,7 @@ regex_compile (const_re_char *pattern, size_t size, reg_syntax_t syntax, re_char *main_p; re_char *main_pattern; re_char *main_pend; +#endif #ifdef DEBUG debug++; @@ -2559,6 +2560,7 @@ regex_compile (const_re_char *pattern, size_t size, reg_syntax_t syntax, { if (p == pend) { +#ifdef emacs /* If this is the end of an included regexp, pop back to the main regexp and try again. */ if (in_subpattern) @@ -2569,6 +2571,7 @@ regex_compile (const_re_char *pattern, size_t size, reg_syntax_t syntax, pend = main_pend; continue; } +#endif /* If this is the end of the main regexp, we are done. */ break; } @@ -2577,6 +2580,7 @@ regex_compile (const_re_char *pattern, size_t size, reg_syntax_t syntax, switch (c) { +#ifdef emacs case ' ': { re_char *p1 = p; @@ -2609,6 +2613,7 @@ regex_compile (const_re_char *pattern, size_t size, reg_syntax_t syntax, pend = p + strlen ((const char *) p); break; } +#endif case '^': { @@ -6276,13 +6281,10 @@ bcmp_translate (const_re_char *s1, const_re_char *s2, register ssize_t len, const char * re_compile_pattern (const char *pattern, size_t length, #ifdef emacs - reg_syntax_t syntax, + reg_syntax_t syntax, const char *whitespace_regexp, #endif struct re_pattern_buffer *bufp) { -#ifndef emacs - const reg_syntax_t syntax = re_syntax_options; -#endif reg_errcode_t ret; /* GNU code is written to assume at least RE_NREGS registers will be set @@ -6294,7 +6296,14 @@ re_compile_pattern (const char *pattern, size_t length, setting no_sub. */ bufp->no_sub = 0; - ret = regex_compile ((re_char*) pattern, length, syntax, bufp); + ret = regex_compile ((re_char*) pattern, length, +#ifdef emacs + syntax, + whitespace_regexp, +#else + re_syntax_options, +#endif + bufp); if (!ret) return NULL; diff --git a/src/regex.h b/src/regex.h index 4497333..af9480d 100644 --- a/src/regex.h +++ b/src/regex.h @@ -474,6 +474,7 @@ extern reg_syntax_t re_set_syntax (reg_syntax_t __syntax); extern const char *re_compile_pattern (const char *__pattern, size_t __length, #ifdef emacs reg_syntax_t syntax, + const char *whitespace_regexp, #endif struct re_pattern_buffer *__buffer); @@ -627,8 +628,6 @@ extern re_wctype_t re_wctype_parse (const unsigned char **strp, unsigned limit); typedef int re_wchar_t; -extern void re_set_whitespace_regexp (const char *regexp); - #endif /* not WIDE_CHAR_SUPPORT */ #endif /* regex.h */ diff --git a/src/search.c b/src/search.c index f041952..c7556a9 100644 --- a/src/search.c +++ b/src/search.c @@ -113,6 +113,7 @@ static void compile_pattern_1 (struct regexp_cache *cp, Lisp_Object pattern, Lisp_Object translate, bool posix) { + const char *whitespace_regexp; reg_syntax_t syntax; char *val; @@ -132,21 +133,17 @@ compile_pattern_1 (struct regexp_cache *cp, Lisp_Object pattern, So let's turn it off. */ /* BLOCK_INPUT; */ - if (STRINGP (Vsearch_spaces_regexp)) - re_set_whitespace_regexp (SSDATA (Vsearch_spaces_regexp)); - else - re_set_whitespace_regexp (NULL); - syntax = RE_SYNTAX_EMACS | (posix ? 0 : RE_NO_POSIX_BACKTRACKING); + whitespace_regexp = STRINGP (Vsearch_spaces_regexp) ? + SSDATA (Vsearch_spaces_regexp) : NULL; + val = (char *) re_compile_pattern (SSDATA (pattern), SBYTES (pattern), - syntax, &cp->buf); + syntax, whitespace_regexp, &cp->buf); /* If the compiled pattern hard codes some of the contents of the syntax-table, it can only be reused with *this* syntax table. */ cp->syntax_table = cp->buf.used_syntax ? BVAR (current_buffer, syntax_table) : Qt; - re_set_whitespace_regexp (NULL); - /* unblock_input (); */ if (val) xsignal1 (Qinvalid_regexp, build_string (val)); -- 2.8.0.rc3.226.g39d4020