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
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
42 Content-Type: multipart/mixed; boundary="=-=-="
\r
43 X-BeenThere: notmuch@notmuchmail.org
\r
44 X-Mailman-Version: 2.1.13
\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
58 Content-Type: multipart/signed; boundary="==-=-=";
\r
59 micalg=pgp-sha1; protocol="application/pgp-signature"
\r
62 Content-Transfer-Encoding: quoted-printable
\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
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
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
79 Content-Type: application/pgp-signature
\r
81 -----BEGIN PGP SIGNATURE-----
\r
82 Version: GnuPG v1.4.11 (GNU/Linux)
\r
84 iJwEAQECAAYFAk6sS2kACgkQTiiN/0Um85lD5AP9F3/wFn9mhV2s21RY5pkFylGo
\r
85 ZdxDa6IWnCYvuCSHgYu6cbYS2Ttimls2gXJIw9p3hVADSWQ5WXNFykG1cLk7EHB7
\r
86 lEGdU3nhRHmj9yX3VD4sLX9moozVVz2+aQBvcywFU+AWS15p09ZSde2APAmhSBTh
\r
87 HnmxCtkC+kk5Rw7Nm/Q=
\r
89 -----END PGP SIGNATURE-----
\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
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
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
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
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
124 util/xutil.h | 55 +++++++++++++++++++
\r
125 xutil.c | 138 ---------------------------------------------=
\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
138 diff --git a/Makefile b/Makefile
\r
139 index 11e3a3d..2fb2a61 100644
\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
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
176 notmuch_client_modules =3D $(notmuch_client_srcs:.c=3D.o)
\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
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
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
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
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
217 -_internal_error (const char *format, ...)
\r
221 - va_start (va_args, format);
\r
223 - fprintf (stderr, "Internal error: ");
\r
224 - vfprintf (stderr, format, va_args);
\r
232 _find_prefix (const char *name)
\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
242 +#include "error_util.h"
\r
244 #pragma GCC visibility push(hidden)
\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
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
254 - * Note that PRINTF_ATTRIBUTE comes from talloc.h
\r
257 -_internal_error (const char *format, ...) PRINTF_ATTRIBUTE (1, 2);
\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
263 - * Note that __location__ comes from talloc.h.
\r
265 -#define INTERNAL_ERROR(format, ...) \
\r
266 - _internal_error (format " (%s).\n", \
\r
267 - ##__VA_ARGS__, __location__)
\r
269 #define unused(x) x __attribute__ ((unused))
\r
272 diff --git a/lib/xutil.c b/lib/xutil.c
\r
273 deleted file mode 100644
\r
274 index 268225b..0000000
\r
278 -/* xutil.c - Various wrapper functions to abort on error.
\r
280 - * Copyright =C2=A9 2009 Carl Worth
\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
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
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
295 - * Author: Carl Worth <cworth@cworth.org>
\r
298 -#include "notmuch-private.h"
\r
300 -#include <stdio.h>
\r
303 -xcalloc (size_t nmemb, size_t size)
\r
307 - ret =3D calloc (nmemb, size);
\r
308 - if (ret =3D=3D NULL) {
\r
309 - fprintf (stderr, "Out of memory.\n");
\r
317 -xmalloc (size_t size)
\r
321 - ret =3D malloc (size);
\r
322 - if (ret =3D=3D NULL) {
\r
323 - fprintf (stderr, "Out of memory.\n");
\r
331 -xrealloc (void *ptr, size_t size)
\r
335 - ret =3D realloc (ptr, size);
\r
336 - if (ret =3D=3D NULL) {
\r
337 - fprintf (stderr, "Out of memory.\n");
\r
345 -xstrdup (const char *s)
\r
349 - ret =3D strdup (s);
\r
350 - if (ret =3D=3D NULL) {
\r
351 - fprintf (stderr, "Out of memory.\n");
\r
359 -xstrndup (const char *s, size_t n)
\r
363 - if (strlen (s) <=3D n)
\r
364 - n =3D strlen (s);
\r
366 - ret =3D malloc (n + 1);
\r
367 - if (ret =3D=3D NULL) {
\r
368 - fprintf (stderr, "Out of memory.\n");
\r
371 - memcpy (ret, s, n);
\r
378 -xregcomp (regex_t *preg, const char *regex, int cflags)
\r
382 - rerr =3D regcomp (preg, regex, cflags);
\r
384 - size_t error_size =3D regerror (rerr, preg, NULL, 0);
\r
385 - char *error =3D xmalloc (error_size);
\r
387 - regerror (rerr, preg, error, error_size);
\r
388 - INTERNAL_ERROR ("compiling regex %s: %s\n",
\r
394 -xregexec (const regex_t *preg, const char *string,
\r
395 - size_t nmatch, regmatch_t pmatch[], int eflags)
\r
400 - rerr =3D regexec (preg, string, nmatch, pmatch, eflags);
\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
412 diff --git a/lib/xutil.h b/lib/xutil.h
\r
413 deleted file mode 100644
\r
414 index fd77f73..0000000
\r
418 -/* xutil.h - Various wrapper functions to abort on error.
\r
420 - * Copyright =C2=A9 2009 Carl Worth
\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
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
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
435 - * Author: Carl Worth <cworth@cworth.org>
\r
438 -#ifndef NOTMUCH_XUTIL_H
\r
439 -#define NOTMUCH_XUTIL_H
\r
441 -#include <stdlib.h>
\r
442 -#include <sys/types.h>
\r
443 -#include <regex.h>
\r
445 -#pragma GCC visibility push(hidden)
\r
449 -xcalloc (size_t nmemb, size_t size);
\r
452 -xmalloc (size_t size);
\r
455 -xrealloc (void *ptrr, size_t size);
\r
458 -xstrdup (const char *s);
\r
461 -xstrndup (const char *s, size_t n);
\r
464 -xregcomp (regex_t *preg, const char *regex, int cflags);
\r
467 -xregexec (const regex_t *preg, const char *string,
\r
468 - size_t nmatch, regmatch_t pmatch[], int eflags);
\r
470 -#pragma GCC visibility pop
\r
473 diff --git a/util/Makefile b/util/Makefile
\r
474 new file mode 100644
\r
475 index 0000000..fa25832
\r
477 +++ b/util/Makefile
\r
480 + $(MAKE) -C .. all
\r
484 diff --git a/util/Makefile.local b/util/Makefile.local
\r
485 new file mode 100644
\r
486 index 0000000..2ff42b3
\r
488 +++ b/util/Makefile.local
\r
490 +# -*- makefile -*-
\r
493 +extra_cflags +=3D -I$(srcdir)/$(dir)
\r
495 +libutil_c_srcs :=3D $(dir)/xutil.c $(dir)/error_util.c
\r
497 +libutil_modules :=3D $(libutil_c_srcs:.c=3D.o)
\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
505 +++ b/util/error_util.c
\r
507 +/* error_util.c - internal error utilities for notmuch.
\r
509 + * Copyright =C2=A9 2009 Carl Worth
\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
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
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
524 + * Author: Carl Worth <cworth@cworth.org>
\r
527 +#include <stdlib.h>
\r
528 +#include <stdarg.h>
\r
529 +#include <stdio.h>
\r
531 +#include "error_util.h"
\r
534 +_internal_error (const char *format, ...)
\r
538 + va_start (va_args, format);
\r
540 + fprintf (stderr, "Internal error: ");
\r
541 + vfprintf (stderr, format, va_args);
\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
552 +++ b/util/error_util.h
\r
554 +/* error_util.h - Internal interfaces for notmuch.
\r
556 + * Copyright =C2=A9 2009 Carl Worth
\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
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
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
571 + * Author: Carl Worth <cworth@cworth.org>
\r
574 +#ifndef ERROR_UTIL_H
\r
575 +#define ERROR_UTIL_H
\r
577 +#include <talloc.h>
\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
583 + * Note that PRINTF_ATTRIBUTE comes from talloc.h
\r
586 +_internal_error (const char *format, ...) PRINTF_ATTRIBUTE (1, 2);
\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
592 + * Note that __location__ comes from talloc.h.
\r
594 +#define INTERNAL_ERROR(format, ...) \
\r
595 + _internal_error (format " (%s).\n", \
\r
596 + ##__VA_ARGS__, __location__)
\r
599 diff --git a/util/xutil.c b/util/xutil.c
\r
600 new file mode 100644
\r
601 index 0000000..15ff765
\r
605 +/* xutil.c - Various wrapper functions to abort on error.
\r
607 + * Copyright =C2=A9 2009 Carl Worth
\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
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
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
622 + * Author: Carl Worth <cworth@cworth.org>
\r
625 +#include <stdio.h>
\r
626 +#include <string.h>
\r
628 +#include "xutil.h"
\r
629 +#include "error_util.h"
\r
632 +xcalloc (size_t nmemb, size_t size)
\r
636 + ret =3D calloc (nmemb, size);
\r
637 + if (ret =3D=3D NULL) {
\r
638 + fprintf (stderr, "Out of memory.\n");
\r
646 +xmalloc (size_t size)
\r
650 + ret =3D malloc (size);
\r
651 + if (ret =3D=3D NULL) {
\r
652 + fprintf (stderr, "Out of memory.\n");
\r
660 +xrealloc (void *ptr, size_t size)
\r
664 + ret =3D realloc (ptr, size);
\r
665 + if (ret =3D=3D NULL) {
\r
666 + fprintf (stderr, "Out of memory.\n");
\r
674 +xstrdup (const char *s)
\r
678 + ret =3D strdup (s);
\r
679 + if (ret =3D=3D NULL) {
\r
680 + fprintf (stderr, "Out of memory.\n");
\r
688 +xstrndup (const char *s, size_t n)
\r
692 + if (strlen (s) <=3D n)
\r
693 + n =3D strlen (s);
\r
695 + ret =3D malloc (n + 1);
\r
696 + if (ret =3D=3D NULL) {
\r
697 + fprintf (stderr, "Out of memory.\n");
\r
700 + memcpy (ret, s, n);
\r
707 +xregcomp (regex_t *preg, const char *regex, int cflags)
\r
711 + rerr =3D regcomp (preg, regex, cflags);
\r
713 + size_t error_size =3D regerror (rerr, preg, NULL, 0);
\r
714 + char *error =3D xmalloc (error_size);
\r
716 + regerror (rerr, preg, error, error_size);
\r
717 + INTERNAL_ERROR ("compiling regex %s: %s\n",
\r
723 +xregexec (const regex_t *preg, const char *string,
\r
724 + size_t nmatch, regmatch_t pmatch[], int eflags)
\r
729 + rerr =3D regexec (preg, string, nmatch, pmatch, eflags);
\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
741 diff --git a/util/xutil.h b/util/xutil.h
\r
742 new file mode 100644
\r
743 index 0000000..fd77f73
\r
747 +/* xutil.h - Various wrapper functions to abort on error.
\r
749 + * Copyright =C2=A9 2009 Carl Worth
\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
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
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
764 + * Author: Carl Worth <cworth@cworth.org>
\r
767 +#ifndef NOTMUCH_XUTIL_H
\r
768 +#define NOTMUCH_XUTIL_H
\r
770 +#include <stdlib.h>
\r
771 +#include <sys/types.h>
\r
772 +#include <regex.h>
\r
774 +#pragma GCC visibility push(hidden)
\r
778 +xcalloc (size_t nmemb, size_t size);
\r
781 +xmalloc (size_t size);
\r
784 +xrealloc (void *ptrr, size_t size);
\r
787 +xstrdup (const char *s);
\r
790 +xstrndup (const char *s, size_t n);
\r
793 +xregcomp (regex_t *preg, const char *regex, int cflags);
\r
796 +xregexec (const regex_t *preg, const char *string,
\r
797 + size_t nmatch, regmatch_t pmatch[], int eflags);
\r
799 +#pragma GCC visibility pop
\r
802 diff --git a/xutil.c b/xutil.c
\r
803 deleted file mode 100644
\r
804 index 5f98f3f..0000000
\r
808 -/* xutil.c - Various wrapper functions to abort on error.
\r
810 - * Copyright =C2=A9 2009 Carl Worth
\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
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
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
825 - * Author: Carl Worth <cworth@cworth.org>
\r
828 -#include "notmuch-private.h"
\r
830 -#include <stdio.h>
\r
833 -xcalloc (size_t nmemb, size_t size)
\r
837 - ret =3D calloc (nmemb, size);
\r
838 - if (ret =3D=3D NULL) {
\r
839 - fprintf (stderr, "Out of memory.\n");
\r
847 -xmalloc (size_t size)
\r
851 - ret =3D malloc (size);
\r
852 - if (ret =3D=3D NULL) {
\r
853 - fprintf (stderr, "Out of memory.\n");
\r
861 -xrealloc (void *ptr, size_t size)
\r
865 - ret =3D realloc (ptr, size);
\r
866 - if (ret =3D=3D NULL) {
\r
867 - fprintf (stderr, "Out of memory.\n");
\r
875 -xstrdup (const char *s)
\r
879 - ret =3D strdup (s);
\r
880 - if (ret =3D=3D NULL) {
\r
881 - fprintf (stderr, "Out of memory.\n");
\r
889 -xstrndup (const char *s, size_t n)
\r
893 - if (strlen (s) <=3D n)
\r
894 - n =3D strlen (s);
\r
896 - ret =3D malloc (n + 1);
\r
897 - if (ret =3D=3D NULL) {
\r
898 - fprintf (stderr, "Out of memory.\n");
\r
901 - memcpy (ret, s, n);
\r
908 -xregcomp (regex_t *preg, const char *regex, int cflags)
\r
912 - rerr =3D regcomp (preg, regex, cflags);
\r
914 - size_t error_size =3D regerror (rerr, preg, NULL, 0);
\r
915 - char *error =3D xmalloc (error_size);
\r
917 - regerror (rerr, preg, error, error_size);
\r
918 - fprintf (stderr, "Internal error: compiling regex %s: %s\n",
\r
925 -xregexec (const regex_t *preg, const char *string,
\r
926 - size_t nmatch, regmatch_t pmatch[], int eflags)
\r
931 - rerr =3D regexec (preg, string, nmatch, pmatch, eflags);
\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