Re: [PATCH] xutil.c: remove duplicate copies, create new library libutil.a to contain...
authorDavid Bremner <david@tethera.net>
Sat, 29 Oct 2011 18:52:25 +0000 (15:52 +2100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:39:51 +0000 (09:39 -0800)
cd/d28a9f92fdb9aa588d53872981c427d7b55787 [new file with mode: 0644]

diff --git a/cd/d28a9f92fdb9aa588d53872981c427d7b55787 b/cd/d28a9f92fdb9aa588d53872981c427d7b55787
new file mode 100644 (file)
index 0000000..c00a132
--- /dev/null
@@ -0,0 +1,950 @@
+Return-Path: <bremner@unb.ca>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 11312429E25\r
+       for <notmuch@notmuchmail.org>; Sat, 29 Oct 2011 11:52:38 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.525\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.525 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_MED=-2.3, URIBL_BLACK=1.775] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id 789WWmsVrckh for <notmuch@notmuchmail.org>;\r
+       Sat, 29 Oct 2011 11:52:35 -0700 (PDT)\r
+Received: from tempo.its.unb.ca (tempo.its.unb.ca [131.202.1.21])\r
+       (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 44A2F431FB6\r
+       for <notmuch@notmuchmail.org>; Sat, 29 Oct 2011 11:52:35 -0700 (PDT)\r
+Received: from zancas.localnet\r
+       (fctnnbsc36w-156034064058.pppoe-dynamic.High-Speed.nb.bellaliant.net\r
+       [156.34.64.58]) (authenticated bits=0)\r
+       by tempo.its.unb.ca (8.13.8/8.13.8) with ESMTP id p9TIqXhe001319\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO);\r
+       Sat, 29 Oct 2011 15:52:33 -0300\r
+Received: from bremner by zancas.localnet with local (Exim 4.76)\r
+       (envelope-from <bremner@unb.ca>)\r
+       id 1RKE1A-0004Nq-Ud; Sat, 29 Oct 2011 15:52:32 -0300\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: Re: [PATCH] xutil.c: remove duplicate copies,\r
+       create new library libutil.a to contain xutil.\r
+In-Reply-To: <1319383133-11006-1-git-send-email-david@tethera.net>\r
+References: <1319383133-11006-1-git-send-email-david@tethera.net>\r
+User-Agent: Notmuch/0.9+26~g4e49596 (http://notmuchmail.org) Emacs/23.3.1\r
+       (x86_64-pc-linux-gnu)\r
+Date: Sat, 29 Oct 2011 15:52:25 -0300\r
+Message-ID: <87aa8j7hqu.fsf@zancas.localnet>\r
+MIME-Version: 1.0\r
+Content-Type: multipart/mixed; boundary="=-=-="\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sat, 29 Oct 2011 18:52:38 -0000\r
+\r
+--=-=-=\r
+Content-Type: multipart/signed; boundary="==-=-=";\r
+       micalg=pgp-sha1; protocol="application/pgp-signature"\r
+\r
+--==-=-=\r
+Content-Transfer-Encoding: quoted-printable\r
+\r
+On Sun, 23 Oct 2011 12:18:53 -0300, David Bremner <david@tethera.net> wrote:\r
+> From: David Bremner <bremner@debian.org>\r
+>=20\r
+> We keep the lib/xutil.c version. As a consequence, also factor out\r
+> _internal_error and associated macros.  It might be overkill to make a\r
+> new file error_util.c for this, but _internal_error does not really\r
+> belong in database.cc.\r
+\r
+It seems this patch was sent out base64 encoded, which confuses git-am.\r
+I attach the patch here. You won't be able to git am this message, but\r
+you can at least save the attachment and apply it. Sorry for the\r
+inconvenience.\r
+\r
+\r
+--==-=-=\r
+Content-Type: application/pgp-signature\r
+\r
+-----BEGIN PGP SIGNATURE-----\r
+Version: GnuPG v1.4.11 (GNU/Linux)\r
+\r
+iJwEAQECAAYFAk6sS2kACgkQTiiN/0Um85lD5AP9F3/wFn9mhV2s21RY5pkFylGo\r
+ZdxDa6IWnCYvuCSHgYu6cbYS2Ttimls2gXJIw9p3hVADSWQ5WXNFykG1cLk7EHB7\r
+lEGdU3nhRHmj9yX3VD4sLX9moozVVz2+aQBvcywFU+AWS15p09ZSde2APAmhSBTh\r
+HnmxCtkC+kk5Rw7Nm/Q=\r
+=BFhN\r
+-----END PGP SIGNATURE-----\r
+--==-=-=--\r
+\r
+--=-=-=\r
+Content-Type: text/x-diff; charset=utf-8\r
+Content-Disposition: attachment;\r
+ filename=0001-xutil.c-remove-duplicate-copies-create-new-library-l.patch\r
+Content-Transfer-Encoding: quoted-printable\r
+Content-Description: xutil patch\r
+\r
+>From 5c678c9bc96890ce9a5965d6654851ebbe2b4767 Mon Sep 17 00:00:00 2001\r
+From: David Bremner <bremner@debian.org>\r
+Date: Sun, 23 Oct 2011 12:05:13 -0300\r
+Subject: [PATCH] xutil.c: remove duplicate copies, create new library\r
+ libutil.a to contain xutil.\r
+\r
+We keep the lib/xutil.c version. As a consequence, also factor out\r
+_internal_error and associated macros.  It might be overkill to make a\r
+new file error_util.c for this, but _internal_error does not really\r
+belong in database.cc.\r
+---\r
+ Makefile              |    2 +-\r
+ Makefile.local        |    7 +--\r
+ lib/Makefile.local    |    5 +-\r
+ lib/database.cc       |   15 -----\r
+ lib/notmuch-private.h |   20 +-------\r
+ lib/xutil.c           |  134 ---------------------------------------------=\r
+--\r
+ lib/xutil.h           |   55 -------------------\r
+ util/Makefile         |    5 ++\r
+ util/Makefile.local   |   11 ++++\r
+ util/error_util.c     |   41 +++++++++++++++\r
+ util/error_util.h     |   45 ++++++++++++++++\r
+ util/xutil.c          |  136 +++++++++++++++++++++++++++++++++++++++++++++=\r
++++\r
+ util/xutil.h          |   55 +++++++++++++++++++\r
+ xutil.c               |  138 ---------------------------------------------=\r
+----\r
+ 14 files changed, 300 insertions(+), 369 deletions(-)\r
+ delete mode 100644 lib/xutil.c\r
+ delete mode 100644 lib/xutil.h\r
+ create mode 100644 util/Makefile\r
+ create mode 100644 util/Makefile.local\r
+ create mode 100644 util/error_util.c\r
+ create mode 100644 util/error_util.h\r
+ create mode 100644 util/xutil.c\r
+ create mode 100644 util/xutil.h\r
+ delete mode 100644 xutil.c\r
+\r
+diff --git a/Makefile b/Makefile\r
+index 11e3a3d..2fb2a61 100644\r
+--- a/Makefile\r
++++ b/Makefile\r
+@@ -3,7 +3,7 @@\r
+ all:\r
+=20\r
+ # List all subdirectories here. Each contains its own Makefile.local\r
+-subdirs =3D compat completion emacs lib test\r
++subdirs =3D compat completion emacs lib util test\r
+=20\r
+ # We make all targets depend on the Makefiles themselves.\r
+ global_deps =3D Makefile Makefile.config Makefile.local \\r
+diff --git a/Makefile.local b/Makefile.local\r
+index ec09f95..6ddef5c 100644\r
+--- a/Makefile.local\r
++++ b/Makefile.local\r
+@@ -39,7 +39,7 @@ PV_FILE=3Dbindings/python/notmuch/version.py\r
+ # Smash together user's values with our extra values\r
+ FINAL_CFLAGS =3D -DNOTMUCH_VERSION=3D$(VERSION) $(CFLAGS) $(WARN_CFLAGS) $=\r
+(CONFIGURE_CFLAGS) $(extra_cflags)\r
+ FINAL_CXXFLAGS =3D $(CXXFLAGS) $(WARN_CXXFLAGS) $(CONFIGURE_CXXFLAGS) $(ex=\r
+tra_cflags) $(extra_cxxflags)\r
+-FINAL_NOTMUCH_LDFLAGS =3D $(LDFLAGS) -Llib -lnotmuch $(AS_NEEDED_LDFLAGS) =\r
+$(GMIME_LDFLAGS) $(TALLOC_LDFLAGS)\r
++FINAL_NOTMUCH_LDFLAGS =3D $(LDFLAGS) -Lutil -lutil -Llib -lnotmuch $(AS_NE=\r
+EDED_LDFLAGS) $(GMIME_LDFLAGS) $(TALLOC_LDFLAGS)\r
+ FINAL_NOTMUCH_LINKER =3D CC\r
+ ifneq ($(LINKER_RESOLVES_LIBRARY_DEPENDENCIES),1)\r
+ FINAL_NOTMUCH_LDFLAGS +=3D $(CONFIGURE_LDFLAGS)\r
+@@ -299,12 +299,11 @@ notmuch_client_srcs =3D          \\r
+       notmuch-time.c          \\r
+       query-string.c          \\r
+       show-message.c          \\r
+-      json.c                  \\r
+-      xutil.c\r
++      json.c\r
+=20\r
+ notmuch_client_modules =3D $(notmuch_client_srcs:.c=3D.o)\r
+=20\r
+-notmuch: $(notmuch_client_modules) lib/libnotmuch.a\r
++notmuch: $(notmuch_client_modules) lib/libnotmuch.a util/libutil.a\r
+       $(call quiet,CXX $(CFLAGS)) $^ $(FINAL_LIBNOTMUCH_LDFLAGS) -o $@\r
+=20\r
+ notmuch-shared: $(notmuch_client_modules) lib/$(LINKER_NAME)\r
+diff --git a/lib/Makefile.local b/lib/Makefile.local\r
+index be51eaa..d58552c 100644\r
+--- a/lib/Makefile.local\r
++++ b/lib/Makefile.local\r
+@@ -54,8 +54,7 @@ libnotmuch_c_srcs =3D                \\r
+       $(dir)/message-file.c   \\r
+       $(dir)/messages.c       \\r
+       $(dir)/sha1.c           \\r
+-      $(dir)/tags.c           \\r
+-      $(dir)/xutil.c\r
++      $(dir)/tags.c\r
+=20\r
+ libnotmuch_cxx_srcs =3D               \\r
+       $(dir)/database.cc      \\r
+@@ -71,7 +70,7 @@ $(dir)/libnotmuch.a: $(libnotmuch_modules)\r
+       $(call quiet,AR) rcs $@ $^\r
+=20\r
+ $(dir)/$(LIBNAME): $(libnotmuch_modules) notmuch.sym\r
+-      $(call quiet,CXX $(CXXFLAGS)) $(libnotmuch_modules) $(FINAL_LIBNOTMUCH_LD=\r
+FLAGS) $(LIBRARY_LINK_FLAG) -o $@\r
++      $(call quiet,CXX $(CXXFLAGS)) $(libnotmuch_modules) $(FINAL_LIBNOTMUCH_LD=\r
+FLAGS) $(LIBRARY_LINK_FLAG) -o $@ -L$(srcdir)/util -lutil\r
+=20\r
+ notmuch.sym: $(srcdir)/$(dir)/notmuch.h $(libnotmuch_modules)\r
+       sh $(srcdir)/$(lib)/gen-version-script.sh $< $(libnotmuch_modules) > $@\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index e77fd53..88be939 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -209,21 +209,6 @@ static prefix_t PROBABILISTIC_PREFIX[]=3D {\r
+     { "folder",                       "XFOLDER"}\r
+ };\r
+=20\r
+-int\r
+-_internal_error (const char *format, ...)\r
+-{\r
+-    va_list va_args;\r
+-\r
+-    va_start (va_args, format);\r
+-\r
+-    fprintf (stderr, "Internal error: ");\r
+-    vfprintf (stderr, format, va_args);\r
+-\r
+-    exit (1);\r
+-\r
+-    return 1;\r
+-}\r
+-\r
+ const char *\r
+ _find_prefix (const char *name)\r
+ {\r
+diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
+index d319530..0d3cc27 100644\r
+--- a/lib/notmuch-private.h\r
++++ b/lib/notmuch-private.h\r
+@@ -47,6 +47,7 @@ NOTMUCH_BEGIN_DECLS\r
+ #include <talloc.h>\r
+=20\r
+ #include "xutil.h"\r
++#include "error_util.h"\r
+=20\r
+ #pragma GCC visibility push(hidden)\r
+=20\r
+@@ -60,25 +61,6 @@ NOTMUCH_BEGIN_DECLS\r
+ #define STRNCMP_LITERAL(var, literal) \\r
+     strncmp ((var), (literal), sizeof (literal) - 1)\r
+=20\r
+-/* There's no point in continuing when we've detected that we've done\r
+- * something wrong internally (as opposed to the user passing in a\r
+- * bogus value).\r
+- *\r
+- * Note that PRINTF_ATTRIBUTE comes from talloc.h\r
+- */\r
+-int\r
+-_internal_error (const char *format, ...) PRINTF_ATTRIBUTE (1, 2);\r
+-\r
+-/* There's no point in continuing when we've detected that we've done\r
+- * something wrong internally (as opposed to the user passing in a\r
+- * bogus value).\r
+- *\r
+- * Note that __location__ comes from talloc.h.\r
+- */\r
+-#define INTERNAL_ERROR(format, ...)                   \\r
+-    _internal_error (format " (%s).\n",                       \\r
+-                   ##__VA_ARGS__, __location__)\r
+-\r
+ #define unused(x) x __attribute__ ((unused))\r
+=20\r
+ #ifdef __cplusplus\r
+diff --git a/lib/xutil.c b/lib/xutil.c\r
+deleted file mode 100644\r
+index 268225b..0000000\r
+--- a/lib/xutil.c\r
++++ /dev/null\r
+@@ -1,134 +0,0 @@\r
+-/* xutil.c - Various wrapper functions to abort on error.\r
+- *\r
+- * Copyright =C2=A9 2009 Carl Worth\r
+- *\r
+- * This program is free software: you can redistribute it and/or modify\r
+- * it under the terms of the GNU General Public License as published by\r
+- * the Free Software Foundation, either version 3 of the License, or\r
+- * (at your option) any later version.\r
+- *\r
+- * This program is distributed in the hope that it will be useful,\r
+- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+- * GNU General Public License for more details.\r
+- *\r
+- * You should have received a copy of the GNU General Public License\r
+- * along with this program.  If not, see http://www.gnu.org/licenses/ .\r
+- *\r
+- * Author: Carl Worth <cworth@cworth.org>\r
+- */\r
+-\r
+-#include "notmuch-private.h"\r
+-\r
+-#include <stdio.h>\r
+-\r
+-void *\r
+-xcalloc (size_t nmemb, size_t size)\r
+-{\r
+-    void *ret;\r
+-\r
+-    ret =3D calloc (nmemb, size);\r
+-    if (ret =3D=3D NULL) {\r
+-      fprintf (stderr, "Out of memory.\n");\r
+-      exit (1);\r
+-    }\r
+-\r
+-    return ret;\r
+-}\r
+-\r
+-void *\r
+-xmalloc (size_t size)\r
+-{\r
+-    void *ret;\r
+-\r
+-    ret =3D malloc (size);\r
+-    if (ret =3D=3D NULL) {\r
+-      fprintf (stderr, "Out of memory.\n");\r
+-      exit (1);\r
+-    }\r
+-\r
+-    return ret;\r
+-}\r
+-\r
+-void *\r
+-xrealloc (void *ptr, size_t size)\r
+-{\r
+-    void *ret;\r
+-\r
+-    ret =3D realloc (ptr, size);\r
+-    if (ret =3D=3D NULL) {\r
+-      fprintf (stderr, "Out of memory.\n");\r
+-      exit (1);\r
+-    }\r
+-\r
+-    return ret;\r
+-}\r
+-\r
+-char *\r
+-xstrdup (const char *s)\r
+-{\r
+-    char *ret;\r
+-\r
+-    ret =3D strdup (s);\r
+-    if (ret =3D=3D NULL) {\r
+-      fprintf (stderr, "Out of memory.\n");\r
+-      exit (1);\r
+-    }\r
+-\r
+-    return ret;\r
+-}\r
+-\r
+-char *\r
+-xstrndup (const char *s, size_t n)\r
+-{\r
+-    char *ret;\r
+-\r
+-    if (strlen (s) <=3D n)\r
+-      n =3D strlen (s);\r
+-\r
+-    ret =3D malloc (n + 1);\r
+-    if (ret =3D=3D NULL) {\r
+-      fprintf (stderr, "Out of memory.\n");\r
+-      exit (1);\r
+-    }\r
+-    memcpy (ret, s, n);\r
+-    ret[n] =3D '\0';\r
+-\r
+-    return ret;\r
+-}\r
+-\r
+-void\r
+-xregcomp (regex_t *preg, const char *regex, int cflags)\r
+-{\r
+-    int rerr;\r
+-\r
+-    rerr =3D regcomp (preg, regex, cflags);\r
+-    if (rerr) {\r
+-      size_t error_size =3D regerror (rerr, preg, NULL, 0);\r
+-      char *error =3D xmalloc (error_size);\r
+-\r
+-      regerror (rerr, preg, error, error_size);\r
+-      INTERNAL_ERROR ("compiling regex %s: %s\n",\r
+-                      regex, error);\r
+-    }\r
+-}\r
+-\r
+-int\r
+-xregexec (const regex_t *preg, const char *string,\r
+-        size_t nmatch, regmatch_t pmatch[], int eflags)\r
+-{\r
+-    unsigned int i;\r
+-    int rerr;\r
+-\r
+-    rerr =3D regexec (preg, string, nmatch, pmatch, eflags);\r
+-    if (rerr)\r
+-      return rerr;\r
+-\r
+-    for (i =3D 0; i < nmatch; i++) {\r
+-      if (pmatch[i].rm_so =3D=3D -1)\r
+-          INTERNAL_ERROR ("matching regex against %s: Sub-match %d not found\n",\r
+-                          string, i);\r
+-    }\r
+-\r
+-    return 0;\r
+-}\r
+diff --git a/lib/xutil.h b/lib/xutil.h\r
+deleted file mode 100644\r
+index fd77f73..0000000\r
+--- a/lib/xutil.h\r
++++ /dev/null\r
+@@ -1,55 +0,0 @@\r
+-/* xutil.h - Various wrapper functions to abort on error.\r
+- *\r
+- * Copyright =C2=A9 2009 Carl Worth\r
+- *\r
+- * This program is free software: you can redistribute it and/or modify\r
+- * it under the terms of the GNU General Public License as published by\r
+- * the Free Software Foundation, either version 3 of the License, or\r
+- * (at your option) any later version.\r
+- *\r
+- * This program is distributed in the hope that it will be useful,\r
+- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+- * GNU General Public License for more details.\r
+- *\r
+- * You should have received a copy of the GNU General Public License\r
+- * along with this program.  If not, see http://www.gnu.org/licenses/ .\r
+- *\r
+- * Author: Carl Worth <cworth@cworth.org>\r
+- */\r
+-\r
+-#ifndef NOTMUCH_XUTIL_H\r
+-#define NOTMUCH_XUTIL_H\r
+-\r
+-#include <stdlib.h>\r
+-#include <sys/types.h>\r
+-#include <regex.h>\r
+-\r
+-#pragma GCC visibility push(hidden)\r
+-\r
+-/* xutil.c */\r
+-void *\r
+-xcalloc (size_t nmemb, size_t size);\r
+-\r
+-void *\r
+-xmalloc (size_t size);\r
+-\r
+-void *\r
+-xrealloc (void *ptrr, size_t size);\r
+-\r
+-char *\r
+-xstrdup (const char *s);\r
+-\r
+-char *\r
+-xstrndup (const char *s, size_t n);\r
+-\r
+-void\r
+-xregcomp (regex_t *preg, const char *regex, int cflags);\r
+-\r
+-int\r
+-xregexec (const regex_t *preg, const char *string,\r
+-        size_t nmatch, regmatch_t pmatch[], int eflags);\r
+-\r
+-#pragma GCC visibility pop\r
+-\r
+-#endif\r
+diff --git a/util/Makefile b/util/Makefile\r
+new file mode 100644\r
+index 0000000..fa25832\r
+--- /dev/null\r
++++ b/util/Makefile\r
+@@ -0,0 +1,5 @@\r
++all:\r
++      $(MAKE) -C .. all\r
++\r
++.DEFAULT:\r
++      $(MAKE) -C .. $@\r
+diff --git a/util/Makefile.local b/util/Makefile.local\r
+new file mode 100644\r
+index 0000000..2ff42b3\r
+--- /dev/null\r
++++ b/util/Makefile.local\r
+@@ -0,0 +1,11 @@\r
++# -*- makefile -*-\r
++\r
++dir :=3D util\r
++extra_cflags +=3D -I$(srcdir)/$(dir)\r
++\r
++libutil_c_srcs :=3D $(dir)/xutil.c $(dir)/error_util.c\r
++\r
++libutil_modules :=3D $(libutil_c_srcs:.c=3D.o)\r
++\r
++$(dir)/libutil.a: $(libutil_modules)\r
++      $(call quiet,AR) rcs $@ $^\r
+diff --git a/util/error_util.c b/util/error_util.c\r
+new file mode 100644\r
+index 0000000..630d228\r
+--- /dev/null\r
++++ b/util/error_util.c\r
+@@ -0,0 +1,41 @@\r
++/* error_util.c - internal error utilities for notmuch.\r
++ *\r
++ * Copyright =C2=A9 2009 Carl Worth\r
++ *\r
++ * This program is free software: you can redistribute it and/or modify\r
++ * it under the terms of the GNU General Public License as published by\r
++ * the Free Software Foundation, either version 3 of the License, or\r
++ * (at your option) any later version.\r
++ *\r
++ * This program is distributed in the hope that it will be useful,\r
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++ * GNU General Public License for more details.\r
++ *\r
++ * You should have received a copy of the GNU General Public License\r
++ * along with this program.  If not, see http://www.gnu.org/licenses/ .\r
++ *\r
++ * Author: Carl Worth <cworth@cworth.org>\r
++ */\r
++\r
++#include <stdlib.h>\r
++#include <stdarg.h>\r
++#include <stdio.h>\r
++\r
++#include "error_util.h"\r
++\r
++int\r
++_internal_error (const char *format, ...)\r
++{\r
++    va_list va_args;\r
++\r
++    va_start (va_args, format);\r
++\r
++    fprintf (stderr, "Internal error: ");\r
++    vfprintf (stderr, format, va_args);\r
++\r
++    exit (1);\r
++\r
++    return 1;\r
++}\r
++\r
+diff --git a/util/error_util.h b/util/error_util.h\r
+new file mode 100644\r
+index 0000000..0f1e5ef\r
+--- /dev/null\r
++++ b/util/error_util.h\r
+@@ -0,0 +1,45 @@\r
++/* error_util.h - Internal interfaces for notmuch.\r
++ *\r
++ * Copyright =C2=A9 2009 Carl Worth\r
++ *\r
++ * This program is free software: you can redistribute it and/or modify\r
++ * it under the terms of the GNU General Public License as published by\r
++ * the Free Software Foundation, either version 3 of the License, or\r
++ * (at your option) any later version.\r
++ *\r
++ * This program is distributed in the hope that it will be useful,\r
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++ * GNU General Public License for more details.\r
++ *\r
++ * You should have received a copy of the GNU General Public License\r
++ * along with this program.  If not, see http://www.gnu.org/licenses/ .\r
++ *\r
++ * Author: Carl Worth <cworth@cworth.org>\r
++ */\r
++\r
++#ifndef ERROR_UTIL_H\r
++#define ERROR_UTIL_H\r
++\r
++#include <talloc.h>\r
++\r
++/* There's no point in continuing when we've detected that we've done\r
++ * something wrong internally (as opposed to the user passing in a\r
++ * bogus value).\r
++ *\r
++ * Note that PRINTF_ATTRIBUTE comes from talloc.h\r
++ */\r
++int\r
++_internal_error (const char *format, ...) PRINTF_ATTRIBUTE (1, 2);\r
++\r
++/* There's no point in continuing when we've detected that we've done\r
++ * something wrong internally (as opposed to the user passing in a\r
++ * bogus value).\r
++ *\r
++ * Note that __location__ comes from talloc.h.\r
++ */\r
++#define INTERNAL_ERROR(format, ...)                   \\r
++    _internal_error (format " (%s).\n",                       \\r
++                   ##__VA_ARGS__, __location__)\r
++\r
++#endif\r
+diff --git a/util/xutil.c b/util/xutil.c\r
+new file mode 100644\r
+index 0000000..15ff765\r
+--- /dev/null\r
++++ b/util/xutil.c\r
+@@ -0,0 +1,136 @@\r
++/* xutil.c - Various wrapper functions to abort on error.\r
++ *\r
++ * Copyright =C2=A9 2009 Carl Worth\r
++ *\r
++ * This program is free software: you can redistribute it and/or modify\r
++ * it under the terms of the GNU General Public License as published by\r
++ * the Free Software Foundation, either version 3 of the License, or\r
++ * (at your option) any later version.\r
++ *\r
++ * This program is distributed in the hope that it will be useful,\r
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++ * GNU General Public License for more details.\r
++ *\r
++ * You should have received a copy of the GNU General Public License\r
++ * along with this program.  If not, see http://www.gnu.org/licenses/ .\r
++ *\r
++ * Author: Carl Worth <cworth@cworth.org>\r
++ */\r
++\r
++#include <stdio.h>\r
++#include <string.h>\r
++\r
++#include "xutil.h"\r
++#include "error_util.h"\r
++\r
++void *\r
++xcalloc (size_t nmemb, size_t size)\r
++{\r
++    void *ret;\r
++\r
++    ret =3D calloc (nmemb, size);\r
++    if (ret =3D=3D NULL) {\r
++      fprintf (stderr, "Out of memory.\n");\r
++      exit (1);\r
++    }\r
++\r
++    return ret;\r
++}\r
++\r
++void *\r
++xmalloc (size_t size)\r
++{\r
++    void *ret;\r
++\r
++    ret =3D malloc (size);\r
++    if (ret =3D=3D NULL) {\r
++      fprintf (stderr, "Out of memory.\n");\r
++      exit (1);\r
++    }\r
++\r
++    return ret;\r
++}\r
++\r
++void *\r
++xrealloc (void *ptr, size_t size)\r
++{\r
++    void *ret;\r
++\r
++    ret =3D realloc (ptr, size);\r
++    if (ret =3D=3D NULL) {\r
++      fprintf (stderr, "Out of memory.\n");\r
++      exit (1);\r
++    }\r
++\r
++    return ret;\r
++}\r
++\r
++char *\r
++xstrdup (const char *s)\r
++{\r
++    char *ret;\r
++\r
++    ret =3D strdup (s);\r
++    if (ret =3D=3D NULL) {\r
++      fprintf (stderr, "Out of memory.\n");\r
++      exit (1);\r
++    }\r
++\r
++    return ret;\r
++}\r
++\r
++char *\r
++xstrndup (const char *s, size_t n)\r
++{\r
++    char *ret;\r
++\r
++    if (strlen (s) <=3D n)\r
++      n =3D strlen (s);\r
++\r
++    ret =3D malloc (n + 1);\r
++    if (ret =3D=3D NULL) {\r
++      fprintf (stderr, "Out of memory.\n");\r
++      exit (1);\r
++    }\r
++    memcpy (ret, s, n);\r
++    ret[n] =3D '\0';\r
++\r
++    return ret;\r
++}\r
++\r
++void\r
++xregcomp (regex_t *preg, const char *regex, int cflags)\r
++{\r
++    int rerr;\r
++\r
++    rerr =3D regcomp (preg, regex, cflags);\r
++    if (rerr) {\r
++      size_t error_size =3D regerror (rerr, preg, NULL, 0);\r
++      char *error =3D xmalloc (error_size);\r
++\r
++      regerror (rerr, preg, error, error_size);\r
++      INTERNAL_ERROR ("compiling regex %s: %s\n",\r
++                      regex, error);\r
++    }\r
++}\r
++\r
++int\r
++xregexec (const regex_t *preg, const char *string,\r
++        size_t nmatch, regmatch_t pmatch[], int eflags)\r
++{\r
++    unsigned int i;\r
++    int rerr;\r
++\r
++    rerr =3D regexec (preg, string, nmatch, pmatch, eflags);\r
++    if (rerr)\r
++      return rerr;\r
++\r
++    for (i =3D 0; i < nmatch; i++) {\r
++      if (pmatch[i].rm_so =3D=3D -1)\r
++          INTERNAL_ERROR ("matching regex against %s: Sub-match %d not found\n",\r
++                          string, i);\r
++    }\r
++\r
++    return 0;\r
++}\r
+diff --git a/util/xutil.h b/util/xutil.h\r
+new file mode 100644\r
+index 0000000..fd77f73\r
+--- /dev/null\r
++++ b/util/xutil.h\r
+@@ -0,0 +1,55 @@\r
++/* xutil.h - Various wrapper functions to abort on error.\r
++ *\r
++ * Copyright =C2=A9 2009 Carl Worth\r
++ *\r
++ * This program is free software: you can redistribute it and/or modify\r
++ * it under the terms of the GNU General Public License as published by\r
++ * the Free Software Foundation, either version 3 of the License, or\r
++ * (at your option) any later version.\r
++ *\r
++ * This program is distributed in the hope that it will be useful,\r
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
++ * GNU General Public License for more details.\r
++ *\r
++ * You should have received a copy of the GNU General Public License\r
++ * along with this program.  If not, see http://www.gnu.org/licenses/ .\r
++ *\r
++ * Author: Carl Worth <cworth@cworth.org>\r
++ */\r
++\r
++#ifndef NOTMUCH_XUTIL_H\r
++#define NOTMUCH_XUTIL_H\r
++\r
++#include <stdlib.h>\r
++#include <sys/types.h>\r
++#include <regex.h>\r
++\r
++#pragma GCC visibility push(hidden)\r
++\r
++/* xutil.c */\r
++void *\r
++xcalloc (size_t nmemb, size_t size);\r
++\r
++void *\r
++xmalloc (size_t size);\r
++\r
++void *\r
++xrealloc (void *ptrr, size_t size);\r
++\r
++char *\r
++xstrdup (const char *s);\r
++\r
++char *\r
++xstrndup (const char *s, size_t n);\r
++\r
++void\r
++xregcomp (regex_t *preg, const char *regex, int cflags);\r
++\r
++int\r
++xregexec (const regex_t *preg, const char *string,\r
++        size_t nmatch, regmatch_t pmatch[], int eflags);\r
++\r
++#pragma GCC visibility pop\r
++\r
++#endif\r
+diff --git a/xutil.c b/xutil.c\r
+deleted file mode 100644\r
+index 5f98f3f..0000000\r
+--- a/xutil.c\r
++++ /dev/null\r
+@@ -1,138 +0,0 @@\r
+-/* xutil.c - Various wrapper functions to abort on error.\r
+- *\r
+- * Copyright =C2=A9 2009 Carl Worth\r
+- *\r
+- * This program is free software: you can redistribute it and/or modify\r
+- * it under the terms of the GNU General Public License as published by\r
+- * the Free Software Foundation, either version 3 of the License, or\r
+- * (at your option) any later version.\r
+- *\r
+- * This program is distributed in the hope that it will be useful,\r
+- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+- * GNU General Public License for more details.\r
+- *\r
+- * You should have received a copy of the GNU General Public License\r
+- * along with this program.  If not, see http://www.gnu.org/licenses/ .\r
+- *\r
+- * Author: Carl Worth <cworth@cworth.org>\r
+- */\r
+-\r
+-#include "notmuch-private.h"\r
+-\r
+-#include <stdio.h>\r
+-\r
+-void *\r
+-xcalloc (size_t nmemb, size_t size)\r
+-{\r
+-    void *ret;\r
+-\r
+-    ret =3D calloc (nmemb, size);\r
+-    if (ret =3D=3D NULL) {\r
+-      fprintf (stderr, "Out of memory.\n");\r
+-      exit (1);\r
+-    }\r
+-\r
+-    return ret;\r
+-}\r
+-\r
+-void *\r
+-xmalloc (size_t size)\r
+-{\r
+-    void *ret;\r
+-\r
+-    ret =3D malloc (size);\r
+-    if (ret =3D=3D NULL) {\r
+-      fprintf (stderr, "Out of memory.\n");\r
+-      exit (1);\r
+-    }\r
+-\r
+-    return ret;\r
+-}\r
+-\r
+-void *\r
+-xrealloc (void *ptr, size_t size)\r
+-{\r
+-    void *ret;\r
+-\r
+-    ret =3D realloc (ptr, size);\r
+-    if (ret =3D=3D NULL) {\r
+-      fprintf (stderr, "Out of memory.\n");\r
+-      exit (1);\r
+-    }\r
+-\r
+-    return ret;\r
+-}\r
+-\r
+-char *\r
+-xstrdup (const char *s)\r
+-{\r
+-    char *ret;\r
+-\r
+-    ret =3D strdup (s);\r
+-    if (ret =3D=3D NULL) {\r
+-      fprintf (stderr, "Out of memory.\n");\r
+-      exit (1);\r
+-    }\r
+-\r
+-    return ret;\r
+-}\r
+-\r
+-char *\r
+-xstrndup (const char *s, size_t n)\r
+-{\r
+-    char *ret;\r
+-\r
+-    if (strlen (s) <=3D n)\r
+-      n =3D strlen (s);\r
+-\r
+-    ret =3D malloc (n + 1);\r
+-    if (ret =3D=3D NULL) {\r
+-      fprintf (stderr, "Out of memory.\n");\r
+-      exit (1);\r
+-    }\r
+-    memcpy (ret, s, n);\r
+-    ret[n] =3D '\0';\r
+-\r
+-    return ret;\r
+-}\r
+-\r
+-void\r
+-xregcomp (regex_t *preg, const char *regex, int cflags)\r
+-{\r
+-    int rerr;\r
+-\r
+-    rerr =3D regcomp (preg, regex, cflags);\r
+-    if (rerr) {\r
+-      size_t error_size =3D regerror (rerr, preg, NULL, 0);\r
+-      char *error =3D xmalloc (error_size);\r
+-\r
+-      regerror (rerr, preg, error, error_size);\r
+-      fprintf (stderr, "Internal error: compiling regex %s: %s\n",\r
+-               regex, error);\r
+-      exit (1);\r
+-    }\r
+-}\r
+-\r
+-int\r
+-xregexec (const regex_t *preg, const char *string,\r
+-        size_t nmatch, regmatch_t pmatch[], int eflags)\r
+-{\r
+-    unsigned int i;\r
+-    int rerr;\r
+-\r
+-    rerr =3D regexec (preg, string, nmatch, pmatch, eflags);\r
+-    if (rerr)\r
+-      return rerr;\r
+-\r
+-    for (i =3D 0; i < nmatch; i++) {\r
+-      if (pmatch[i].rm_so =3D=3D -1) {\r
+-          fprintf (stderr, "Internal error: matching regex against %s:"\r
+-                   "Sub-match %d not found\n",\r
+-                   string, i);\r
+-          exit (1);\r
+-      }\r
+-    }\r
+-\r
+-    return 0;\r
+-}\r
+--=20\r
+1.7.6.3\r
+\r
+\r
+--=-=-=--\r