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
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 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
37 Content-Type: text/plain
\r
38 X-BeenThere: notmuch@notmuchmail.org
\r
39 X-Mailman-Version: 2.1.13
\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
52 On Sun, Mar 30 2014, David Bremner <david@tethera.net> wrote:
\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
59 > This corrects one nasty bug, and a few style/optimization issues brought up by Tomi.
\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
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
70 > I'm also not sure about the error handling. the "real" getline sets
\r
73 In comparison with gzgets() return value
\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
80 "On error, gzgets() shall return Z_NULL.
\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
86 Rest of the style issues inline ;p
\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
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
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
109 > libutil_modules := $(libutil_c_srcs:.c=.o)
\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
115 > +++ b/util/zlib-extra.c
\r
117 > +/* zlib-extra.c - Extra or enhanced routines for compressed I/O.
\r
119 > + * Copyright (c) 2014 David Bremner
\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
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
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
134 > + * Author: David Bremner <david@tethera.net>
\r
137 > +#include "zlib-extra.h"
\r
138 > +#include <talloc.h>
\r
139 > +#include <stdio.h>
\r
140 > +#include <string.h>
\r
142 > +/* mimic POSIX/glibc getline, but on a zlib gzFile stream, and using talloc */
\r
144 > +gzgetline (void *ctx, char **lineptr, size_t *n, gzFile stream) {
\r
147 opening brace ({) starting function content to it's own line.
\r
149 > + size_t len = *n;
\r
150 > + char *buf = *lineptr;
\r
151 > + size_t offset = 0;
\r
153 > + if (len == 0 || buf == NULL) {
\r
154 > + /* same as getdelim from gnulib */
\r
156 > + buf = talloc_size (ctx, len);
\r
157 > + if (buf == NULL)
\r
166 > + if (!gzgets (stream, buf + offset, len - offset))
\r
172 > + offset += strlen (buf+offset);
\r
177 > + if ( buf[offset-1] == '\n' )
\r
184 > + buf = talloc_realloc (ctx, buf, char, len);
\r
185 > + if (buf == NULL)
\r
193 > + *lineptr = buf;
\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
201 > +++ b/util/zlib-extra.h
\r
203 > +#ifndef _ZLIB_EXTRA_H
\r
204 > +#define _ZLIB_EXTRA_H
\r
206 > +#include <zlib.h>
\r
208 > +/* Like getline, but read from a gzFile. Allocation is with talloc */
\r
210 > +gzgetline (void *ctx, char **lineptr, size_t *n, gzFile stream);
\r