Re: [PATCH] NEWS: initial NEWS for 0.22.1
[notmuch-archives.git] / 98 / ce3445bf29489f08a4f91824b9562d2f9e29a8
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 29422431FBC\r
6         for <notmuch@notmuchmail.org>; Sun, 30 Mar 2014 05:45:45 -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\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 U0qQ6iKf7FeU for <notmuch@notmuchmail.org>;\r
16         Sun, 30 Mar 2014 05:45:31 -0700 (PDT)\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 84412431FB6\r
19         for <notmuch@notmuchmail.org>; Sun, 30 Mar 2014 05:45:31 -0700 (PDT)\r
20 Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
21         by guru.guru-group.fi (Postfix) with ESMTP id D4F5310005E;\r
22         Sun, 30 Mar 2014 15:45:21 +0300 (EEST)\r
23 From: Tomi Ollila <tomi.ollila@iki.fi>\r
24 To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org\r
25 Subject: Re: [Patch v3] util: add gzreadline\r
26 In-Reply-To: <1396178602-7583-1-git-send-email-david@tethera.net>\r
27 References: <m2zjk8um02.fsf@guru.guru-group.fi>\r
28         <1396178602-7583-1-git-send-email-david@tethera.net>\r
29 User-Agent: Notmuch/0.17+171~g9a127b7 (http://notmuchmail.org) Emacs/24.3.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: Sun, 30 Mar 2014 15:45:21 +0300\r
35 Message-ID: <m2txafvori.fsf@guru.guru-group.fi>\r
36 MIME-Version: 1.0\r
37 Content-Type: text/plain\r
38 X-BeenThere: notmuch@notmuchmail.org\r
39 X-Mailman-Version: 2.1.13\r
40 Precedence: list\r
41 List-Id: "Use and development of the notmuch mail system."\r
42         <notmuch.notmuchmail.org>\r
43 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
44         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
46 List-Post: <mailto:notmuch@notmuchmail.org>\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
48 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
49         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
50 X-List-Received-Date: Sun, 30 Mar 2014 12:45:45 -0000\r
51 \r
52 On Sun, Mar 30 2014, David Bremner <david@tethera.net> wrote:\r
53 \r
54 > The idea is to provide a more or less drop in replacement for readline\r
55 > to read from zlib/gzip streams.  Take the opportunity to replace\r
56 > malloc with talloc.\r
57 > ---\r
58 >\r
59 > This corrects one nasty bug, and a few style/optimization issues brought up by Tomi.\r
60 >\r
61 > I'm not sure about the name. I agree in principle it would be good to\r
62 > signal "talloc". I'm just not sure the best way to do that.\r
63 \r
64 how about just gz_getline(). If there were gzgetline() one would expect it's\r
65 function "signature" be gzgetline(char **lineptr, size_t *m gzFile *stream);\r
66 (consistent with other '' -> gz'' conversions). for gz_getline() there\r
67 would be no expectations.\r
68 \r
69 >\r
70 > I'm also not sure about the error handling. the "real" getline sets\r
71 > errno. Should we?\r
72 \r
73 In comparison with gzgets() return value\r
74 \r
75 "On success, gzgets() shall return a pointer to buf. Otherwise, gzgets()\r
76 "shall return Z_NULL. Applications may examine the cause using gzerror().\r
77 "\r
78 "Errors\r
79 "\r
80 "On error, gzgets() shall return Z_NULL.\r
81 \r
82 In light of this I'd say no. can we set out-of-memory using some public\r
83 api so it is available using gzerror()\r
84 \r
85 \r
86 Rest of the style issues inline ;p\r
87 \r
88 Tomi\r
89 \r
90 >\r
91 >  util/Makefile.local |  2 +-\r
92 >  util/zlib-extra.c   | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++\r
93 >  util/zlib-extra.h   | 10 +++++++++\r
94 >  3 files changed, 73 insertions(+), 1 deletion(-)\r
95 >  create mode 100644 util/zlib-extra.c\r
96 >  create mode 100644 util/zlib-extra.h\r
97 >\r
98 > diff --git a/util/Makefile.local b/util/Makefile.local\r
99 > index 29c0ce6..e2a5b65 100644\r
100 > --- a/util/Makefile.local\r
101 > +++ b/util/Makefile.local\r
102 > @@ -4,7 +4,7 @@ dir := util\r
103 >  extra_cflags += -I$(srcdir)/$(dir)\r
104 >  \r
105 >  libutil_c_srcs := $(dir)/xutil.c $(dir)/error_util.c $(dir)/hex-escape.c \\r
106 > -               $(dir)/string-util.c $(dir)/talloc-extra.c\r
107 > +               $(dir)/string-util.c $(dir)/talloc-extra.c $(dir)/zlib-extra.c\r
108 >  \r
109 >  libutil_modules := $(libutil_c_srcs:.c=.o)\r
110 >  \r
111 > diff --git a/util/zlib-extra.c b/util/zlib-extra.c\r
112 > new file mode 100644\r
113 > index 0000000..7afe175\r
114 > --- /dev/null\r
115 > +++ b/util/zlib-extra.c\r
116 > @@ -0,0 +1,62 @@\r
117 > +/* zlib-extra.c -  Extra or enhanced routines for compressed I/O.\r
118 > + *\r
119 > + * Copyright (c) 2014 David Bremner\r
120 > + *\r
121 > + * This program is free software: you can redistribute it and/or modify\r
122 > + * it under the terms of the GNU General Public License as published by\r
123 > + * the Free Software Foundation, either version 3 of the License, or\r
124 > + * (at your option) any later version.\r
125 > + *\r
126 > + * This program is distributed in the hope that it will be useful,\r
127 > + * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
128 > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
129 > + * GNU General Public License for more details.\r
130 > + *\r
131 > + * You should have received a copy of the GNU General Public License\r
132 > + * along with this program.  If not, see http://www.gnu.org/licenses/ .\r
133 > + *\r
134 > + * Author: David Bremner <david@tethera.net>\r
135 > + */\r
136 > +\r
137 > +#include "zlib-extra.h"\r
138 > +#include <talloc.h>\r
139 > +#include <stdio.h>\r
140 > +#include <string.h>\r
141 > +\r
142 > +/* mimic POSIX/glibc getline, but on a zlib gzFile stream, and using talloc */\r
143 > +ssize_t\r
144 > +gzgetline (void *ctx, char **lineptr, size_t *n, gzFile stream) {\r
145 > +\r
146 \r
147 opening brace ({) starting function content to it's own line.\r
148 \r
149 > +    size_t len = *n;\r
150 > +    char *buf = *lineptr;\r
151 > +    size_t offset = 0;\r
152 > +\r
153 > +    if (len == 0 || buf == NULL) {\r
154 > +     /* same as getdelim from gnulib */\r
155 > +     len = 120;\r
156 > +     buf = talloc_size (ctx, len);\r
157 > +     if (buf == NULL)\r
158 > +         return -1;\r
159 > +    }\r
160 > +\r
161 > +    while (1) {\r
162 > +\r
163 \r
164 extra empty line ?\r
165 \r
166 > +     if (!gzgets (stream, buf + offset, len - offset))\r
167 \r
168 ! gzgets\r
169 \r
170 > +         return -1;\r
171 > +\r
172 > +     offset += strlen (buf+offset);\r
173 \r
174 (buf + offset)\r
175 \r
176 > +\r
177 > +     if ( buf[offset-1] == '\n' )\r
178 \r
179 [ offset - 1 ]\r
180 \r
181 > +         break;\r
182 > +\r
183 > +     len *= 2;\r
184 > +     buf = talloc_realloc (ctx, buf, char, len);\r
185 > +     if (buf == NULL)\r
186 > +         return -1;\r
187 > +\r
188 \r
189 extra empty line\r
190 \r
191 > +    }\r
192 > +\r
193 > +    *lineptr = buf;\r
194 > +    *n = len;\r
195 > +    return offset;\r
196 > +}\r
197 > diff --git a/util/zlib-extra.h b/util/zlib-extra.h\r
198 > new file mode 100644\r
199 > index 0000000..c18480f\r
200 > --- /dev/null\r
201 > +++ b/util/zlib-extra.h\r
202 > @@ -0,0 +1,10 @@\r
203 > +#ifndef _ZLIB_EXTRA_H\r
204 > +#define _ZLIB_EXTRA_H\r
205 > +\r
206 > +#include <zlib.h>\r
207 > +\r
208 > +/* Like getline, but read from a gzFile. Allocation is with talloc */\r
209 > +ssize_t\r
210 > +gzgetline (void *ctx, char **lineptr, size_t *n, gzFile stream);\r
211 > +\r
212 > +#endif\r
213 > -- \r
214 > 1.9.0\r