[RFC PATCH 1/5] cli: g_hash_table_lookup_extended is overkill
[notmuch-archives.git] / 1c / 3ac34e70296b71670137720280fa8a48f2d1e7
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 D1F23431FC2\r
6         for <notmuch@notmuchmail.org>; Sun, 16 Dec 2012 19:24:29 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         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 NJSJICkb0zdg for <notmuch@notmuchmail.org>;\r
16         Sun, 16 Dec 2012 19:24:28 -0800 (PST)\r
17 Received: from tesseract.cs.unb.ca (tesseract.cs.unb.ca [131.202.240.238])\r
18         (using TLSv1 with cipher AES256-SHA (256/256 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 413FA431E62\r
21         for <notmuch@notmuchmail.org>; Sun, 16 Dec 2012 19:24:26 -0800 (PST)\r
22 Received: from fctnnbsc30w-142167090129.dhcp-dynamic.fibreop.nb.bellaliant.net\r
23         ([142.167.90.129] helo=zancas.localnet)\r
24         by tesseract.cs.unb.ca with esmtpsa\r
25         (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72)\r
26         (envelope-from <bremner@tethera.net>)\r
27         id 1TkRJZ-0008Jl-AJ; Sun, 16 Dec 2012 23:24:25 -0400\r
28 Received: from bremner by zancas.localnet with local (Exim 4.80)\r
29         (envelope-from <bremner@tethera.net>)\r
30         id 1TkRJT-00063P-OV; Sun, 16 Dec 2012 23:24:19 -0400\r
31 From: david@tethera.net\r
32 To: notmuch@notmuchmail.org\r
33 Subject: [PATCH 2/3] util: add xtalloc.[ch]\r
34 Date: Sun, 16 Dec 2012 23:24:06 -0400\r
35 Message-Id: <1355714648-23144-3-git-send-email-david@tethera.net>\r
36 X-Mailer: git-send-email 1.7.10.4\r
37 In-Reply-To: <1355714648-23144-1-git-send-email-david@tethera.net>\r
38 References: <1355714648-23144-1-git-send-email-david@tethera.net>\r
39 X-Spam_bar: -\r
40 Cc: David Bremner <bremner@debian.org>\r
41 X-BeenThere: notmuch@notmuchmail.org\r
42 X-Mailman-Version: 2.1.13\r
43 Precedence: list\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: Mon, 17 Dec 2012 03:24:30 -0000\r
54 \r
55 From: David Bremner <bremner@debian.org>\r
56 \r
57 These are intended to be simple wrappers to provide slightly better\r
58 debugging information than what talloc currently provides natively.\r
59 ---\r
60  notmuch-client.h    |    2 +-\r
61  util/Makefile.local |    2 +-\r
62  util/xtalloc.c      |   15 +++++++++++++++\r
63  util/xtalloc.h      |   18 ++++++++++++++++++\r
64  4 files changed, 35 insertions(+), 2 deletions(-)\r
65  create mode 100644 util/xtalloc.c\r
66  create mode 100644 util/xtalloc.h\r
67 \r
68 diff --git a/notmuch-client.h b/notmuch-client.h\r
69 index d7b352e..60be030 100644\r
70 --- a/notmuch-client.h\r
71 +++ b/notmuch-client.h\r
72 @@ -58,7 +58,7 @@ typedef GMimeCipherContext notmuch_crypto_context_t;\r
73  #include <errno.h>\r
74  #include <signal.h>\r
75  \r
76 -#include <talloc.h>\r
77 +#include "xtalloc.h"\r
78  \r
79  #define unused(x) x __attribute__ ((unused))\r
80  \r
81 diff --git a/util/Makefile.local b/util/Makefile.local\r
82 index a11e35b..8a62c00 100644\r
83 --- a/util/Makefile.local\r
84 +++ b/util/Makefile.local\r
85 @@ -4,7 +4,7 @@ dir := util\r
86  extra_cflags += -I$(srcdir)/$(dir)\r
87  \r
88  libutil_c_srcs := $(dir)/xutil.c $(dir)/error_util.c $(dir)/hex-escape.c \\r
89 -                 $(dir)/string-util.c\r
90 +                 $(dir)/string-util.c $(dir)/xtalloc.c\r
91  \r
92  libutil_modules := $(libutil_c_srcs:.c=.o)\r
93  \r
94 diff --git a/util/xtalloc.c b/util/xtalloc.c\r
95 new file mode 100644\r
96 index 0000000..22834bd\r
97 --- /dev/null\r
98 +++ b/util/xtalloc.c\r
99 @@ -0,0 +1,15 @@\r
100 +#include <string.h>\r
101 +#include "xtalloc.h"\r
102 +\r
103 +char *\r
104 +xtalloc_strndup_named_const (void *ctx, const char *str,\r
105 +                            size_t len, const char *name)\r
106 +{\r
107 +    char *ptr = talloc_named_const (ctx, len + 1, name);\r
108 +\r
109 +    if (ptr) {\r
110 +       memcpy (ptr, str, len);\r
111 +       *(ptr + len) = '\0';\r
112 +    }\r
113 +    return ptr;\r
114 +}\r
115 diff --git a/util/xtalloc.h b/util/xtalloc.h\r
116 new file mode 100644\r
117 index 0000000..3cc1179\r
118 --- /dev/null\r
119 +++ b/util/xtalloc.h\r
120 @@ -0,0 +1,18 @@\r
121 +#ifndef _XTALLOC_H\r
122 +#define _XTALLOC_H\r
123 +\r
124 +#include <talloc.h>\r
125 +\r
126 +/* Like talloc_strndup, but take an extra parameter for the internal talloc\r
127 + * name (for debugging) */\r
128 +\r
129 +char *\r
130 +xtalloc_strndup_named_const (void *ctx, const char *str,\r
131 +                            size_t len, const char *name);\r
132 +\r
133 +/* use the __location__ macro from talloc.h to name a string according to its\r
134 + * source location */\r
135 +\r
136 +#define xtalloc_strndup(ctx, str, len) xtalloc_strndup_named_const (ctx, str, len, __location__)\r
137 +\r
138 +#endif\r
139 -- \r
140 1.7.10.4\r
141 \r