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 2/4] Get rid of re_set_syntax Date: Thu, 28 Jul 2016 20:07:15 +0200 Message-ID: <1469729237-14208-2-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 1469729342 23180 80.91.229.3 (28 Jul 2016 18:09:02 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 28 Jul 2016 18:09:02 +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:55 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 1bSpjq-0001I4-Vr for geb-bug-gnu-emacs@m.gmane.org; Thu, 28 Jul 2016 20:08:55 +0200 Original-Received: from localhost ([::1]:54957 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bSpjk-0006Ls-Vt for geb-bug-gnu-emacs@m.gmane.org; Thu, 28 Jul 2016 14:08:49 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:37383) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bSpj5-0005NW-20 for bug-gnu-emacs@gnu.org; Thu, 28 Jul 2016 14:08:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bSpj1-0007sV-Ro for bug-gnu-emacs@gnu.org; Thu, 28 Jul 2016 14:08:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:52277) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bSpj1-0007sR-Nw 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-0007ku-KM 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.146972925429754 (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:34 +0000 Original-Received: from localhost ([127.0.0.1]:49571 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bSpiX-0007jq-Tw for submit@debbugs.gnu.org; Thu, 28 Jul 2016 14:07:34 -0400 Original-Received: from mail-wm0-f54.google.com ([74.125.82.54]:37291) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bSpiU-0007j1-W2 for 24100@debbugs.gnu.org; Thu, 28 Jul 2016 14:07:31 -0400 Original-Received: by mail-wm0-f54.google.com with SMTP id i5so119628078wmg.0 for <24100@debbugs.gnu.org>; Thu, 28 Jul 2016 11:07:30 -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=Wox80dkCNEneMkzvjn3C2xFd+grPElulAi/dePbhRuo=; b=ZSgv+nQdJnnMjpmB7pmm7Aremvxb6Whz2ZQ1dXhJpUaBTLafCXWCy5V5g5kUe0wddq d5/kqhZ8Re1Yblj6W64CqHp7Mr89+YCTCGS73YeIl99VGqGjrp/tw2sJomAJz+pRmN8w HVTk4KUcTa6J6oBKpvBkWNvnMdLVgqe9LsuXCX8Vnmhm61ICfEsIH+1LpAb4CaBl3dqL U8TYRnh5IT2uA0HqNFdp7GQ99FAhQQVxvEtHCh2lMQXPeEpMfSOyUZdoJxkMTYAD44kf 99R1t/LWgl/+1GI1YFjRJhgwk8L8NAu56spb7OESklLOYzPgAQwBf2N7NzcwuVJ3UkeW SKyA== 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=Wox80dkCNEneMkzvjn3C2xFd+grPElulAi/dePbhRuo=; b=L0kXhq/9OsQJn6tQAp9UWsFF2EL6XARFQR7YGgxf58oPeQZgBg5LTg+YhmpPeRY3XW oRRtfdS7I8iLa1P9w6+ZPhkVqd6gFmI2KQOl6ncJ5Nun3+iLrqVdiyZPw4hpG/6YVDkU 9CY+uoDG3xOO1CeIyDGjCaxxOrwpOHrkahBsYaFGKA2hYdl96q+jCv3QOT/Ojj0qtA4t 4vnzXfP/vHbXdN0W3oLVLea7cCu/pR7FRmVFvknwlKkx8NkMfu8Fkq2rIKdu4AdjQkik kPLIcqZp1iOYExjFQBFIpawHaCyr1D4KCZ5kLZL1832fjygAZ7qr3F6WOAWUmdtYopAd aMLQ== X-Gm-Message-State: ALyK8tI3sB/sCBxprZwKMNxTjONmZosQTTRsyLb61jl46vFQC/N9ewfU6Y8tsVzCtCNffzPl X-Received: by 10.28.38.196 with SMTP id m187mr57936901wmm.81.1469729242671; Thu, 28 Jul 2016 11:07:22 -0700 (PDT) Original-Received: from mpn.zrh.corp.google.com ([172.16.113.135]) by smtp.gmail.com with ESMTPSA id m62sm13336642wmm.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 C8B301E0291; 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:121642 Archived-At: Instead of using a global variable for storing regex syntax, pass it to re_compile_pattern. This is only enabled when compiling Emacs (i.e. ‘#ifdef emacs’). * src/regex.h (re_set_syntax): Declare only #ifndef emacs. (re_compile_pattern): Now takes syntax argument #ifdef emacs. * src/regex.c (re_syntax_options): Define only #ifndef emacs. (re_compile_pattern): Use the new syntax argument #ifdef emacs. * src/search.c (compile_pattern_1): Don’t use re_set_syntax and instead pass syntax to re_compile_pattern directly. --- src/regex.c | 12 +++++++++++- src/regex.h | 14 ++++++++++++++ src/search.c | 10 ++++------ 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/regex.c b/src/regex.c index 261d299..4edc064 100644 --- a/src/regex.c +++ b/src/regex.c @@ -1149,6 +1149,8 @@ print_double_string (re_char *where, re_char *string1, ssize_t size1, #endif /* not DEBUG */ +#ifndef emacs + /* Set by `re_set_syntax' to the current regexp syntax to recognize. Can also be assigned to arbitrarily: each pattern buffer stores its own syntax, so it can be changed between regex compilations. */ @@ -1174,6 +1176,8 @@ 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; @@ -6271,8 +6275,14 @@ 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, +#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 @@ -6284,7 +6294,7 @@ re_compile_pattern (const char *pattern, size_t length, setting no_sub. */ bufp->no_sub = 0; - ret = regex_compile ((re_char*) pattern, length, re_syntax_options, bufp); + ret = regex_compile ((re_char*) pattern, length, syntax, bufp); if (!ret) return NULL; diff --git a/src/regex.h b/src/regex.h index 01b659a..4497333 100644 --- a/src/regex.h +++ b/src/regex.h @@ -20,6 +20,13 @@ #ifndef _REGEX_H #define _REGEX_H 1 +#if defined emacs && (defined _REGEX_RE_COMP || defined _LIBC) +/* We’re not defining re_set_syntax and using a different prototype of + re_compile_pattern when building Emacs so fail compilation early with + a (somewhat helpful) error message when conflict is detected. */ +# error "_REGEX_RE_COMP nor _LIBC can be defined if emacs is defined." +#endif + /* Allow the use in C++ code. */ #ifdef __cplusplus extern "C" { @@ -453,14 +460,21 @@ typedef struct /* Declarations for routines. */ +#ifndef emacs + /* Sets the current default syntax to SYNTAX, and return the old syntax. You can also simply assign to the `re_syntax_options' variable. */ extern reg_syntax_t re_set_syntax (reg_syntax_t __syntax); +#endif + /* Compile the regular expression PATTERN, with length LENGTH and syntax given by the global `re_syntax_options', into the buffer BUFFER. Return NULL if successful, and an error string if not. */ extern const char *re_compile_pattern (const char *__pattern, size_t __length, +#ifdef emacs + reg_syntax_t syntax, +#endif struct re_pattern_buffer *__buffer); diff --git a/src/search.c b/src/search.c index 7cb18a2..f041952 100644 --- a/src/search.c +++ b/src/search.c @@ -113,8 +113,8 @@ static void compile_pattern_1 (struct regexp_cache *cp, Lisp_Object pattern, Lisp_Object translate, bool posix) { + reg_syntax_t syntax; char *val; - reg_syntax_t old; cp->regexp = Qnil; cp->buf.translate = (! NILP (translate) ? translate : make_number (0)); @@ -131,16 +131,15 @@ compile_pattern_1 (struct regexp_cache *cp, Lisp_Object pattern, Using BLOCK_INPUT here means the debugger won't run if an error occurs. So let's turn it off. */ /* BLOCK_INPUT; */ - old = re_set_syntax (RE_SYNTAX_EMACS - | (posix ? 0 : RE_NO_POSIX_BACKTRACKING)); if (STRINGP (Vsearch_spaces_regexp)) re_set_whitespace_regexp (SSDATA (Vsearch_spaces_regexp)); else re_set_whitespace_regexp (NULL); - val = (char *) re_compile_pattern (SSDATA (pattern), - SBYTES (pattern), &cp->buf); + syntax = RE_SYNTAX_EMACS | (posix ? 0 : RE_NO_POSIX_BACKTRACKING); + val = (char *) re_compile_pattern (SSDATA (pattern), SBYTES (pattern), + syntax, &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. */ @@ -148,7 +147,6 @@ compile_pattern_1 (struct regexp_cache *cp, Lisp_Object pattern, re_set_whitespace_regexp (NULL); - re_set_syntax (old); /* unblock_input (); */ if (val) xsignal1 (Qinvalid_regexp, build_string (val)); -- 2.8.0.rc3.226.g39d4020