Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id BC6CC431FAF for ; Wed, 18 Jan 2012 18:24:07 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id CTxMdQQHg9Mg for ; Wed, 18 Jan 2012 18:24:07 -0800 (PST) Received: from dmz-mailsec-scanner-8.mit.edu (DMZ-MAILSEC-SCANNER-8.MIT.EDU [18.7.68.37]) by olra.theworths.org (Postfix) with ESMTP id F307D431FAE for ; Wed, 18 Jan 2012 18:24:06 -0800 (PST) X-AuditID: 12074425-b7f4a6d0000008e0-ac-4f177ec508ca Received: from mailhub-auth-3.mit.edu ( [18.9.21.43]) by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP id EF.DA.02272.5CE771F4; Wed, 18 Jan 2012 21:24:05 -0500 (EST) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id q0J2O4Xu023561; Wed, 18 Jan 2012 21:24:04 -0500 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q0J2O3Ie004223 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Wed, 18 Jan 2012 21:24:04 -0500 (EST) Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77) (envelope-from ) id 1RnhfI-00028F-2x; Wed, 18 Jan 2012 21:23:48 -0500 Date: Wed, 18 Jan 2012 21:23:48 -0500 From: Austin Clements To: Jani Nikula Subject: Re: [PATCH 3/3] show: Introduce mime_node formatter callback Message-ID: <20120119022348.GK16740@mit.edu> References: <1326918507-28033-1-git-send-email-amdragon@mit.edu> <1326918507-28033-4-git-send-email-amdragon@mit.edu> <87wr8obpyv.fsf@nikula.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87wr8obpyv.fsf@nikula.org> User-Agent: Mutt/1.5.21 (2010-09-15) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprHKsWRmVeSWpSXmKPExsUixCmqrXu0TtzfoP2xpkVr92cmi6tb+9kt mqY7W+zZ52Vx/eZMZgdWj7Pd7awed09zeeycdZfd49b91+wez1bdYg5gjeKySUnNySxLLdK3 S+DK6P/Wxl6wRaXi4vufTA2Me6S7GDk5JARMJG4/X8oGYYtJXLi3Hsjm4hAS2McosazlLQuE s4FR4syGXlYI5ySTxNYXpxghnCWMEutv3mMC6WcRUJVoaZ/EDmKzCWhIbNu/nBHEFhFQlNh8 cj+QzcHBLFAs0fOxCsQUFnCVWPtBFaSCV0BHYs+clewQI6cyStz4d4INIiEocXLmExYQm1lA Cyj+kglijLTE8n8cIGFOoE0bvr9kBrFFBVQkppzcxjaBUWgWku5ZSLpnIXQvYGRexSibklul m5uYmVOcmqxbnJyYl5dapGuhl5tZopeaUrqJERQN7C6qOxgnHFI6xCjAwajEwxshIu4vxJpY VlyZe4hRkoNJSZT3QDVQiC8pP6UyI7E4I76oNCe1+BCjBAezkgjvThOgHG9KYmVValE+TEqa g0VJnFdT652fkEB6YklqdmpqQWoRTFaGg0NJgreiBqhRsCg1PbUiLTOnBCHNxMEJMpwHaPgd kMW8xQWJucWZ6RD5U4yKUuK8VsB0IyQAksgozYPrhSWrV4ziQK8I856oBariASY6uO5XQIOZ gAZ7NImBDC5JREhJNTAuzl3vmiz8z0bR/ZZsbfLKsg2v/+8LV9J36zOMnvX/e9eOBY2Tjefx SM5+9HHi+Zm76iVtwwrnVUVuP1F8SnE/g+2vV1MVpynPX3Wc81KB+AfXQxOvdHDqpmd7RaVN 1yu08RXXtv5rZvlto6asj9hsV1vFFKuPAWdWsk6edvNNbo1Ajeo8179KLMUZiYZazEXFiQDQ aoPjMQMAAA== Cc: notmuch@notmuchmail.org, dkg@fifthhorseman.net X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Jan 2012 02:24:07 -0000 Quoth Jani Nikula on Jan 19 at 12:33 am: > On Wed, 18 Jan 2012 15:28:27 -0500, Austin Clements wrote: > > This callback is the gateway to the new mime_node_t-based formatters. > > This maintains backwards compatibility so the formatters can be > > transitioned one at a time. Once all formatters are converted, the > > formatter structure can be reduced to only message_set_{start,sep,end} > > and part, most of show_message can be deleted, and all of > > show-message.c can be deleted. > > --- > > notmuch-client.h | 6 ++++++ > > notmuch-reply.c | 2 +- > > notmuch-show.c | 22 ++++++++++++++++++---- > > 3 files changed, 25 insertions(+), 5 deletions(-) > > > > diff --git a/notmuch-client.h b/notmuch-client.h > > index b3dcb6b..3ccdfad 100644 > > --- a/notmuch-client.h > > +++ b/notmuch-client.h > > @@ -54,8 +54,14 @@ > > #define STRINGIFY(s) STRINGIFY_(s) > > #define STRINGIFY_(s) #s > > > > +struct mime_node; > > +struct notmuch_show_params; > > + > > typedef struct notmuch_show_format { > > const char *message_set_start; > > + void (*part) (const void *ctx, > > + struct mime_node *node, int indent, > > + struct notmuch_show_params *params); > > const char *message_start; > > void (*message) (const void *ctx, > > notmuch_message_t *message, > > diff --git a/notmuch-reply.c b/notmuch-reply.c > > index 0f682db..9a224e2 100644 > > --- a/notmuch-reply.c > > +++ b/notmuch-reply.c > > @@ -31,7 +31,7 @@ static void > > reply_part_content (GMimeObject *part); > > > > static const notmuch_show_format_t format_reply = { > > - "", > > + "", NULL, > > "", NULL, > > "", NULL, reply_headers_message_part, ">\n", > > "", > > diff --git a/notmuch-show.c b/notmuch-show.c > > index ecadfa8..46eef44 100644 > > --- a/notmuch-show.c > > +++ b/notmuch-show.c > > @@ -42,7 +42,7 @@ static void > > format_part_end_text (GMimeObject *part); > > > > static const notmuch_show_format_t format_text = { > > - "", > > + "", NULL, > > "\fmessage{ ", format_message_text, > > "\fheader{\n", format_headers_text, format_headers_message_part_text, "\fheader}\n", > > "\fbody{\n", > > @@ -85,7 +85,7 @@ static void > > format_part_end_json (GMimeObject *part); > > > > static const notmuch_show_format_t format_json = { > > - "[", > > + "[", NULL, > > "{", format_message_json, > > "\"headers\": {", format_headers_json, format_headers_message_part_json, "}", > > ", \"body\": [", > > @@ -106,7 +106,7 @@ format_message_mbox (const void *ctx, > > unused (int indent)); > > > > static const notmuch_show_format_t format_mbox = { > > - "", > > + "", NULL, > > "", format_message_mbox, > > "", NULL, NULL, "", > > "", > > @@ -125,7 +125,7 @@ static void > > format_part_content_raw (GMimeObject *part); > > > > static const notmuch_show_format_t format_raw = { > > - "", > > + "", NULL, > > "", NULL, > > "", NULL, format_headers_message_part_text, "\n", > > "", > > @@ -762,6 +762,20 @@ show_message (void *ctx, > > int indent, > > notmuch_show_params_t *params) > > { > > + if (format->part) { > > + void *local = talloc_new (ctx); > > + mime_node_t *root, *part; > > + > > + if (mime_node_open (local, message, params->cryptoctx, params->decrypt, > > + &root) != NOTMUCH_STATUS_SUCCESS) > > I'm new to talloc, I think I like it, but I always find it confusing > when some code paths free the contexts, and some don't. Like here. > > Are you not freeing the local context here because it's just an empty > context, and freeing below because it's no longer empty? No, that's just a bug. In practice it probably doesn't matter much because, as you pointed out, the local context consumes very little memory and since the caller will eventually free ctx, local will get cleaned up, too. So, while this isn't strictly a memory leak, in principle this could add up before ctx gets freed. Fixed. > No need to change anything, I guess, just asking... I wait a little for other comments and then send a new version. Thanks for the review! > BR, > Jani. > > > + return; > > + part = mime_node_seek_dfs (root, params->part < 0 ? 0 : params->part); > > + if (part) > > + format->part (local, part, indent, params); > > + talloc_free (local); > > + return; > > + } > > + > > if (params->part <= 0) { > > fputs (format->message_start, stdout); > > if (format->message)