Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id DE8BD429E21 for ; Sun, 23 Oct 2011 14:52:07 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -2.3 X-Spam-Level: X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id qQIQiq5b4iII for ; Sun, 23 Oct 2011 14:52:05 -0700 (PDT) Received: from tempo.its.unb.ca (tempo.its.unb.ca [131.202.1.21]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 89CA2431FB6 for ; Sun, 23 Oct 2011 14:52:05 -0700 (PDT) Received: from zancas.localnet (fctnnbsc36w-156034064058.pppoe-dynamic.High-Speed.nb.bellaliant.net [156.34.64.58]) (authenticated bits=0) by tempo.its.unb.ca (8.13.8/8.13.8) with ESMTP id p9NLq0n2012762 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO); Sun, 23 Oct 2011 18:52:01 -0300 Received: from bremner by zancas.localnet with local (Exim 4.76) (envelope-from ) id 1RI5xY-0001st-7G; Sun, 23 Oct 2011 18:52:00 -0300 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH] xregcomp: don't consider every regex compilation failure an internal error. Date: Sun, 23 Oct 2011 18:51:13 -0300 Message-Id: <1319406673-7208-1-git-send-email-david@tethera.net> X-Mailer: git-send-email 1.7.6.3 In-Reply-To: <1319383133-11006-1-git-send-email-david@tethera.net> References: <1319383133-11006-1-git-send-email-david@tethera.net> Cc: David Bremner X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 23 Oct 2011 21:52:08 -0000 From: David Bremner This pushes the error handling up one step, but makes the function more flexible. Running out of memory still triggers an internal error, in the spirit of other xutils functions. --- And here is the promised modification of xregcomp. One issue I thought about is that we now have a(nother) place where a library routine is writing to stderr, not necessarily in the process of shutting down. notmuch-restore.c | 7 ++++--- util/xutil.c | 7 +++++-- util/xutil.h | 3 ++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/notmuch-restore.c b/notmuch-restore.c index ff1ebab..13b4325 100644 --- a/notmuch-restore.c +++ b/notmuch-restore.c @@ -88,9 +88,10 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[]) * non-space characters for the message-id, then one or more * spaces, then a list of space-separated tags as a sequence of * characters within literal '(' and ')'. */ - xregcomp (®ex, - "^([^ ]+) \\(([^)]*)\\)$", - REG_EXTENDED); + if ( xregcomp (®ex, + "^([^ ]+) \\(([^)]*)\\)$", + REG_EXTENDED) ) + INTERNAL_ERROR("compile time constant regex failed."); while ((line_len = getline (&line, &line_size, input)) != -1) { regmatch_t match[3]; diff --git a/util/xutil.c b/util/xutil.c index 15ff765..ac496da 100644 --- a/util/xutil.c +++ b/util/xutil.c @@ -99,7 +99,7 @@ xstrndup (const char *s, size_t n) return ret; } -void +int xregcomp (regex_t *preg, const char *regex, int cflags) { int rerr; @@ -110,9 +110,12 @@ xregcomp (regex_t *preg, const char *regex, int cflags) char *error = xmalloc (error_size); regerror (rerr, preg, error, error_size); - INTERNAL_ERROR ("compiling regex %s: %s\n", + fprintf (stderr, "compiling regex %s: %s\n", regex, error); + free (error); + return 1; } + return 0; } int diff --git a/util/xutil.h b/util/xutil.h index fd77f73..9299256 100644 --- a/util/xutil.h +++ b/util/xutil.h @@ -43,7 +43,8 @@ xstrdup (const char *s); char * xstrndup (const char *s, size_t n); -void +/* Returns 0 for successful compilation, 1 otherwise */ +int xregcomp (regex_t *preg, const char *regex, int cflags); int -- 1.7.6.3