Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 7c / bc6d3e4b41d594c5cff12575dbe629553cb3db
1 Return-Path: <amdragon@mit.edu>\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 1DAFF431FBF\r
6         for <notmuch@notmuchmail.org>; Wed,  2 Apr 2014 13:43:54 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 HNJ+rtZaPRll for <notmuch@notmuchmail.org>;\r
16         Wed,  2 Apr 2014 13:43:46 -0700 (PDT)\r
17 Received: from dmz-mailsec-scanner-1.mit.edu (dmz-mailsec-scanner-1.mit.edu\r
18         [18.9.25.12])\r
19         (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id 4043E431FAE\r
22         for <notmuch@notmuchmail.org>; Wed,  2 Apr 2014 13:43:46 -0700 (PDT)\r
23 X-AuditID: 1209190c-f794a6d000000c27-bf-533c767fe4f3\r
24 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])\r
25         (using TLS with cipher AES256-SHA (256/256 bits))\r
26         (Client did not present a certificate)\r
27         by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP\r
28         id 76.64.03111.F767C335; Wed,  2 Apr 2014 16:43:43 -0400 (EDT)\r
29 Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
30         by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id s32KhffS031181; \r
31         Wed, 2 Apr 2014 16:43:42 -0400\r
32 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])\r
33         (authenticated bits=0)\r
34         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
35         by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s32Khc8G004820\r
36         (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT);\r
37         Wed, 2 Apr 2014 16:43:40 -0400\r
38 Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.80)\r
39         (envelope-from <amdragon@mit.edu>)\r
40         id 1WVS0Y-0001dl-H8; Wed, 02 Apr 2014 16:43:38 -0400\r
41 Date: Wed, 2 Apr 2014 16:43:38 -0400\r
42 From: Austin Clements <amdragon@MIT.EDU>\r
43 To: Tomi Ollila <tomi.ollila@iki.fi>\r
44 Subject: Re: [Patch v5 3/6] util: add gz_readline\r
45 Message-ID: <20140402204337.GA4678@mit.edu>\r
46 References: <1396401381-18128-1-git-send-email-david@tethera.net>\r
47         <1396401381-18128-4-git-send-email-david@tethera.net>\r
48         <20140402032644.GB25677@mit.edu>\r
49         <m2wqf73co4.fsf@guru.guru-group.fi>\r
50 MIME-Version: 1.0\r
51 Content-Type: text/plain; charset=us-ascii\r
52 Content-Disposition: inline\r
53 In-Reply-To: <m2wqf73co4.fsf@guru.guru-group.fi>\r
54 User-Agent: Mutt/1.5.21 (2010-09-15)\r
55 X-Brightmail-Tracker:\r
56  H4sIAAAAAAAAA+NgFprNKsWRmVeSWpSXmKPExsUixCmqrFtfZhNs0LdD0+JGazejxfWbM5kt\r
57         3qycx+rA7HH460IWj2erbjF7bDn0njmAOYrLJiU1J7MstUjfLoEr487U2WwFTcYVL5o2MjYw\r
58         PlPrYuTkkBAwkVj+rJ0ZwhaTuHBvPVsXIxeHkMBsJoktT79AORsYJa72nIVyTjFJzLm9kxXC\r
59         WcIocej4N3aQfhYBFYlHL5awgdhsAhoS2/YvZwSxRYDiD9rWs4LYzAJ2Eke+d4HFhQUMJf4v\r
60         e8YCYvMKaEss7JkIteEQo8TG82dYIRKCEidnPmGBaNaSuPHvJVMXIweQLS2x/B8HSJhTwECi\r
61         4+UbsJmiQLumnNzGNoFRaBaS7llIumchdC9gZF7FKJuSW6Wbm5iZU5yarFucnJiXl1qka6iX\r
62         m1mil5pSuokRHO6SPDsY3xxUOsQowMGoxMNrIWUTLMSaWFZcmXuIUZKDSUmUN7cEKMSXlJ9S\r
63         mZFYnBFfVJqTWgz0BwezkgivShRQjjclsbIqtSgfJiXNwaIkzvvW2ipYSCA9sSQ1OzW1ILUI\r
64         JivDwaEkwdtQCtQoWJSanlqRlplTgpBm4uAEGc4DNHw2yGLe4oLE3OLMdIj8KUZdjk8b1jQy\r
65         CbHk5eelSonzXgApEgApyijNg5sDS1OvGMWB3hLmDQNZxwNMcXCTXgEtYQJawr3OCmRJSSJC\r
66         SqqB0WGvU9qefdUfr2s6bu0VXRR8bVHym4ozxd/Nn58SdmdZqC/86KzQR8N/c59yXnvNODdc\r
67         RPaj3cwtbClqtxvdUmYFlbrWrdrJE8gsuCwqIb2x9UjIullNDh6PPr5+tzvNuufeoa1nyu4w\r
68         Wv7fE7hU783tLGNek3M/34T/WKvAIzyxrWE6f9gtfiWW4oxEQy3mouJEAHDnz1IuAwAA\r
69 Cc: notmuch@notmuchmail.org\r
70 X-BeenThere: notmuch@notmuchmail.org\r
71 X-Mailman-Version: 2.1.13\r
72 Precedence: list\r
73 List-Id: "Use and development of the notmuch mail system."\r
74         <notmuch.notmuchmail.org>\r
75 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
76         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
77 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
78 List-Post: <mailto:notmuch@notmuchmail.org>\r
79 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
80 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
81         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
82 X-List-Received-Date: Wed, 02 Apr 2014 20:43:54 -0000\r
83 \r
84 Quoth Tomi Ollila on Apr 02 at  7:43 pm:\r
85 > On Wed, Apr 02 2014, Austin Clements <amdragon@MIT.EDU> wrote:\r
86\r
87 > > Quoth David Bremner on Apr 01 at 10:16 pm:\r
88 > >> The idea is to provide a more or less drop in replacement for readline\r
89 > >> to read from zlib/gzip streams.  Take the opportunity to replace\r
90 > >> malloc with talloc.\r
91 > >> ---\r
92 > >>  util/Makefile.local |  2 +-\r
93 > >>  util/util.h         | 12 +++++++++\r
94 > >>  util/zlib-extra.c   | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++\r
95 > >>  util/zlib-extra.h   | 11 ++++++++\r
96 > >>  4 files changed, 100 insertions(+), 1 deletion(-)\r
97 > >>  create mode 100644 util/util.h\r
98 > >>  create mode 100644 util/zlib-extra.c\r
99 > >>  create mode 100644 util/zlib-extra.h\r
100 > >> \r
101 > >> diff --git a/util/Makefile.local b/util/Makefile.local\r
102 > >> index 29c0ce6..e2a5b65 100644\r
103 > >> --- a/util/Makefile.local\r
104 > >> +++ b/util/Makefile.local\r
105 > >> @@ -4,7 +4,7 @@ dir := util\r
106 > >>  extra_cflags += -I$(srcdir)/$(dir)\r
107 > >>  \r
108 > >>  libutil_c_srcs := $(dir)/xutil.c $(dir)/error_util.c $(dir)/hex-escape.c \\r
109 > >> -            $(dir)/string-util.c $(dir)/talloc-extra.c\r
110 > >> +            $(dir)/string-util.c $(dir)/talloc-extra.c $(dir)/zlib-extra.c\r
111 > >>  \r
112 > >>  libutil_modules := $(libutil_c_srcs:.c=.o)\r
113 > >>  \r
114 > >> diff --git a/util/util.h b/util/util.h\r
115 > >> new file mode 100644\r
116 > >> index 0000000..8663cfc\r
117 > >> --- /dev/null\r
118 > >> +++ b/util/util.h\r
119 > >> @@ -0,0 +1,12 @@\r
120 > >> +#ifndef _UTIL_H\r
121 > >> +#define _UTIL_H\r
122 > >> +\r
123 > >> +typedef enum util_status {\r
124 > >> +    UTIL_SUCCESS = 0,\r
125 > >> +    UTIL_ERROR = 1,\r
126 > >> +    UTIL_OUT_OF_MEMORY,\r
127 > >> +    UTIL_EOF,\r
128 > >> +    UTIL_FILE,\r
129 > >> +} util_status_t;\r
130 > >> +\r
131 > >> +#endif\r
132 > >> diff --git a/util/zlib-extra.c b/util/zlib-extra.c\r
133 > >> new file mode 100644\r
134 > >> index 0000000..cb1eba0\r
135 > >> --- /dev/null\r
136 > >> +++ b/util/zlib-extra.c\r
137 > >> @@ -0,0 +1,76 @@\r
138 > >> +/* zlib-extra.c -  Extra or enhanced routines for compressed I/O.\r
139 > >> + *\r
140 > >> + * Copyright (c) 2014 David Bremner\r
141 > >> + *\r
142 > >> + * This program is free software: you can redistribute it and/or modify\r
143 > >> + * it under the terms of the GNU General Public License as published by\r
144 > >> + * the Free Software Foundation, either version 3 of the License, or\r
145 > >> + * (at your option) any later version.\r
146 > >> + *\r
147 > >> + * This program is distributed in the hope that it will be useful,\r
148 > >> + * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
149 > >> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
150 > >> + * GNU General Public License for more details.\r
151 > >> + *\r
152 > >> + * You should have received a copy of the GNU General Public License\r
153 > >> + * along with this program.  If not, see http://www.gnu.org/licenses/ .\r
154 > >> + *\r
155 > >> + * Author: David Bremner <david@tethera.net>\r
156 > >> + */\r
157 > >> +\r
158 > >> +#include "zlib-extra.h"\r
159 > >> +#include <talloc.h>\r
160 > >> +#include <stdio.h>\r
161 > >> +#include <string.h>\r
162 > >> +\r
163 > >> +/* mimic POSIX/glibc getline, but on a zlib gzFile stream, and using talloc */\r
164 > >> +util_status_t\r
165 > >> +gz_getline (void *talloc_ctx, char **bufptr, size_t *bufsiz, ssize_t *bytes_read,\r
166 > >\r
167 > > Talloc chunks know their size, so rather than taking bufsize, use\r
168 > > talloc_get_size (or talloc_array_length if you switch to talloc array\r
169 > > functions below).\r
170\r
171 > Now yoy David have a chance to drop the bufsiz argument altogether, as the\r
172 > info is available in *bufptr:s talloc context...\r
173\r
174 > >\r
175 > >> +      gzFile stream)\r
176 > >> +{\r
177 > >> +    size_t len = *bufsiz;\r
178 > >> +    char *buf = *bufptr;\r
179 > >> +    size_t offset = 0;\r
180 > >> +\r
181 > >> +    if (len == 0 || buf == NULL) {\r
182 > >> +  /* same as getdelim from gnulib */\r
183 > >> +  len = 120;\r
184 > >\r
185 > > This is presumably because glibc's malloc has an 8 byte header.  Fun\r
186 > > fact: talloc has a 104 byte header (on 64-bit and including the malloc\r
187 > > header).\r
188\r
189 > hmm, what should we choose here? 152 ? Some bikeshedding on IRC ?\r
190 \r
191 How about we bikeshed about not bikeshedding about this?\r
192 \r
193 > >> +  buf = talloc_size (talloc_ctx, len);\r
194 > >> +  if (buf == NULL)\r
195 > >> +      return UTIL_OUT_OF_MEMORY;\r
196 > >> +    }\r
197 > >> +\r
198 > >> +    while (1) {\r
199 > >> +  if (! gzgets (stream, buf + offset, len - offset)) {\r
200 > >> +      int zlib_status = 0;\r
201 > >> +      (void) gzerror (stream, &zlib_status);\r
202 > >> +      switch (zlib_status) {\r
203 > >> +      case Z_OK:\r
204 > >> +          /* follow getline behaviour */\r
205 > >> +          *bytes_read = -1;\r
206 > >\r
207 > > Is this really what getline does when the last line of a file isn't\r
208 > > \n-terminated?\r
209\r
210 > Maybe the previous call returned non-\n -terminated string and\r
211 > for this call there was 0 bytes left to return ???\r
212 \r
213 But my point is that the previous call *won't* return a\r
214 non-\n-terminated string.  If my file looks like "a\nb\nc", this will\r
215 return "a\n", then "b\n", and then fail (unless I'm following the code\r
216 wrong).  This is *not* what getline does (the manpage is confusing,\r
217 but I just tested it).\r
218 \r
219 > Tomi\r
220\r
221 > >> +          return UTIL_EOF;\r
222 > >> +          break;\r
223 \r
224 Unnecessary break.\r
225 \r
226 > >> +      case Z_ERRNO:\r
227 > >> +          return UTIL_FILE;\r
228 > >> +          break;\r
229 \r
230 And here.\r
231 \r
232 > >> +      default:\r
233 > >> +          return UTIL_ERROR;\r
234 > >> +      }\r
235 > >> +  }\r
236 > >> +\r
237 > >> +  offset += strlen (buf + offset);\r
238 > >> +\r
239 > >> +  if ( buf[offset - 1] == '\n' )\r
240 > >\r
241 > > Too many spaces!\r
242 > >\r
243 > >> +      break;\r
244 > >> +\r
245 > >> +  len *= 2;\r
246 > >> +  buf = talloc_realloc (talloc_ctx, buf, char, len);\r
247 > >\r
248 > > Or talloc_realloc_size, to match the initial talloc_size.\r
249 > > Alternatively, the initial talloc_size could be a talloc_array.\r
250 > >\r
251 > >> +  if (buf == NULL)\r
252 > >> +      return UTIL_OUT_OF_MEMORY;\r
253 > >> +    }\r
254 > >> +\r
255 > >> +    *bufptr = buf;\r
256 > >> +    *bufsiz = len;\r
257 > >> +    *bytes_read = offset;\r
258 > >> +    return UTIL_SUCCESS;\r
259 > >> +}\r
260 > >> diff --git a/util/zlib-extra.h b/util/zlib-extra.h\r
261 > >> new file mode 100644\r
262 > >> index 0000000..ed46ac1\r
263 > >> --- /dev/null\r
264 > >> +++ b/util/zlib-extra.h\r
265 > >> @@ -0,0 +1,11 @@\r
266 > >> +#ifndef _ZLIB_EXTRA_H\r
267 > >> +#define _ZLIB_EXTRA_H\r
268 > >> +\r
269 > >> +#include <zlib.h>\r
270 > >> +#include "util.h"\r
271 > >\r
272 > > I'd put "util.h" first so we're more likely to catch missing header\r
273 > > dependencies (obviously util.h doesn't have any right now, but in the\r
274 > > future).\r
275 > >\r
276 > > Also, I'd put a blank line after the #includes.\r
277 > >\r
278 > >> +/* Like getline, but read from a gzFile. Allocation is with talloc */\r
279 > >> +util_status_t\r
280 > >> +gz_getline (void *ctx, char **lineptr, size_t *line_size, ssize_t *bytes_read,\r
281 > >> +      gzFile stream);\r
282 > >> +\r
283 > >> +#endif\r