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 69F2F431FD0
\r
6 for <notmuch@notmuchmail.org>; Sun, 23 Oct 2011 08:19:09 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\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 jAMzopR-sJUp for <notmuch@notmuchmail.org>;
\r
16 Sun, 23 Oct 2011 08:19:07 -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 A86DC431FB6
\r
21 for <notmuch@notmuchmail.org>; Sun, 23 Oct 2011 08:19:07 -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 p9NFJ0iS008916
\r
26 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO);
\r
27 Sun, 23 Oct 2011 12:19:02 -0300
\r
28 Received: from bremner by zancas.localnet with local (Exim 4.76)
\r
29 (envelope-from <bremner@tethera.net>)
\r
30 id 1RHzpD-0002sY-NH; Sun, 23 Oct 2011 12:18:59 -0300
\r
31 From: David Bremner <david@tethera.net>
\r
32 To: notmuch@notmuchmail.org
\r
33 Subject: [PATCH] xutil.c: remove duplicate copies, create new library libutil.a to contain xutil.
\r
34 Date: Sun, 23 Oct 2011 12:18:53 -0300
\r
35 Message-Id: <1319383133-11006-1-git-send-email-david@tethera.net>
\r
36 X-Mailer: git-send-email 1.7.6.3
\r
38 Content-Type: text/plain; charset=UTF-8
\r
39 Content-Transfer-Encoding: 8bit
\r
40 Cc: David Bremner <bremner@debian.org>
\r
41 X-BeenThere: notmuch@notmuchmail.org
\r
42 X-Mailman-Version: 2.1.13
\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 15:19:09 -0000
\r
55 From: David Bremner <bremner@debian.org>
\r
57 We keep the lib/xutil.c version. As a consequence, also factor out
\r
58 _internal_error and associated macros. It might be overkill to make a
\r
59 new file error_util.c for this, but _internal_error does not really
\r
60 belong in database.cc.
\r
63 This turned out to be more disruptive than I thought. On the other
\r
64 hand, having two copies of xutil.c seems like a recipe for disaster.
\r
65 I wanted to factor out the logic in xregcomp so I could use it in
\r
66 situations where miscompilation is not an internal error, but more
\r
67 likely a user error.
\r
70 Makefile.local | 7 +--
\r
71 lib/Makefile.local | 5 +-
\r
72 lib/database.cc | 15 -----
\r
73 lib/notmuch-private.h | 20 +-------
\r
74 lib/xutil.c | 134 -----------------------------------------------
\r
75 lib/xutil.h | 55 -------------------
\r
76 util/Makefile | 5 ++
\r
77 util/Makefile.local | 11 ++++
\r
78 util/error_util.c | 41 +++++++++++++++
\r
79 util/error_util.h | 45 ++++++++++++++++
\r
80 util/xutil.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++++
\r
81 util/xutil.h | 55 +++++++++++++++++++
\r
82 xutil.c | 138 -------------------------------------------------
\r
83 14 files changed, 300 insertions(+), 369 deletions(-)
\r
84 delete mode 100644 lib/xutil.c
\r
85 delete mode 100644 lib/xutil.h
\r
86 create mode 100644 util/Makefile
\r
87 create mode 100644 util/Makefile.local
\r
88 create mode 100644 util/error_util.c
\r
89 create mode 100644 util/error_util.h
\r
90 create mode 100644 util/xutil.c
\r
91 create mode 100644 util/xutil.h
\r
92 delete mode 100644 xutil.c
\r
94 diff --git a/Makefile b/Makefile
\r
95 index 11e3a3d..2fb2a61 100644
\r
101 # List all subdirectories here. Each contains its own Makefile.local
\r
102 -subdirs = compat completion emacs lib test
\r
103 +subdirs = compat completion emacs lib util test
\r
105 # We make all targets depend on the Makefiles themselves.
\r
106 global_deps = Makefile Makefile.config Makefile.local \
\r
107 diff --git a/Makefile.local b/Makefile.local
\r
108 index 38f6c17..e31defa 100644
\r
109 --- a/Makefile.local
\r
110 +++ b/Makefile.local
\r
111 @@ -39,7 +39,7 @@ PV_FILE=bindings/python/notmuch/version.py
\r
112 # Smash together user's values with our extra values
\r
113 FINAL_CFLAGS = -DNOTMUCH_VERSION=$(VERSION) $(CFLAGS) $(WARN_CFLAGS) $(CONFIGURE_CFLAGS) $(extra_cflags)
\r
114 FINAL_CXXFLAGS = $(CXXFLAGS) $(WARN_CXXFLAGS) $(CONFIGURE_CXXFLAGS) $(extra_cflags) $(extra_cxxflags)
\r
115 -FINAL_NOTMUCH_LDFLAGS = $(LDFLAGS) -Llib -lnotmuch $(AS_NEEDED_LDFLAGS) $(GMIME_LDFLAGS) $(TALLOC_LDFLAGS)
\r
116 +FINAL_NOTMUCH_LDFLAGS = $(LDFLAGS) -Lutil -lutil -Llib -lnotmuch $(AS_NEEDED_LDFLAGS) $(GMIME_LDFLAGS) $(TALLOC_LDFLAGS)
\r
117 FINAL_NOTMUCH_LINKER = CC
\r
118 ifneq ($(LINKER_RESOLVES_LIBRARY_DEPENDENCIES),1)
\r
119 FINAL_NOTMUCH_LDFLAGS += $(CONFIGURE_LDFLAGS)
\r
120 @@ -288,12 +288,11 @@ notmuch_client_srcs = \
\r
128 notmuch_client_modules = $(notmuch_client_srcs:.c=.o)
\r
130 -notmuch: $(notmuch_client_modules) lib/libnotmuch.a
\r
131 +notmuch: $(notmuch_client_modules) lib/libnotmuch.a util/libutil.a
\r
132 $(call quiet,CXX $(CFLAGS)) $^ $(FINAL_LIBNOTMUCH_LDFLAGS) -o $@
\r
134 notmuch-shared: $(notmuch_client_modules) lib/$(LINKER_NAME)
\r
135 diff --git a/lib/Makefile.local b/lib/Makefile.local
\r
136 index ea20b2b..f148661 100644
\r
137 --- a/lib/Makefile.local
\r
138 +++ b/lib/Makefile.local
\r
139 @@ -49,8 +49,7 @@ libnotmuch_c_srcs = \
\r
140 $(dir)/message-file.c \
\r
141 $(dir)/messages.c \
\r
147 libnotmuch_cxx_srcs = \
\r
148 $(dir)/database.cc \
\r
149 @@ -66,7 +65,7 @@ $(dir)/libnotmuch.a: $(libnotmuch_modules)
\r
150 $(call quiet,AR) rcs $@ $^
\r
152 $(dir)/$(LIBNAME): $(libnotmuch_modules) notmuch.sym
\r
153 - $(call quiet,CXX $(CXXFLAGS)) $(libnotmuch_modules) $(FINAL_LIBNOTMUCH_LDFLAGS) $(LIBRARY_LINK_FLAG) -o $@
\r
154 + $(call quiet,CXX $(CXXFLAGS)) $(libnotmuch_modules) $(FINAL_LIBNOTMUCH_LDFLAGS) $(LIBRARY_LINK_FLAG) -o $@ -L$(srcdir)/util -lutil
\r
156 notmuch.sym: lib/notmuch.h $(libnotmuch_modules)
\r
157 sh lib/gen-version-script.sh $< $(libnotmuch_modules) > $@
\r
158 diff --git a/lib/database.cc b/lib/database.cc
\r
159 index e77fd53..88be939 100644
\r
160 --- a/lib/database.cc
\r
161 +++ b/lib/database.cc
\r
162 @@ -209,21 +209,6 @@ static prefix_t PROBABILISTIC_PREFIX[]= {
\r
163 { "folder", "XFOLDER"}
\r
167 -_internal_error (const char *format, ...)
\r
171 - va_start (va_args, format);
\r
173 - fprintf (stderr, "Internal error: ");
\r
174 - vfprintf (stderr, format, va_args);
\r
182 _find_prefix (const char *name)
\r
184 diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
\r
185 index d319530..0d3cc27 100644
\r
186 --- a/lib/notmuch-private.h
\r
187 +++ b/lib/notmuch-private.h
\r
188 @@ -47,6 +47,7 @@ NOTMUCH_BEGIN_DECLS
\r
189 #include <talloc.h>
\r
192 +#include "error_util.h"
\r
194 #pragma GCC visibility push(hidden)
\r
196 @@ -60,25 +61,6 @@ NOTMUCH_BEGIN_DECLS
\r
197 #define STRNCMP_LITERAL(var, literal) \
\r
198 strncmp ((var), (literal), sizeof (literal) - 1)
\r
200 -/* There's no point in continuing when we've detected that we've done
\r
201 - * something wrong internally (as opposed to the user passing in a
\r
204 - * Note that PRINTF_ATTRIBUTE comes from talloc.h
\r
207 -_internal_error (const char *format, ...) PRINTF_ATTRIBUTE (1, 2);
\r
209 -/* There's no point in continuing when we've detected that we've done
\r
210 - * something wrong internally (as opposed to the user passing in a
\r
213 - * Note that __location__ comes from talloc.h.
\r
215 -#define INTERNAL_ERROR(format, ...) \
\r
216 - _internal_error (format " (%s).\n", \
\r
217 - ##__VA_ARGS__, __location__)
\r
219 #define unused(x) x __attribute__ ((unused))
\r
222 diff --git a/lib/xutil.c b/lib/xutil.c
\r
223 deleted file mode 100644
\r
224 index 268225b..0000000
\r
225 diff --git a/lib/xutil.h b/lib/xutil.h
\r
226 deleted file mode 100644
\r
227 index fd77f73..0000000
\r
228 diff --git a/util/Makefile b/util/Makefile
\r
229 new file mode 100644
\r
230 index 0000000..fa25832
\r
232 +++ b/util/Makefile
\r
235 + $(MAKE) -C .. all
\r
239 diff --git a/util/Makefile.local b/util/Makefile.local
\r
240 new file mode 100644
\r
241 index 0000000..2ff42b3
\r
243 +++ b/util/Makefile.local
\r
245 +# -*- makefile -*-
\r
248 +extra_cflags += -I$(srcdir)/$(dir)
\r
250 +libutil_c_srcs := $(dir)/xutil.c $(dir)/error_util.c
\r
252 +libutil_modules := $(libutil_c_srcs:.c=.o)
\r
254 +$(dir)/libutil.a: $(libutil_modules)
\r
255 + $(call quiet,AR) rcs $@ $^
\r
256 diff --git a/util/error_util.c b/util/error_util.c
\r
257 new file mode 100644
\r
258 index 0000000..630d228
\r
260 +++ b/util/error_util.c
\r
262 +/* error_util.c - internal error utilities for notmuch.
\r
264 + * Copyright © 2009 Carl Worth
\r
266 + * This program is free software: you can redistribute it and/or modify
\r
267 + * it under the terms of the GNU General Public License as published by
\r
268 + * the Free Software Foundation, either version 3 of the License, or
\r
269 + * (at your option) any later version.
\r
271 + * This program is distributed in the hope that it will be useful,
\r
272 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
273 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
274 + * GNU General Public License for more details.
\r
276 + * You should have received a copy of the GNU General Public License
\r
277 + * along with this program. If not, see http://www.gnu.org/licenses/ .
\r
279 + * Author: Carl Worth <cworth@cworth.org>
\r
282 +#include <stdlib.h>
\r
283 +#include <stdarg.h>
\r
284 +#include <stdio.h>
\r
286 +#include "error_util.h"
\r
289 +_internal_error (const char *format, ...)
\r
293 + va_start (va_args, format);
\r
295 + fprintf (stderr, "Internal error: ");
\r
296 + vfprintf (stderr, format, va_args);
\r
303 diff --git a/util/error_util.h b/util/error_util.h
\r
304 new file mode 100644
\r
305 index 0000000..0f1e5ef
\r
307 +++ b/util/error_util.h
\r
309 +/* error_util.h - Internal interfaces for notmuch.
\r
311 + * Copyright © 2009 Carl Worth
\r
313 + * This program is free software: you can redistribute it and/or modify
\r
314 + * it under the terms of the GNU General Public License as published by
\r
315 + * the Free Software Foundation, either version 3 of the License, or
\r
316 + * (at your option) any later version.
\r
318 + * This program is distributed in the hope that it will be useful,
\r
319 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
320 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
321 + * GNU General Public License for more details.
\r
323 + * You should have received a copy of the GNU General Public License
\r
324 + * along with this program. If not, see http://www.gnu.org/licenses/ .
\r
326 + * Author: Carl Worth <cworth@cworth.org>
\r
329 +#ifndef ERROR_UTIL_H
\r
330 +#define ERROR_UTIL_H
\r
332 +#include <talloc.h>
\r
334 +/* There's no point in continuing when we've detected that we've done
\r
335 + * something wrong internally (as opposed to the user passing in a
\r
338 + * Note that PRINTF_ATTRIBUTE comes from talloc.h
\r
341 +_internal_error (const char *format, ...) PRINTF_ATTRIBUTE (1, 2);
\r
343 +/* There's no point in continuing when we've detected that we've done
\r
344 + * something wrong internally (as opposed to the user passing in a
\r
347 + * Note that __location__ comes from talloc.h.
\r
349 +#define INTERNAL_ERROR(format, ...) \
\r
350 + _internal_error (format " (%s).\n", \
\r
351 + ##__VA_ARGS__, __location__)
\r
354 diff --git a/util/xutil.c b/util/xutil.c
\r
355 new file mode 100644
\r
356 index 0000000..15ff765
\r
360 +/* xutil.c - Various wrapper functions to abort on error.
\r
362 + * Copyright © 2009 Carl Worth
\r
364 + * This program is free software: you can redistribute it and/or modify
\r
365 + * it under the terms of the GNU General Public License as published by
\r
366 + * the Free Software Foundation, either version 3 of the License, or
\r
367 + * (at your option) any later version.
\r
369 + * This program is distributed in the hope that it will be useful,
\r
370 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
371 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
372 + * GNU General Public License for more details.
\r
374 + * You should have received a copy of the GNU General Public License
\r
375 + * along with this program. If not, see http://www.gnu.org/licenses/ .
\r
377 + * Author: Carl Worth <cworth@cworth.org>
\r
380 +#include <stdio.h>
\r
381 +#include <string.h>
\r
383 +#include "xutil.h"
\r
384 +#include "error_util.h"
\r
387 +xcalloc (size_t nmemb, size_t size)
\r
391 + ret = calloc (nmemb, size);
\r
392 + if (ret == NULL) {
\r
393 + fprintf (stderr, "Out of memory.\n");
\r
401 +xmalloc (size_t size)
\r
405 + ret = malloc (size);
\r
406 + if (ret == NULL) {
\r
407 + fprintf (stderr, "Out of memory.\n");
\r
415 +xrealloc (void *ptr, size_t size)
\r
419 + ret = realloc (ptr, size);
\r
420 + if (ret == NULL) {
\r
421 + fprintf (stderr, "Out of memory.\n");
\r
429 +xstrdup (const char *s)
\r
433 + ret = strdup (s);
\r
434 + if (ret == NULL) {
\r
435 + fprintf (stderr, "Out of memory.\n");
\r
443 +xstrndup (const char *s, size_t n)
\r
447 + if (strlen (s) <= n)
\r
450 + ret = malloc (n + 1);
\r
451 + if (ret == NULL) {
\r
452 + fprintf (stderr, "Out of memory.\n");
\r
455 + memcpy (ret, s, n);
\r
462 +xregcomp (regex_t *preg, const char *regex, int cflags)
\r
466 + rerr = regcomp (preg, regex, cflags);
\r
468 + size_t error_size = regerror (rerr, preg, NULL, 0);
\r
469 + char *error = xmalloc (error_size);
\r
471 + regerror (rerr, preg, error, error_size);
\r
472 + INTERNAL_ERROR ("compiling regex %s: %s\n",
\r
478 +xregexec (const regex_t *preg, const char *string,
\r
479 + size_t nmatch, regmatch_t pmatch[], int eflags)
\r
484 + rerr = regexec (preg, string, nmatch, pmatch, eflags);
\r
488 + for (i = 0; i < nmatch; i++) {
\r
489 + if (pmatch[i].rm_so == -1)
\r
490 + INTERNAL_ERROR ("matching regex against %s: Sub-match %d not found\n",
\r
496 diff --git a/util/xutil.h b/util/xutil.h
\r
497 new file mode 100644
\r
498 index 0000000..fd77f73
\r
502 +/* xutil.h - Various wrapper functions to abort on error.
\r
504 + * Copyright © 2009 Carl Worth
\r
506 + * This program is free software: you can redistribute it and/or modify
\r
507 + * it under the terms of the GNU General Public License as published by
\r
508 + * the Free Software Foundation, either version 3 of the License, or
\r
509 + * (at your option) any later version.
\r
511 + * This program is distributed in the hope that it will be useful,
\r
512 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
513 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
514 + * GNU General Public License for more details.
\r
516 + * You should have received a copy of the GNU General Public License
\r
517 + * along with this program. If not, see http://www.gnu.org/licenses/ .
\r
519 + * Author: Carl Worth <cworth@cworth.org>
\r
522 +#ifndef NOTMUCH_XUTIL_H
\r
523 +#define NOTMUCH_XUTIL_H
\r
525 +#include <stdlib.h>
\r
526 +#include <sys/types.h>
\r
527 +#include <regex.h>
\r
529 +#pragma GCC visibility push(hidden)
\r
533 +xcalloc (size_t nmemb, size_t size);
\r
536 +xmalloc (size_t size);
\r
539 +xrealloc (void *ptrr, size_t size);
\r
542 +xstrdup (const char *s);
\r
545 +xstrndup (const char *s, size_t n);
\r
548 +xregcomp (regex_t *preg, const char *regex, int cflags);
\r
551 +xregexec (const regex_t *preg, const char *string,
\r
552 + size_t nmatch, regmatch_t pmatch[], int eflags);
\r
554 +#pragma GCC visibility pop
\r
557 diff --git a/xutil.c b/xutil.c
\r
558 deleted file mode 100644
\r
559 index 5f98f3f..0000000
\r