Re: [RFC] http://notmuchmail.org/searching/ [was: Re: Improving notmuch query documen...
[notmuch-archives.git] / 20 / 6b070147ebe3ac473965d178df0cf1dc745b03
1 Return-Path: <bremner@tethera.net>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id DE8BD429E21\r
6         for <notmuch@notmuchmail.org>; Sun, 23 Oct 2011 14:52:07 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -2.3\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id qQIQiq5b4iII for <notmuch@notmuchmail.org>;\r
16         Sun, 23 Oct 2011 14:52:05 -0700 (PDT)\r
17 Received: from tempo.its.unb.ca (tempo.its.unb.ca [131.202.1.21])\r
18         (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 89CA2431FB6\r
21         for <notmuch@notmuchmail.org>; Sun, 23 Oct 2011 14:52:05 -0700 (PDT)\r
22 Received: from zancas.localnet\r
23         (fctnnbsc36w-156034064058.pppoe-dynamic.High-Speed.nb.bellaliant.net\r
24         [156.34.64.58]) (authenticated bits=0)\r
25         by tempo.its.unb.ca (8.13.8/8.13.8) with ESMTP id p9NLq0n2012762\r
26         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO);\r
27         Sun, 23 Oct 2011 18:52:01 -0300\r
28 Received: from bremner by zancas.localnet with local (Exim 4.76)\r
29         (envelope-from <bremner@tethera.net>)\r
30         id 1RI5xY-0001st-7G; Sun, 23 Oct 2011 18:52:00 -0300\r
31 From: David Bremner <david@tethera.net>\r
32 To: notmuch@notmuchmail.org\r
33 Subject: [PATCH] xregcomp: don't consider every regex compilation failure an\r
34         internal error.\r
35 Date: Sun, 23 Oct 2011 18:51:13 -0300\r
36 Message-Id: <1319406673-7208-1-git-send-email-david@tethera.net>\r
37 X-Mailer: git-send-email 1.7.6.3\r
38 In-Reply-To: <1319383133-11006-1-git-send-email-david@tethera.net>\r
39 References: <1319383133-11006-1-git-send-email-david@tethera.net>\r
40 Cc: David Bremner <bremner@debian.org>\r
41 X-BeenThere: notmuch@notmuchmail.org\r
42 X-Mailman-Version: 2.1.13\r
43 Precedence: list\r
44 List-Id: "Use and development of the notmuch mail system."\r
45         <notmuch.notmuchmail.org>\r
46 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
47         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
48 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
49 List-Post: <mailto:notmuch@notmuchmail.org>\r
50 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
51 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
52         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
53 X-List-Received-Date: Sun, 23 Oct 2011 21:52:08 -0000\r
54 \r
55 From: David Bremner <bremner@debian.org>\r
56 \r
57 This pushes the error handling up one step, but makes the function\r
58 more flexible. Running out of memory still triggers an internal error,\r
59 in the spirit of other xutils functions.\r
60 ---\r
61 \r
62 And here is the promised modification of xregcomp.  One issue I\r
63 thought about is that we now have a(nother) place where a library\r
64 routine is writing to stderr, not necessarily in the process of\r
65 shutting down.\r
66 \r
67  notmuch-restore.c |    7 ++++---\r
68  util/xutil.c      |    7 +++++--\r
69  util/xutil.h      |    3 ++-\r
70  3 files changed, 11 insertions(+), 6 deletions(-)\r
71 \r
72 diff --git a/notmuch-restore.c b/notmuch-restore.c\r
73 index ff1ebab..13b4325 100644\r
74 --- a/notmuch-restore.c\r
75 +++ b/notmuch-restore.c\r
76 @@ -88,9 +88,10 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
77       * non-space characters for the message-id, then one or more\r
78       * spaces, then a list of space-separated tags as a sequence of\r
79       * characters within literal '(' and ')'. */\r
80 -    xregcomp (&regex,\r
81 -             "^([^ ]+) \\(([^)]*)\\)$",\r
82 -             REG_EXTENDED);\r
83 +    if ( xregcomp (&regex,\r
84 +                  "^([^ ]+) \\(([^)]*)\\)$",\r
85 +                  REG_EXTENDED) )\r
86 +       INTERNAL_ERROR("compile time constant regex failed.");\r
87  \r
88      while ((line_len = getline (&line, &line_size, input)) != -1) {\r
89         regmatch_t match[3];\r
90 diff --git a/util/xutil.c b/util/xutil.c\r
91 index 15ff765..ac496da 100644\r
92 --- a/util/xutil.c\r
93 +++ b/util/xutil.c\r
94 @@ -99,7 +99,7 @@ xstrndup (const char *s, size_t n)\r
95      return ret;\r
96  }\r
97  \r
98 -void\r
99 +int\r
100  xregcomp (regex_t *preg, const char *regex, int cflags)\r
101  {\r
102      int rerr;\r
103 @@ -110,9 +110,12 @@ xregcomp (regex_t *preg, const char *regex, int cflags)\r
104         char *error = xmalloc (error_size);\r
105  \r
106         regerror (rerr, preg, error, error_size);\r
107 -       INTERNAL_ERROR ("compiling regex %s: %s\n",\r
108 +       fprintf (stderr, "compiling regex %s: %s\n",\r
109                         regex, error);\r
110 +       free (error);\r
111 +       return 1;\r
112      }\r
113 +    return 0;\r
114  }\r
115  \r
116  int\r
117 diff --git a/util/xutil.h b/util/xutil.h\r
118 index fd77f73..9299256 100644\r
119 --- a/util/xutil.h\r
120 +++ b/util/xutil.h\r
121 @@ -43,7 +43,8 @@ xstrdup (const char *s);\r
122  char *\r
123  xstrndup (const char *s, size_t n);\r
124  \r
125 -void\r
126 +/* Returns 0 for successful compilation, 1 otherwise */\r
127 +int\r
128  xregcomp (regex_t *preg, const char *regex, int cflags);\r
129  \r
130  int\r
131 -- \r
132 1.7.6.3\r
133 \r