Re: [PATCH 5/7] py3k: the basestring and unicode types are removed in python 3
[notmuch-archives.git] / cd / d28a9f92fdb9aa588d53872981c427d7b55787
1 Return-Path: <bremner@unb.ca>\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 11312429E25\r
6         for <notmuch@notmuchmail.org>; Sat, 29 Oct 2011 11:52:38 -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: -0.525\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.525 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_MED=-2.3, URIBL_BLACK=1.775] 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 789WWmsVrckh for <notmuch@notmuchmail.org>;\r
16         Sat, 29 Oct 2011 11:52:35 -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 44A2F431FB6\r
21         for <notmuch@notmuchmail.org>; Sat, 29 Oct 2011 11:52:35 -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 p9TIqXhe001319\r
26         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO);\r
27         Sat, 29 Oct 2011 15:52:33 -0300\r
28 Received: from bremner by zancas.localnet with local (Exim 4.76)\r
29         (envelope-from <bremner@unb.ca>)\r
30         id 1RKE1A-0004Nq-Ud; Sat, 29 Oct 2011 15:52:32 -0300\r
31 From: David Bremner <david@tethera.net>\r
32 To: notmuch@notmuchmail.org\r
33 Subject: Re: [PATCH] xutil.c: remove duplicate copies,\r
34         create new library libutil.a to contain xutil.\r
35 In-Reply-To: <1319383133-11006-1-git-send-email-david@tethera.net>\r
36 References: <1319383133-11006-1-git-send-email-david@tethera.net>\r
37 User-Agent: Notmuch/0.9+26~g4e49596 (http://notmuchmail.org) Emacs/23.3.1\r
38         (x86_64-pc-linux-gnu)\r
39 Date: Sat, 29 Oct 2011 15:52:25 -0300\r
40 Message-ID: <87aa8j7hqu.fsf@zancas.localnet>\r
41 MIME-Version: 1.0\r
42 Content-Type: multipart/mixed; boundary="=-=-="\r
43 X-BeenThere: notmuch@notmuchmail.org\r
44 X-Mailman-Version: 2.1.13\r
45 Precedence: list\r
46 List-Id: "Use and development of the notmuch mail system."\r
47         <notmuch.notmuchmail.org>\r
48 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
49         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
50 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
51 List-Post: <mailto:notmuch@notmuchmail.org>\r
52 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
53 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
54         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
55 X-List-Received-Date: Sat, 29 Oct 2011 18:52:38 -0000\r
56 \r
57 --=-=-=\r
58 Content-Type: multipart/signed; boundary="==-=-=";\r
59         micalg=pgp-sha1; protocol="application/pgp-signature"\r
60 \r
61 --==-=-=\r
62 Content-Transfer-Encoding: quoted-printable\r
63 \r
64 On Sun, 23 Oct 2011 12:18:53 -0300, David Bremner <david@tethera.net> wrote:\r
65 > From: David Bremner <bremner@debian.org>\r
66 >=20\r
67 > We keep the lib/xutil.c version. As a consequence, also factor out\r
68 > _internal_error and associated macros.  It might be overkill to make a\r
69 > new file error_util.c for this, but _internal_error does not really\r
70 > belong in database.cc.\r
71 \r
72 It seems this patch was sent out base64 encoded, which confuses git-am.\r
73 I attach the patch here. You won't be able to git am this message, but\r
74 you can at least save the attachment and apply it. Sorry for the\r
75 inconvenience.\r
76 \r
77 \r
78 --==-=-=\r
79 Content-Type: application/pgp-signature\r
80 \r
81 -----BEGIN PGP SIGNATURE-----\r
82 Version: GnuPG v1.4.11 (GNU/Linux)\r
83 \r
84 iJwEAQECAAYFAk6sS2kACgkQTiiN/0Um85lD5AP9F3/wFn9mhV2s21RY5pkFylGo\r
85 ZdxDa6IWnCYvuCSHgYu6cbYS2Ttimls2gXJIw9p3hVADSWQ5WXNFykG1cLk7EHB7\r
86 lEGdU3nhRHmj9yX3VD4sLX9moozVVz2+aQBvcywFU+AWS15p09ZSde2APAmhSBTh\r
87 HnmxCtkC+kk5Rw7Nm/Q=\r
88 =BFhN\r
89 -----END PGP SIGNATURE-----\r
90 --==-=-=--\r
91 \r
92 --=-=-=\r
93 Content-Type: text/x-diff; charset=utf-8\r
94 Content-Disposition: attachment;\r
95  filename=0001-xutil.c-remove-duplicate-copies-create-new-library-l.patch\r
96 Content-Transfer-Encoding: quoted-printable\r
97 Content-Description: xutil patch\r
98 \r
99 >From 5c678c9bc96890ce9a5965d6654851ebbe2b4767 Mon Sep 17 00:00:00 2001\r
100 From: David Bremner <bremner@debian.org>\r
101 Date: Sun, 23 Oct 2011 12:05:13 -0300\r
102 Subject: [PATCH] xutil.c: remove duplicate copies, create new library\r
103  libutil.a to contain xutil.\r
104 \r
105 We keep the lib/xutil.c version. As a consequence, also factor out\r
106 _internal_error and associated macros.  It might be overkill to make a\r
107 new file error_util.c for this, but _internal_error does not really\r
108 belong in database.cc.\r
109 ---\r
110  Makefile              |    2 +-\r
111  Makefile.local        |    7 +--\r
112  lib/Makefile.local    |    5 +-\r
113  lib/database.cc       |   15 -----\r
114  lib/notmuch-private.h |   20 +-------\r
115  lib/xutil.c           |  134 ---------------------------------------------=\r
116 --\r
117  lib/xutil.h           |   55 -------------------\r
118  util/Makefile         |    5 ++\r
119  util/Makefile.local   |   11 ++++\r
120  util/error_util.c     |   41 +++++++++++++++\r
121  util/error_util.h     |   45 ++++++++++++++++\r
122  util/xutil.c          |  136 +++++++++++++++++++++++++++++++++++++++++++++=\r
123 +++\r
124  util/xutil.h          |   55 +++++++++++++++++++\r
125  xutil.c               |  138 ---------------------------------------------=\r
126 ----\r
127  14 files changed, 300 insertions(+), 369 deletions(-)\r
128  delete mode 100644 lib/xutil.c\r
129  delete mode 100644 lib/xutil.h\r
130  create mode 100644 util/Makefile\r
131  create mode 100644 util/Makefile.local\r
132  create mode 100644 util/error_util.c\r
133  create mode 100644 util/error_util.h\r
134  create mode 100644 util/xutil.c\r
135  create mode 100644 util/xutil.h\r
136  delete mode 100644 xutil.c\r
137 \r
138 diff --git a/Makefile b/Makefile\r
139 index 11e3a3d..2fb2a61 100644\r
140 --- a/Makefile\r
141 +++ b/Makefile\r
142 @@ -3,7 +3,7 @@\r
143  all:\r
144 =20\r
145  # List all subdirectories here. Each contains its own Makefile.local\r
146 -subdirs =3D compat completion emacs lib test\r
147 +subdirs =3D compat completion emacs lib util test\r
148 =20\r
149  # We make all targets depend on the Makefiles themselves.\r
150  global_deps =3D Makefile Makefile.config Makefile.local \\r
151 diff --git a/Makefile.local b/Makefile.local\r
152 index ec09f95..6ddef5c 100644\r
153 --- a/Makefile.local\r
154 +++ b/Makefile.local\r
155 @@ -39,7 +39,7 @@ PV_FILE=3Dbindings/python/notmuch/version.py\r
156  # Smash together user's values with our extra values\r
157  FINAL_CFLAGS =3D -DNOTMUCH_VERSION=3D$(VERSION) $(CFLAGS) $(WARN_CFLAGS) $=\r
158 (CONFIGURE_CFLAGS) $(extra_cflags)\r
159  FINAL_CXXFLAGS =3D $(CXXFLAGS) $(WARN_CXXFLAGS) $(CONFIGURE_CXXFLAGS) $(ex=\r
160 tra_cflags) $(extra_cxxflags)\r
161 -FINAL_NOTMUCH_LDFLAGS =3D $(LDFLAGS) -Llib -lnotmuch $(AS_NEEDED_LDFLAGS) =\r
162 $(GMIME_LDFLAGS) $(TALLOC_LDFLAGS)\r
163 +FINAL_NOTMUCH_LDFLAGS =3D $(LDFLAGS) -Lutil -lutil -Llib -lnotmuch $(AS_NE=\r
164 EDED_LDFLAGS) $(GMIME_LDFLAGS) $(TALLOC_LDFLAGS)\r
165  FINAL_NOTMUCH_LINKER =3D CC\r
166  ifneq ($(LINKER_RESOLVES_LIBRARY_DEPENDENCIES),1)\r
167  FINAL_NOTMUCH_LDFLAGS +=3D $(CONFIGURE_LDFLAGS)\r
168 @@ -299,12 +299,11 @@ notmuch_client_srcs =3D           \\r
169         notmuch-time.c          \\r
170         query-string.c          \\r
171         show-message.c          \\r
172 -       json.c                  \\r
173 -       xutil.c\r
174 +       json.c\r
175 =20\r
176  notmuch_client_modules =3D $(notmuch_client_srcs:.c=3D.o)\r
177 =20\r
178 -notmuch: $(notmuch_client_modules) lib/libnotmuch.a\r
179 +notmuch: $(notmuch_client_modules) lib/libnotmuch.a util/libutil.a\r
180         $(call quiet,CXX $(CFLAGS)) $^ $(FINAL_LIBNOTMUCH_LDFLAGS) -o $@\r
181 =20\r
182  notmuch-shared: $(notmuch_client_modules) lib/$(LINKER_NAME)\r
183 diff --git a/lib/Makefile.local b/lib/Makefile.local\r
184 index be51eaa..d58552c 100644\r
185 --- a/lib/Makefile.local\r
186 +++ b/lib/Makefile.local\r
187 @@ -54,8 +54,7 @@ libnotmuch_c_srcs =3D         \\r
188         $(dir)/message-file.c   \\r
189         $(dir)/messages.c       \\r
190         $(dir)/sha1.c           \\r
191 -       $(dir)/tags.c           \\r
192 -       $(dir)/xutil.c\r
193 +       $(dir)/tags.c\r
194 =20\r
195  libnotmuch_cxx_srcs =3D                \\r
196         $(dir)/database.cc      \\r
197 @@ -71,7 +70,7 @@ $(dir)/libnotmuch.a: $(libnotmuch_modules)\r
198         $(call quiet,AR) rcs $@ $^\r
199 =20\r
200  $(dir)/$(LIBNAME): $(libnotmuch_modules) notmuch.sym\r
201 -       $(call quiet,CXX $(CXXFLAGS)) $(libnotmuch_modules) $(FINAL_LIBNOTMUCH_LD=\r
202 FLAGS) $(LIBRARY_LINK_FLAG) -o $@\r
203 +       $(call quiet,CXX $(CXXFLAGS)) $(libnotmuch_modules) $(FINAL_LIBNOTMUCH_LD=\r
204 FLAGS) $(LIBRARY_LINK_FLAG) -o $@ -L$(srcdir)/util -lutil\r
205 =20\r
206  notmuch.sym: $(srcdir)/$(dir)/notmuch.h $(libnotmuch_modules)\r
207         sh $(srcdir)/$(lib)/gen-version-script.sh $< $(libnotmuch_modules) > $@\r
208 diff --git a/lib/database.cc b/lib/database.cc\r
209 index e77fd53..88be939 100644\r
210 --- a/lib/database.cc\r
211 +++ b/lib/database.cc\r
212 @@ -209,21 +209,6 @@ static prefix_t PROBABILISTIC_PREFIX[]=3D {\r
213      { "folder",                        "XFOLDER"}\r
214  };\r
215 =20\r
216 -int\r
217 -_internal_error (const char *format, ...)\r
218 -{\r
219 -    va_list va_args;\r
220 -\r
221 -    va_start (va_args, format);\r
222 -\r
223 -    fprintf (stderr, "Internal error: ");\r
224 -    vfprintf (stderr, format, va_args);\r
225 -\r
226 -    exit (1);\r
227 -\r
228 -    return 1;\r
229 -}\r
230 -\r
231  const char *\r
232  _find_prefix (const char *name)\r
233  {\r
234 diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
235 index d319530..0d3cc27 100644\r
236 --- a/lib/notmuch-private.h\r
237 +++ b/lib/notmuch-private.h\r
238 @@ -47,6 +47,7 @@ NOTMUCH_BEGIN_DECLS\r
239  #include <talloc.h>\r
240 =20\r
241  #include "xutil.h"\r
242 +#include "error_util.h"\r
243 =20\r
244  #pragma GCC visibility push(hidden)\r
245 =20\r
246 @@ -60,25 +61,6 @@ NOTMUCH_BEGIN_DECLS\r
247  #define STRNCMP_LITERAL(var, literal) \\r
248      strncmp ((var), (literal), sizeof (literal) - 1)\r
249 =20\r
250 -/* There's no point in continuing when we've detected that we've done\r
251 - * something wrong internally (as opposed to the user passing in a\r
252 - * bogus value).\r
253 - *\r
254 - * Note that PRINTF_ATTRIBUTE comes from talloc.h\r
255 - */\r
256 -int\r
257 -_internal_error (const char *format, ...) PRINTF_ATTRIBUTE (1, 2);\r
258 -\r
259 -/* There's no point in continuing when we've detected that we've done\r
260 - * something wrong internally (as opposed to the user passing in a\r
261 - * bogus value).\r
262 - *\r
263 - * Note that __location__ comes from talloc.h.\r
264 - */\r
265 -#define INTERNAL_ERROR(format, ...)                    \\r
266 -    _internal_error (format " (%s).\n",                        \\r
267 -                    ##__VA_ARGS__, __location__)\r
268 -\r
269  #define unused(x) x __attribute__ ((unused))\r
270 =20\r
271  #ifdef __cplusplus\r
272 diff --git a/lib/xutil.c b/lib/xutil.c\r
273 deleted file mode 100644\r
274 index 268225b..0000000\r
275 --- a/lib/xutil.c\r
276 +++ /dev/null\r
277 @@ -1,134 +0,0 @@\r
278 -/* xutil.c - Various wrapper functions to abort on error.\r
279 - *\r
280 - * Copyright =C2=A9 2009 Carl Worth\r
281 - *\r
282 - * This program is free software: you can redistribute it and/or modify\r
283 - * it under the terms of the GNU General Public License as published by\r
284 - * the Free Software Foundation, either version 3 of the License, or\r
285 - * (at your option) any later version.\r
286 - *\r
287 - * This program is distributed in the hope that it will be useful,\r
288 - * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
289 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
290 - * GNU General Public License for more details.\r
291 - *\r
292 - * You should have received a copy of the GNU General Public License\r
293 - * along with this program.  If not, see http://www.gnu.org/licenses/ .\r
294 - *\r
295 - * Author: Carl Worth <cworth@cworth.org>\r
296 - */\r
297 -\r
298 -#include "notmuch-private.h"\r
299 -\r
300 -#include <stdio.h>\r
301 -\r
302 -void *\r
303 -xcalloc (size_t nmemb, size_t size)\r
304 -{\r
305 -    void *ret;\r
306 -\r
307 -    ret =3D calloc (nmemb, size);\r
308 -    if (ret =3D=3D NULL) {\r
309 -       fprintf (stderr, "Out of memory.\n");\r
310 -       exit (1);\r
311 -    }\r
312 -\r
313 -    return ret;\r
314 -}\r
315 -\r
316 -void *\r
317 -xmalloc (size_t size)\r
318 -{\r
319 -    void *ret;\r
320 -\r
321 -    ret =3D malloc (size);\r
322 -    if (ret =3D=3D NULL) {\r
323 -       fprintf (stderr, "Out of memory.\n");\r
324 -       exit (1);\r
325 -    }\r
326 -\r
327 -    return ret;\r
328 -}\r
329 -\r
330 -void *\r
331 -xrealloc (void *ptr, size_t size)\r
332 -{\r
333 -    void *ret;\r
334 -\r
335 -    ret =3D realloc (ptr, size);\r
336 -    if (ret =3D=3D NULL) {\r
337 -       fprintf (stderr, "Out of memory.\n");\r
338 -       exit (1);\r
339 -    }\r
340 -\r
341 -    return ret;\r
342 -}\r
343 -\r
344 -char *\r
345 -xstrdup (const char *s)\r
346 -{\r
347 -    char *ret;\r
348 -\r
349 -    ret =3D strdup (s);\r
350 -    if (ret =3D=3D NULL) {\r
351 -       fprintf (stderr, "Out of memory.\n");\r
352 -       exit (1);\r
353 -    }\r
354 -\r
355 -    return ret;\r
356 -}\r
357 -\r
358 -char *\r
359 -xstrndup (const char *s, size_t n)\r
360 -{\r
361 -    char *ret;\r
362 -\r
363 -    if (strlen (s) <=3D n)\r
364 -       n =3D strlen (s);\r
365 -\r
366 -    ret =3D malloc (n + 1);\r
367 -    if (ret =3D=3D NULL) {\r
368 -       fprintf (stderr, "Out of memory.\n");\r
369 -       exit (1);\r
370 -    }\r
371 -    memcpy (ret, s, n);\r
372 -    ret[n] =3D '\0';\r
373 -\r
374 -    return ret;\r
375 -}\r
376 -\r
377 -void\r
378 -xregcomp (regex_t *preg, const char *regex, int cflags)\r
379 -{\r
380 -    int rerr;\r
381 -\r
382 -    rerr =3D regcomp (preg, regex, cflags);\r
383 -    if (rerr) {\r
384 -       size_t error_size =3D regerror (rerr, preg, NULL, 0);\r
385 -       char *error =3D xmalloc (error_size);\r
386 -\r
387 -       regerror (rerr, preg, error, error_size);\r
388 -       INTERNAL_ERROR ("compiling regex %s: %s\n",\r
389 -                       regex, error);\r
390 -    }\r
391 -}\r
392 -\r
393 -int\r
394 -xregexec (const regex_t *preg, const char *string,\r
395 -         size_t nmatch, regmatch_t pmatch[], int eflags)\r
396 -{\r
397 -    unsigned int i;\r
398 -    int rerr;\r
399 -\r
400 -    rerr =3D regexec (preg, string, nmatch, pmatch, eflags);\r
401 -    if (rerr)\r
402 -       return rerr;\r
403 -\r
404 -    for (i =3D 0; i < nmatch; i++) {\r
405 -       if (pmatch[i].rm_so =3D=3D -1)\r
406 -           INTERNAL_ERROR ("matching regex against %s: Sub-match %d not found\n",\r
407 -                           string, i);\r
408 -    }\r
409 -\r
410 -    return 0;\r
411 -}\r
412 diff --git a/lib/xutil.h b/lib/xutil.h\r
413 deleted file mode 100644\r
414 index fd77f73..0000000\r
415 --- a/lib/xutil.h\r
416 +++ /dev/null\r
417 @@ -1,55 +0,0 @@\r
418 -/* xutil.h - Various wrapper functions to abort on error.\r
419 - *\r
420 - * Copyright =C2=A9 2009 Carl Worth\r
421 - *\r
422 - * This program is free software: you can redistribute it and/or modify\r
423 - * it under the terms of the GNU General Public License as published by\r
424 - * the Free Software Foundation, either version 3 of the License, or\r
425 - * (at your option) any later version.\r
426 - *\r
427 - * This program is distributed in the hope that it will be useful,\r
428 - * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
429 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
430 - * GNU General Public License for more details.\r
431 - *\r
432 - * You should have received a copy of the GNU General Public License\r
433 - * along with this program.  If not, see http://www.gnu.org/licenses/ .\r
434 - *\r
435 - * Author: Carl Worth <cworth@cworth.org>\r
436 - */\r
437 -\r
438 -#ifndef NOTMUCH_XUTIL_H\r
439 -#define NOTMUCH_XUTIL_H\r
440 -\r
441 -#include <stdlib.h>\r
442 -#include <sys/types.h>\r
443 -#include <regex.h>\r
444 -\r
445 -#pragma GCC visibility push(hidden)\r
446 -\r
447 -/* xutil.c */\r
448 -void *\r
449 -xcalloc (size_t nmemb, size_t size);\r
450 -\r
451 -void *\r
452 -xmalloc (size_t size);\r
453 -\r
454 -void *\r
455 -xrealloc (void *ptrr, size_t size);\r
456 -\r
457 -char *\r
458 -xstrdup (const char *s);\r
459 -\r
460 -char *\r
461 -xstrndup (const char *s, size_t n);\r
462 -\r
463 -void\r
464 -xregcomp (regex_t *preg, const char *regex, int cflags);\r
465 -\r
466 -int\r
467 -xregexec (const regex_t *preg, const char *string,\r
468 -         size_t nmatch, regmatch_t pmatch[], int eflags);\r
469 -\r
470 -#pragma GCC visibility pop\r
471 -\r
472 -#endif\r
473 diff --git a/util/Makefile b/util/Makefile\r
474 new file mode 100644\r
475 index 0000000..fa25832\r
476 --- /dev/null\r
477 +++ b/util/Makefile\r
478 @@ -0,0 +1,5 @@\r
479 +all:\r
480 +       $(MAKE) -C .. all\r
481 +\r
482 +.DEFAULT:\r
483 +       $(MAKE) -C .. $@\r
484 diff --git a/util/Makefile.local b/util/Makefile.local\r
485 new file mode 100644\r
486 index 0000000..2ff42b3\r
487 --- /dev/null\r
488 +++ b/util/Makefile.local\r
489 @@ -0,0 +1,11 @@\r
490 +# -*- makefile -*-\r
491 +\r
492 +dir :=3D util\r
493 +extra_cflags +=3D -I$(srcdir)/$(dir)\r
494 +\r
495 +libutil_c_srcs :=3D $(dir)/xutil.c $(dir)/error_util.c\r
496 +\r
497 +libutil_modules :=3D $(libutil_c_srcs:.c=3D.o)\r
498 +\r
499 +$(dir)/libutil.a: $(libutil_modules)\r
500 +       $(call quiet,AR) rcs $@ $^\r
501 diff --git a/util/error_util.c b/util/error_util.c\r
502 new file mode 100644\r
503 index 0000000..630d228\r
504 --- /dev/null\r
505 +++ b/util/error_util.c\r
506 @@ -0,0 +1,41 @@\r
507 +/* error_util.c - internal error utilities for notmuch.\r
508 + *\r
509 + * Copyright =C2=A9 2009 Carl Worth\r
510 + *\r
511 + * This program is free software: you can redistribute it and/or modify\r
512 + * it under the terms of the GNU General Public License as published by\r
513 + * the Free Software Foundation, either version 3 of the License, or\r
514 + * (at your option) any later version.\r
515 + *\r
516 + * This program is distributed in the hope that it will be useful,\r
517 + * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
518 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
519 + * GNU General Public License for more details.\r
520 + *\r
521 + * You should have received a copy of the GNU General Public License\r
522 + * along with this program.  If not, see http://www.gnu.org/licenses/ .\r
523 + *\r
524 + * Author: Carl Worth <cworth@cworth.org>\r
525 + */\r
526 +\r
527 +#include <stdlib.h>\r
528 +#include <stdarg.h>\r
529 +#include <stdio.h>\r
530 +\r
531 +#include "error_util.h"\r
532 +\r
533 +int\r
534 +_internal_error (const char *format, ...)\r
535 +{\r
536 +    va_list va_args;\r
537 +\r
538 +    va_start (va_args, format);\r
539 +\r
540 +    fprintf (stderr, "Internal error: ");\r
541 +    vfprintf (stderr, format, va_args);\r
542 +\r
543 +    exit (1);\r
544 +\r
545 +    return 1;\r
546 +}\r
547 +\r
548 diff --git a/util/error_util.h b/util/error_util.h\r
549 new file mode 100644\r
550 index 0000000..0f1e5ef\r
551 --- /dev/null\r
552 +++ b/util/error_util.h\r
553 @@ -0,0 +1,45 @@\r
554 +/* error_util.h - Internal interfaces for notmuch.\r
555 + *\r
556 + * Copyright =C2=A9 2009 Carl Worth\r
557 + *\r
558 + * This program is free software: you can redistribute it and/or modify\r
559 + * it under the terms of the GNU General Public License as published by\r
560 + * the Free Software Foundation, either version 3 of the License, or\r
561 + * (at your option) any later version.\r
562 + *\r
563 + * This program is distributed in the hope that it will be useful,\r
564 + * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
565 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
566 + * GNU General Public License for more details.\r
567 + *\r
568 + * You should have received a copy of the GNU General Public License\r
569 + * along with this program.  If not, see http://www.gnu.org/licenses/ .\r
570 + *\r
571 + * Author: Carl Worth <cworth@cworth.org>\r
572 + */\r
573 +\r
574 +#ifndef ERROR_UTIL_H\r
575 +#define ERROR_UTIL_H\r
576 +\r
577 +#include <talloc.h>\r
578 +\r
579 +/* There's no point in continuing when we've detected that we've done\r
580 + * something wrong internally (as opposed to the user passing in a\r
581 + * bogus value).\r
582 + *\r
583 + * Note that PRINTF_ATTRIBUTE comes from talloc.h\r
584 + */\r
585 +int\r
586 +_internal_error (const char *format, ...) PRINTF_ATTRIBUTE (1, 2);\r
587 +\r
588 +/* There's no point in continuing when we've detected that we've done\r
589 + * something wrong internally (as opposed to the user passing in a\r
590 + * bogus value).\r
591 + *\r
592 + * Note that __location__ comes from talloc.h.\r
593 + */\r
594 +#define INTERNAL_ERROR(format, ...)                    \\r
595 +    _internal_error (format " (%s).\n",                        \\r
596 +                    ##__VA_ARGS__, __location__)\r
597 +\r
598 +#endif\r
599 diff --git a/util/xutil.c b/util/xutil.c\r
600 new file mode 100644\r
601 index 0000000..15ff765\r
602 --- /dev/null\r
603 +++ b/util/xutil.c\r
604 @@ -0,0 +1,136 @@\r
605 +/* xutil.c - Various wrapper functions to abort on error.\r
606 + *\r
607 + * Copyright =C2=A9 2009 Carl Worth\r
608 + *\r
609 + * This program is free software: you can redistribute it and/or modify\r
610 + * it under the terms of the GNU General Public License as published by\r
611 + * the Free Software Foundation, either version 3 of the License, or\r
612 + * (at your option) any later version.\r
613 + *\r
614 + * This program is distributed in the hope that it will be useful,\r
615 + * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
616 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
617 + * GNU General Public License for more details.\r
618 + *\r
619 + * You should have received a copy of the GNU General Public License\r
620 + * along with this program.  If not, see http://www.gnu.org/licenses/ .\r
621 + *\r
622 + * Author: Carl Worth <cworth@cworth.org>\r
623 + */\r
624 +\r
625 +#include <stdio.h>\r
626 +#include <string.h>\r
627 +\r
628 +#include "xutil.h"\r
629 +#include "error_util.h"\r
630 +\r
631 +void *\r
632 +xcalloc (size_t nmemb, size_t size)\r
633 +{\r
634 +    void *ret;\r
635 +\r
636 +    ret =3D calloc (nmemb, size);\r
637 +    if (ret =3D=3D NULL) {\r
638 +       fprintf (stderr, "Out of memory.\n");\r
639 +       exit (1);\r
640 +    }\r
641 +\r
642 +    return ret;\r
643 +}\r
644 +\r
645 +void *\r
646 +xmalloc (size_t size)\r
647 +{\r
648 +    void *ret;\r
649 +\r
650 +    ret =3D malloc (size);\r
651 +    if (ret =3D=3D NULL) {\r
652 +       fprintf (stderr, "Out of memory.\n");\r
653 +       exit (1);\r
654 +    }\r
655 +\r
656 +    return ret;\r
657 +}\r
658 +\r
659 +void *\r
660 +xrealloc (void *ptr, size_t size)\r
661 +{\r
662 +    void *ret;\r
663 +\r
664 +    ret =3D realloc (ptr, size);\r
665 +    if (ret =3D=3D NULL) {\r
666 +       fprintf (stderr, "Out of memory.\n");\r
667 +       exit (1);\r
668 +    }\r
669 +\r
670 +    return ret;\r
671 +}\r
672 +\r
673 +char *\r
674 +xstrdup (const char *s)\r
675 +{\r
676 +    char *ret;\r
677 +\r
678 +    ret =3D strdup (s);\r
679 +    if (ret =3D=3D NULL) {\r
680 +       fprintf (stderr, "Out of memory.\n");\r
681 +       exit (1);\r
682 +    }\r
683 +\r
684 +    return ret;\r
685 +}\r
686 +\r
687 +char *\r
688 +xstrndup (const char *s, size_t n)\r
689 +{\r
690 +    char *ret;\r
691 +\r
692 +    if (strlen (s) <=3D n)\r
693 +       n =3D strlen (s);\r
694 +\r
695 +    ret =3D malloc (n + 1);\r
696 +    if (ret =3D=3D NULL) {\r
697 +       fprintf (stderr, "Out of memory.\n");\r
698 +       exit (1);\r
699 +    }\r
700 +    memcpy (ret, s, n);\r
701 +    ret[n] =3D '\0';\r
702 +\r
703 +    return ret;\r
704 +}\r
705 +\r
706 +void\r
707 +xregcomp (regex_t *preg, const char *regex, int cflags)\r
708 +{\r
709 +    int rerr;\r
710 +\r
711 +    rerr =3D regcomp (preg, regex, cflags);\r
712 +    if (rerr) {\r
713 +       size_t error_size =3D regerror (rerr, preg, NULL, 0);\r
714 +       char *error =3D xmalloc (error_size);\r
715 +\r
716 +       regerror (rerr, preg, error, error_size);\r
717 +       INTERNAL_ERROR ("compiling regex %s: %s\n",\r
718 +                       regex, error);\r
719 +    }\r
720 +}\r
721 +\r
722 +int\r
723 +xregexec (const regex_t *preg, const char *string,\r
724 +         size_t nmatch, regmatch_t pmatch[], int eflags)\r
725 +{\r
726 +    unsigned int i;\r
727 +    int rerr;\r
728 +\r
729 +    rerr =3D regexec (preg, string, nmatch, pmatch, eflags);\r
730 +    if (rerr)\r
731 +       return rerr;\r
732 +\r
733 +    for (i =3D 0; i < nmatch; i++) {\r
734 +       if (pmatch[i].rm_so =3D=3D -1)\r
735 +           INTERNAL_ERROR ("matching regex against %s: Sub-match %d not found\n",\r
736 +                           string, i);\r
737 +    }\r
738 +\r
739 +    return 0;\r
740 +}\r
741 diff --git a/util/xutil.h b/util/xutil.h\r
742 new file mode 100644\r
743 index 0000000..fd77f73\r
744 --- /dev/null\r
745 +++ b/util/xutil.h\r
746 @@ -0,0 +1,55 @@\r
747 +/* xutil.h - Various wrapper functions to abort on error.\r
748 + *\r
749 + * Copyright =C2=A9 2009 Carl Worth\r
750 + *\r
751 + * This program is free software: you can redistribute it and/or modify\r
752 + * it under the terms of the GNU General Public License as published by\r
753 + * the Free Software Foundation, either version 3 of the License, or\r
754 + * (at your option) any later version.\r
755 + *\r
756 + * This program is distributed in the hope that it will be useful,\r
757 + * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
758 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
759 + * GNU General Public License for more details.\r
760 + *\r
761 + * You should have received a copy of the GNU General Public License\r
762 + * along with this program.  If not, see http://www.gnu.org/licenses/ .\r
763 + *\r
764 + * Author: Carl Worth <cworth@cworth.org>\r
765 + */\r
766 +\r
767 +#ifndef NOTMUCH_XUTIL_H\r
768 +#define NOTMUCH_XUTIL_H\r
769 +\r
770 +#include <stdlib.h>\r
771 +#include <sys/types.h>\r
772 +#include <regex.h>\r
773 +\r
774 +#pragma GCC visibility push(hidden)\r
775 +\r
776 +/* xutil.c */\r
777 +void *\r
778 +xcalloc (size_t nmemb, size_t size);\r
779 +\r
780 +void *\r
781 +xmalloc (size_t size);\r
782 +\r
783 +void *\r
784 +xrealloc (void *ptrr, size_t size);\r
785 +\r
786 +char *\r
787 +xstrdup (const char *s);\r
788 +\r
789 +char *\r
790 +xstrndup (const char *s, size_t n);\r
791 +\r
792 +void\r
793 +xregcomp (regex_t *preg, const char *regex, int cflags);\r
794 +\r
795 +int\r
796 +xregexec (const regex_t *preg, const char *string,\r
797 +         size_t nmatch, regmatch_t pmatch[], int eflags);\r
798 +\r
799 +#pragma GCC visibility pop\r
800 +\r
801 +#endif\r
802 diff --git a/xutil.c b/xutil.c\r
803 deleted file mode 100644\r
804 index 5f98f3f..0000000\r
805 --- a/xutil.c\r
806 +++ /dev/null\r
807 @@ -1,138 +0,0 @@\r
808 -/* xutil.c - Various wrapper functions to abort on error.\r
809 - *\r
810 - * Copyright =C2=A9 2009 Carl Worth\r
811 - *\r
812 - * This program is free software: you can redistribute it and/or modify\r
813 - * it under the terms of the GNU General Public License as published by\r
814 - * the Free Software Foundation, either version 3 of the License, or\r
815 - * (at your option) any later version.\r
816 - *\r
817 - * This program is distributed in the hope that it will be useful,\r
818 - * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
819 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
820 - * GNU General Public License for more details.\r
821 - *\r
822 - * You should have received a copy of the GNU General Public License\r
823 - * along with this program.  If not, see http://www.gnu.org/licenses/ .\r
824 - *\r
825 - * Author: Carl Worth <cworth@cworth.org>\r
826 - */\r
827 -\r
828 -#include "notmuch-private.h"\r
829 -\r
830 -#include <stdio.h>\r
831 -\r
832 -void *\r
833 -xcalloc (size_t nmemb, size_t size)\r
834 -{\r
835 -    void *ret;\r
836 -\r
837 -    ret =3D calloc (nmemb, size);\r
838 -    if (ret =3D=3D NULL) {\r
839 -       fprintf (stderr, "Out of memory.\n");\r
840 -       exit (1);\r
841 -    }\r
842 -\r
843 -    return ret;\r
844 -}\r
845 -\r
846 -void *\r
847 -xmalloc (size_t size)\r
848 -{\r
849 -    void *ret;\r
850 -\r
851 -    ret =3D malloc (size);\r
852 -    if (ret =3D=3D NULL) {\r
853 -       fprintf (stderr, "Out of memory.\n");\r
854 -       exit (1);\r
855 -    }\r
856 -\r
857 -    return ret;\r
858 -}\r
859 -\r
860 -void *\r
861 -xrealloc (void *ptr, size_t size)\r
862 -{\r
863 -    void *ret;\r
864 -\r
865 -    ret =3D realloc (ptr, size);\r
866 -    if (ret =3D=3D NULL) {\r
867 -       fprintf (stderr, "Out of memory.\n");\r
868 -       exit (1);\r
869 -    }\r
870 -\r
871 -    return ret;\r
872 -}\r
873 -\r
874 -char *\r
875 -xstrdup (const char *s)\r
876 -{\r
877 -    char *ret;\r
878 -\r
879 -    ret =3D strdup (s);\r
880 -    if (ret =3D=3D NULL) {\r
881 -       fprintf (stderr, "Out of memory.\n");\r
882 -       exit (1);\r
883 -    }\r
884 -\r
885 -    return ret;\r
886 -}\r
887 -\r
888 -char *\r
889 -xstrndup (const char *s, size_t n)\r
890 -{\r
891 -    char *ret;\r
892 -\r
893 -    if (strlen (s) <=3D n)\r
894 -       n =3D strlen (s);\r
895 -\r
896 -    ret =3D malloc (n + 1);\r
897 -    if (ret =3D=3D NULL) {\r
898 -       fprintf (stderr, "Out of memory.\n");\r
899 -       exit (1);\r
900 -    }\r
901 -    memcpy (ret, s, n);\r
902 -    ret[n] =3D '\0';\r
903 -\r
904 -    return ret;\r
905 -}\r
906 -\r
907 -void\r
908 -xregcomp (regex_t *preg, const char *regex, int cflags)\r
909 -{\r
910 -    int rerr;\r
911 -\r
912 -    rerr =3D regcomp (preg, regex, cflags);\r
913 -    if (rerr) {\r
914 -       size_t error_size =3D regerror (rerr, preg, NULL, 0);\r
915 -       char *error =3D xmalloc (error_size);\r
916 -\r
917 -       regerror (rerr, preg, error, error_size);\r
918 -       fprintf (stderr, "Internal error: compiling regex %s: %s\n",\r
919 -                regex, error);\r
920 -       exit (1);\r
921 -    }\r
922 -}\r
923 -\r
924 -int\r
925 -xregexec (const regex_t *preg, const char *string,\r
926 -         size_t nmatch, regmatch_t pmatch[], int eflags)\r
927 -{\r
928 -    unsigned int i;\r
929 -    int rerr;\r
930 -\r
931 -    rerr =3D regexec (preg, string, nmatch, pmatch, eflags);\r
932 -    if (rerr)\r
933 -       return rerr;\r
934 -\r
935 -    for (i =3D 0; i < nmatch; i++) {\r
936 -       if (pmatch[i].rm_so =3D=3D -1) {\r
937 -           fprintf (stderr, "Internal error: matching regex against %s:"\r
938 -                    "Sub-match %d not found\n",\r
939 -                    string, i);\r
940 -           exit (1);\r
941 -       }\r
942 -    }\r
943 -\r
944 -    return 0;\r
945 -}\r
946 --=20\r
947 1.7.6.3\r
948 \r
949 \r
950 --=-=-=--\r