Re: [BUG] notmuch crashes on FreeBSD when synchronize_flags=true
[notmuch-archives.git] / ab / d7bfaf901d183afafc662bcfad4053f91d37ac
1 Return-Path: <sojkam1@fel.cvut.cz>\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 7F8CF431FCB\r
6         for <notmuch@notmuchmail.org>; Tue,  4 Nov 2014 16:26:24 -0800 (PST)\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 OX2+mD1Av7pm for <notmuch@notmuchmail.org>;\r
16         Tue,  4 Nov 2014 16:26:19 -0800 (PST)\r
17 Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36])\r
18         by olra.theworths.org (Postfix) with ESMTP id C17AB431FAF\r
19         for <notmuch@notmuchmail.org>; Tue,  4 Nov 2014 16:26:18 -0800 (PST)\r
20 Received: from localhost (unknown [192.168.200.7])\r
21         by max.feld.cvut.cz (Postfix) with ESMTP id 26AAF5CD1AA\r
22         for <notmuch@notmuchmail.org>; Wed,  5 Nov 2014 01:26:18 +0100 (CET)\r
23 X-Virus-Scanned: IMAP STYX AMAVIS\r
24 Received: from max.feld.cvut.cz ([192.168.200.1])\r
25         by localhost (styx.feld.cvut.cz [192.168.200.7]) (amavisd-new,\r
26         port 10044) with ESMTP id 1TkkPSEsyMjG for <notmuch@notmuchmail.org>;\r
27         Wed,  5 Nov 2014 01:26:13 +0100 (CET)\r
28 Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34])\r
29         by max.feld.cvut.cz (Postfix) with ESMTP id 4B2735CD1A6\r
30         for <notmuch@notmuchmail.org>; Wed,  5 Nov 2014 01:26:13 +0100 (CET)\r
31 Received: from wsh by steelpick.2x.cz with local (Exim 4.84)\r
32         (envelope-from <sojkam1@fel.cvut.cz>)\r
33         id 1XloQI-0005Co-Q4; Wed, 05 Nov 2014 01:26:06 +0100\r
34 From: Michal Sojka <sojkam1@fel.cvut.cz>\r
35 To: notmuch@notmuchmail.org\r
36 Subject: [PATCH v3 03/10] cli: search: Convert ctx. to ctx->\r
37 Date: Wed,  5 Nov 2014 01:25:52 +0100\r
38 Message-Id: <1415147159-19946-4-git-send-email-sojkam1@fel.cvut.cz>\r
39 X-Mailer: git-send-email 2.1.1\r
40 In-Reply-To: <1415147159-19946-1-git-send-email-sojkam1@fel.cvut.cz>\r
41 References: <1415147159-19946-1-git-send-email-sojkam1@fel.cvut.cz>\r
42 X-BeenThere: notmuch@notmuchmail.org\r
43 X-Mailman-Version: 2.1.13\r
44 Precedence: list\r
45 List-Id: "Use and development of the notmuch mail system."\r
46         <notmuch.notmuchmail.org>\r
47 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
48         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
49 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
50 List-Post: <mailto:notmuch@notmuchmail.org>\r
51 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
52 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
53         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
54 X-List-Received-Date: Wed, 05 Nov 2014 00:26:24 -0000\r
55 \r
56 In the next commit, notmuch_search_command will be refactored to\r
57 several smaller functions. In order to simplify the next commit to\r
58 verbatim move of several lines to new functions with search_context_t*\r
59 argument, we convert all references to this structure to pointer\r
60 dereferences. To do so we rename the context variable and use the\r
61 original name ctx as the pointer to the renamed structure.\r
62 ---\r
63  notmuch-search.c | 81 ++++++++++++++++++++++++++++----------------------------\r
64  1 file changed, 41 insertions(+), 40 deletions(-)\r
65 \r
66 diff --git a/notmuch-search.c b/notmuch-search.c\r
67 index 3d2012b..6765a16 100644\r
68 --- a/notmuch-search.c\r
69 +++ b/notmuch-search.c\r
70 @@ -474,7 +474,7 @@ do_search_tags (const search_context_t *ctx)\r
71  int\r
72  notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
73  {\r
74 -    search_context_t ctx = {\r
75 +    search_context_t search_context = {\r
76         .format_sel = NOTMUCH_FORMAT_TEXT,\r
77         .exclude = NOTMUCH_EXCLUDE_TRUE,\r
78         .sort = NOTMUCH_SORT_NEWEST_FIRST,\r
79 @@ -483,23 +483,24 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
80         .limit = -1, /* unlimited */\r
81         .dupe = -1,\r
82      };\r
83 +    search_context_t *ctx = &search_context;\r
84      char *query_str;\r
85      int opt_index, ret;\r
86      unsigned int i;\r
87  \r
88      notmuch_opt_desc_t options[] = {\r
89 -       { NOTMUCH_OPT_KEYWORD, &ctx.sort, "sort", 's',\r
90 +       { NOTMUCH_OPT_KEYWORD, &ctx->sort, "sort", 's',\r
91           (notmuch_keyword_t []){ { "oldest-first", NOTMUCH_SORT_OLDEST_FIRST },\r
92                                   { "newest-first", NOTMUCH_SORT_NEWEST_FIRST },\r
93                                   { 0, 0 } } },\r
94 -       { NOTMUCH_OPT_KEYWORD, &ctx.format_sel, "format", 'f',\r
95 +       { NOTMUCH_OPT_KEYWORD, &ctx->format_sel, "format", 'f',\r
96           (notmuch_keyword_t []){ { "json", NOTMUCH_FORMAT_JSON },\r
97                                   { "sexp", NOTMUCH_FORMAT_SEXP },\r
98                                   { "text", NOTMUCH_FORMAT_TEXT },\r
99                                   { "text0", NOTMUCH_FORMAT_TEXT0 },\r
100                                   { 0, 0 } } },\r
101         { NOTMUCH_OPT_INT, &notmuch_format_version, "format-version", 0, 0 },\r
102 -       { NOTMUCH_OPT_KEYWORD_FLAGS, &ctx.output, "output", 'o',\r
103 +       { NOTMUCH_OPT_KEYWORD_FLAGS, &ctx->output, "output", 'o',\r
104           (notmuch_keyword_t []){ { "summary", OUTPUT_SUMMARY },\r
105                                   { "threads", OUTPUT_THREADS },\r
106                                   { "messages", OUTPUT_MESSAGES },\r
107 @@ -508,15 +509,15 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
108                                   { "files", OUTPUT_FILES },\r
109                                   { "tags", OUTPUT_TAGS },\r
110                                   { 0, 0 } } },\r
111 -        { NOTMUCH_OPT_KEYWORD, &ctx.exclude, "exclude", 'x',\r
112 +        { NOTMUCH_OPT_KEYWORD, &ctx->exclude, "exclude", 'x',\r
113            (notmuch_keyword_t []){ { "true", NOTMUCH_EXCLUDE_TRUE },\r
114                                    { "false", NOTMUCH_EXCLUDE_FALSE },\r
115                                    { "flag", NOTMUCH_EXCLUDE_FLAG },\r
116                                    { "all", NOTMUCH_EXCLUDE_ALL },\r
117                                    { 0, 0 } } },\r
118 -       { NOTMUCH_OPT_INT, &ctx.offset, "offset", 'O', 0 },\r
119 -       { NOTMUCH_OPT_INT, &ctx.limit, "limit", 'L', 0  },\r
120 -       { NOTMUCH_OPT_INT, &ctx.dupe, "duplicate", 'D', 0  },\r
121 +       { NOTMUCH_OPT_INT, &ctx->offset, "offset", 'O', 0 },\r
122 +       { NOTMUCH_OPT_INT, &ctx->limit, "limit", 'L', 0  },\r
123 +       { NOTMUCH_OPT_INT, &ctx->dupe, "duplicate", 'D', 0  },\r
124         { 0, 0, 0, 0, 0 }\r
125      };\r
126  \r
127 @@ -524,31 +525,31 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
128      if (opt_index < 0)\r
129         return EXIT_FAILURE;\r
130  \r
131 -    if (! ctx.output)\r
132 -       ctx.output = OUTPUT_SUMMARY;\r
133 +    if (! ctx->output)\r
134 +       ctx->output = OUTPUT_SUMMARY;\r
135  \r
136 -    if (ctx.output != OUTPUT_FILES && ctx.output != OUTPUT_MESSAGES &&\r
137 -       ctx.dupe != -1) {\r
138 +    if (ctx->output != OUTPUT_FILES && ctx->output != OUTPUT_MESSAGES &&\r
139 +       ctx->dupe != -1) {\r
140          fprintf (stderr, "Error: --duplicate=N is only supported with --output=files and --output=messages.\n");\r
141          return EXIT_FAILURE;\r
142      }\r
143  \r
144 -    switch (ctx.format_sel) {\r
145 +    switch (ctx->format_sel) {\r
146      case NOTMUCH_FORMAT_TEXT:\r
147 -       ctx.format = sprinter_text_create (config, stdout);\r
148 +       ctx->format = sprinter_text_create (config, stdout);\r
149         break;\r
150      case NOTMUCH_FORMAT_TEXT0:\r
151 -       if (ctx.output == OUTPUT_SUMMARY) {\r
152 +       if (ctx->output == OUTPUT_SUMMARY) {\r
153             fprintf (stderr, "Error: --format=text0 is not compatible with --output=summary.\n");\r
154             return EXIT_FAILURE;\r
155         }\r
156 -       ctx.format = sprinter_text0_create (config, stdout);\r
157 +       ctx->format = sprinter_text0_create (config, stdout);\r
158         break;\r
159      case NOTMUCH_FORMAT_JSON:\r
160 -       ctx.format = sprinter_json_create (config, stdout);\r
161 +       ctx->format = sprinter_json_create (config, stdout);\r
162         break;\r
163      case NOTMUCH_FORMAT_SEXP:\r
164 -       ctx.format = sprinter_sexp_create (config, stdout);\r
165 +       ctx->format = sprinter_sexp_create (config, stdout);\r
166         break;\r
167      default:\r
168         /* this should never happen */\r
169 @@ -558,10 +559,10 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
170      notmuch_exit_if_unsupported_format ();\r
171  \r
172      if (notmuch_database_open (notmuch_config_get_database_path (config),\r
173 -                              NOTMUCH_DATABASE_MODE_READ_ONLY, &ctx.notmuch))\r
174 +                              NOTMUCH_DATABASE_MODE_READ_ONLY, &ctx->notmuch))\r
175         return EXIT_FAILURE;\r
176  \r
177 -    query_str = query_string_from_args (ctx.notmuch, argc-opt_index, argv+opt_index);\r
178 +    query_str = query_string_from_args (ctx->notmuch, argc-opt_index, argv+opt_index);\r
179      if (query_str == NULL) {\r
180         fprintf (stderr, "Out of memory.\n");\r
181         return EXIT_FAILURE;\r
182 @@ -571,51 +572,51 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
183         return EXIT_FAILURE;\r
184      }\r
185  \r
186 -    ctx.query = notmuch_query_create (ctx.notmuch, query_str);\r
187 -    if (ctx.query == NULL) {\r
188 +    ctx->query = notmuch_query_create (ctx->notmuch, query_str);\r
189 +    if (ctx->query == NULL) {\r
190         fprintf (stderr, "Out of memory\n");\r
191         return EXIT_FAILURE;\r
192      }\r
193  \r
194 -    notmuch_query_set_sort (ctx.query, ctx.sort);\r
195 +    notmuch_query_set_sort (ctx->query, ctx->sort);\r
196  \r
197 -    if (ctx.exclude == NOTMUCH_EXCLUDE_FLAG && ctx.output != OUTPUT_SUMMARY) {\r
198 +    if (ctx->exclude == NOTMUCH_EXCLUDE_FLAG && ctx->output != OUTPUT_SUMMARY) {\r
199         /* If we are not doing summary output there is nowhere to\r
200          * print the excluded flag so fall back on including the\r
201          * excluded messages. */\r
202         fprintf (stderr, "Warning: this output format cannot flag excluded messages.\n");\r
203 -       ctx.exclude = NOTMUCH_EXCLUDE_FALSE;\r
204 +       ctx->exclude = NOTMUCH_EXCLUDE_FALSE;\r
205      }\r
206  \r
207 -    if (ctx.exclude != NOTMUCH_EXCLUDE_FALSE) {\r
208 +    if (ctx->exclude != NOTMUCH_EXCLUDE_FALSE) {\r
209         const char **search_exclude_tags;\r
210         size_t search_exclude_tags_length;\r
211  \r
212         search_exclude_tags = notmuch_config_get_search_exclude_tags\r
213             (config, &search_exclude_tags_length);\r
214         for (i = 0; i < search_exclude_tags_length; i++)\r
215 -           notmuch_query_add_tag_exclude (ctx.query, search_exclude_tags[i]);\r
216 -       notmuch_query_set_omit_excluded (ctx.query, ctx.exclude);\r
217 +           notmuch_query_add_tag_exclude (ctx->query, search_exclude_tags[i]);\r
218 +       notmuch_query_set_omit_excluded (ctx->query, ctx->exclude);\r
219      }\r
220  \r
221 -    if (ctx.output == OUTPUT_SUMMARY ||\r
222 -       ctx.output == OUTPUT_THREADS)\r
223 -       ret = do_search_threads (&ctx);\r
224 -    else if (ctx.output == OUTPUT_MESSAGES ||\r
225 -            ctx.output == OUTPUT_FILES ||\r
226 -            (ctx.output & OUTPUT_ADDRESS_FLAGS && !(ctx.output & ~OUTPUT_ADDRESS_FLAGS)))\r
227 -       ret = do_search_messages (&ctx);\r
228 -    else if (ctx.output == OUTPUT_TAGS)\r
229 -       ret = do_search_tags (&ctx);\r
230 +    if (ctx->output == OUTPUT_SUMMARY ||\r
231 +       ctx->output == OUTPUT_THREADS)\r
232 +       ret = do_search_threads (ctx);\r
233 +    else if (ctx->output == OUTPUT_MESSAGES ||\r
234 +            ctx->output == OUTPUT_FILES ||\r
235 +            (ctx->output & OUTPUT_ADDRESS_FLAGS && !(ctx->output & ~OUTPUT_ADDRESS_FLAGS)))\r
236 +       ret = do_search_messages (ctx);\r
237 +    else if (ctx->output == OUTPUT_TAGS)\r
238 +       ret = do_search_tags (ctx);\r
239      else {\r
240         fprintf (stderr, "Error: the combination of outputs is not supported.\n");\r
241         ret = 1;\r
242      }\r
243  \r
244 -    notmuch_query_destroy (ctx.query);\r
245 -    notmuch_database_destroy (ctx.notmuch);\r
246 +    notmuch_query_destroy (ctx->query);\r
247 +    notmuch_database_destroy (ctx->notmuch);\r
248  \r
249 -    talloc_free (ctx.format);\r
250 +    talloc_free (ctx->format);\r
251  \r
252      return ret ? EXIT_FAILURE : EXIT_SUCCESS;\r
253  }\r
254 -- \r
255 2.1.1\r
256 \r