1 Return-Path: <tomi.ollila@iki.fi>
\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 DC61F431FAF
\r
6 for <notmuch@notmuchmail.org>; Thu, 20 Dec 2012 07:42:45 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\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 t4E-OUV1qtVV for <notmuch@notmuchmail.org>;
\r
16 Thu, 20 Dec 2012 07:42:45 -0800 (PST)
\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])
\r
18 by olra.theworths.org (Postfix) with ESMTP id 1AF64431FAE
\r
19 for <notmuch@notmuchmail.org>; Thu, 20 Dec 2012 07:42:45 -0800 (PST)
\r
20 Received: from guru.guru-group.fi (localhost [IPv6:::1])
\r
21 by guru.guru-group.fi (Postfix) with ESMTP id C6A85100094;
\r
22 Thu, 20 Dec 2012 17:42:39 +0200 (EET)
\r
23 From: Tomi Ollila <tomi.ollila@iki.fi>
\r
24 To: david@tethera.net, notmuch@notmuchmail.org
\r
25 Subject: Re: [PATCH 2/3] util: add xtalloc.[ch]
\r
26 In-Reply-To: <1355714648-23144-3-git-send-email-david@tethera.net>
\r
27 References: <1355714648-23144-1-git-send-email-david@tethera.net>
\r
28 <1355714648-23144-3-git-send-email-david@tethera.net>
\r
29 User-Agent: Notmuch/0.14+211~g71b47e9 (http://notmuchmail.org) Emacs/24.2.1
\r
30 (x86_64-unknown-linux-gnu)
\r
31 X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL
\r
32 $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F
\r
33 !)g;OY^,BjTbr)Np:%c_o'jj,Z
\r
34 Date: Thu, 20 Dec 2012 17:42:39 +0200
\r
35 Message-ID: <m2ehikivbk.fsf@guru.guru-group.fi>
\r
37 Content-Type: text/plain
\r
38 Cc: David Bremner <bremner@debian.org>
\r
39 X-BeenThere: notmuch@notmuchmail.org
\r
40 X-Mailman-Version: 2.1.13
\r
42 List-Id: "Use and development of the notmuch mail system."
\r
43 <notmuch.notmuchmail.org>
\r
44 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
45 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
46 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
47 List-Post: <mailto:notmuch@notmuchmail.org>
\r
48 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
49 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
50 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
51 X-List-Received-Date: Thu, 20 Dec 2012 15:42:46 -0000
\r
53 On Mon, Dec 17 2012, david@tethera.net wrote:
\r
55 > From: David Bremner <bremner@debian.org>
\r
57 > These are intended to be simple wrappers to provide slightly better
\r
58 > debugging information than what talloc currently provides natively.
\r
61 AFAIC it's been customary to have memory allocation functions starting
\r
62 with 'x' to abort execution if memory allocation fails. See util/xutil.c
\r
63 in notmuch source for reference. IMHO it would be confusing to use
\r
64 the 'x' prefix for some other use.
\r
69 > notmuch-client.h | 2 +-
\r
70 > util/Makefile.local | 2 +-
\r
71 > util/xtalloc.c | 15 +++++++++++++++
\r
72 > util/xtalloc.h | 18 ++++++++++++++++++
\r
73 > 4 files changed, 35 insertions(+), 2 deletions(-)
\r
74 > create mode 100644 util/xtalloc.c
\r
75 > create mode 100644 util/xtalloc.h
\r
77 > diff --git a/notmuch-client.h b/notmuch-client.h
\r
78 > index d7b352e..60be030 100644
\r
79 > --- a/notmuch-client.h
\r
80 > +++ b/notmuch-client.h
\r
81 > @@ -58,7 +58,7 @@ typedef GMimeCipherContext notmuch_crypto_context_t;
\r
82 > #include <errno.h>
\r
83 > #include <signal.h>
\r
85 > -#include <talloc.h>
\r
86 > +#include "xtalloc.h"
\r
88 > #define unused(x) x __attribute__ ((unused))
\r
90 > diff --git a/util/Makefile.local b/util/Makefile.local
\r
91 > index a11e35b..8a62c00 100644
\r
92 > --- a/util/Makefile.local
\r
93 > +++ b/util/Makefile.local
\r
94 > @@ -4,7 +4,7 @@ dir := util
\r
95 > extra_cflags += -I$(srcdir)/$(dir)
\r
97 > libutil_c_srcs := $(dir)/xutil.c $(dir)/error_util.c $(dir)/hex-escape.c \
\r
98 > - $(dir)/string-util.c
\r
99 > + $(dir)/string-util.c $(dir)/xtalloc.c
\r
101 > libutil_modules := $(libutil_c_srcs:.c=.o)
\r
103 > diff --git a/util/xtalloc.c b/util/xtalloc.c
\r
104 > new file mode 100644
\r
105 > index 0000000..22834bd
\r
107 > +++ b/util/xtalloc.c
\r
109 > +#include <string.h>
\r
110 > +#include "xtalloc.h"
\r
113 > +xtalloc_strndup_named_const (void *ctx, const char *str,
\r
114 > + size_t len, const char *name)
\r
116 > + char *ptr = talloc_named_const (ctx, len + 1, name);
\r
119 > + memcpy (ptr, str, len);
\r
120 > + *(ptr + len) = '\0';
\r
124 > diff --git a/util/xtalloc.h b/util/xtalloc.h
\r
125 > new file mode 100644
\r
126 > index 0000000..3cc1179
\r
128 > +++ b/util/xtalloc.h
\r
130 > +#ifndef _XTALLOC_H
\r
131 > +#define _XTALLOC_H
\r
133 > +#include <talloc.h>
\r
135 > +/* Like talloc_strndup, but take an extra parameter for the internal talloc
\r
136 > + * name (for debugging) */
\r
139 > +xtalloc_strndup_named_const (void *ctx, const char *str,
\r
140 > + size_t len, const char *name);
\r
142 > +/* use the __location__ macro from talloc.h to name a string according to its
\r
143 > + * source location */
\r
145 > +#define xtalloc_strndup(ctx, str, len) xtalloc_strndup_named_const (ctx, str, len, __location__)
\r
151 > _______________________________________________
\r
152 > notmuch mailing list
\r
153 > notmuch@notmuchmail.org
\r
154 > http://notmuchmail.org/mailman/listinfo/notmuch
\r