[PATCH] xregcomp: don't consider every regex compilation failure an internal error.
authorDavid Bremner <david@tethera.net>
Sun, 23 Oct 2011 21:51:13 +0000 (18:51 +2100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:39:44 +0000 (09:39 -0800)
20/6b070147ebe3ac473965d178df0cf1dc745b03 [new file with mode: 0644]

diff --git a/20/6b070147ebe3ac473965d178df0cf1dc745b03 b/20/6b070147ebe3ac473965d178df0cf1dc745b03
new file mode 100644 (file)
index 0000000..6af2253
--- /dev/null
@@ -0,0 +1,133 @@
+Return-Path: <bremner@tethera.net>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id DE8BD429E21\r
+       for <notmuch@notmuchmail.org>; Sun, 23 Oct 2011 14:52:07 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -2.3\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id qQIQiq5b4iII for <notmuch@notmuchmail.org>;\r
+       Sun, 23 Oct 2011 14:52:05 -0700 (PDT)\r
+Received: from tempo.its.unb.ca (tempo.its.unb.ca [131.202.1.21])\r
+       (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 89CA2431FB6\r
+       for <notmuch@notmuchmail.org>; Sun, 23 Oct 2011 14:52:05 -0700 (PDT)\r
+Received: from zancas.localnet\r
+       (fctnnbsc36w-156034064058.pppoe-dynamic.High-Speed.nb.bellaliant.net\r
+       [156.34.64.58]) (authenticated bits=0)\r
+       by tempo.its.unb.ca (8.13.8/8.13.8) with ESMTP id p9NLq0n2012762\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO);\r
+       Sun, 23 Oct 2011 18:52:01 -0300\r
+Received: from bremner by zancas.localnet with local (Exim 4.76)\r
+       (envelope-from <bremner@tethera.net>)\r
+       id 1RI5xY-0001st-7G; Sun, 23 Oct 2011 18:52:00 -0300\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] xregcomp: don't consider every regex compilation failure an\r
+       internal error.\r
+Date: Sun, 23 Oct 2011 18:51:13 -0300\r
+Message-Id: <1319406673-7208-1-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 1.7.6.3\r
+In-Reply-To: <1319383133-11006-1-git-send-email-david@tethera.net>\r
+References: <1319383133-11006-1-git-send-email-david@tethera.net>\r
+Cc: David Bremner <bremner@debian.org>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 23 Oct 2011 21:52:08 -0000\r
+\r
+From: David Bremner <bremner@debian.org>\r
+\r
+This pushes the error handling up one step, but makes the function\r
+more flexible. Running out of memory still triggers an internal error,\r
+in the spirit of other xutils functions.\r
+---\r
+\r
+And here is the promised modification of xregcomp.  One issue I\r
+thought about is that we now have a(nother) place where a library\r
+routine is writing to stderr, not necessarily in the process of\r
+shutting down.\r
+\r
+ notmuch-restore.c |    7 ++++---\r
+ util/xutil.c      |    7 +++++--\r
+ util/xutil.h      |    3 ++-\r
+ 3 files changed, 11 insertions(+), 6 deletions(-)\r
+\r
+diff --git a/notmuch-restore.c b/notmuch-restore.c\r
+index ff1ebab..13b4325 100644\r
+--- a/notmuch-restore.c\r
++++ b/notmuch-restore.c\r
+@@ -88,9 +88,10 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
+      * non-space characters for the message-id, then one or more\r
+      * spaces, then a list of space-separated tags as a sequence of\r
+      * characters within literal '(' and ')'. */\r
+-    xregcomp (&regex,\r
+-            "^([^ ]+) \\(([^)]*)\\)$",\r
+-            REG_EXTENDED);\r
++    if ( xregcomp (&regex,\r
++                 "^([^ ]+) \\(([^)]*)\\)$",\r
++                 REG_EXTENDED) )\r
++      INTERNAL_ERROR("compile time constant regex failed.");\r
\r
+     while ((line_len = getline (&line, &line_size, input)) != -1) {\r
+       regmatch_t match[3];\r
+diff --git a/util/xutil.c b/util/xutil.c\r
+index 15ff765..ac496da 100644\r
+--- a/util/xutil.c\r
++++ b/util/xutil.c\r
+@@ -99,7 +99,7 @@ xstrndup (const char *s, size_t n)\r
+     return ret;\r
+ }\r
\r
+-void\r
++int\r
+ xregcomp (regex_t *preg, const char *regex, int cflags)\r
+ {\r
+     int rerr;\r
+@@ -110,9 +110,12 @@ xregcomp (regex_t *preg, const char *regex, int cflags)\r
+       char *error = xmalloc (error_size);\r
\r
+       regerror (rerr, preg, error, error_size);\r
+-      INTERNAL_ERROR ("compiling regex %s: %s\n",\r
++      fprintf (stderr, "compiling regex %s: %s\n",\r
+                       regex, error);\r
++      free (error);\r
++      return 1;\r
+     }\r
++    return 0;\r
+ }\r
\r
+ int\r
+diff --git a/util/xutil.h b/util/xutil.h\r
+index fd77f73..9299256 100644\r
+--- a/util/xutil.h\r
++++ b/util/xutil.h\r
+@@ -43,7 +43,8 @@ xstrdup (const char *s);\r
+ char *\r
+ xstrndup (const char *s, size_t n);\r
\r
+-void\r
++/* Returns 0 for successful compilation, 1 otherwise */\r
++int\r
+ xregcomp (regex_t *preg, const char *regex, int cflags);\r
\r
+ int\r
+-- \r
+1.7.6.3\r
+\r