From 715c04e1f7cb032c9c733a053b2e3fb4e5324105 Mon Sep 17 00:00:00 2001 From: Daniel Kahn Gillmor Date: Sat, 19 May 2012 16:37:09 +2000 Subject: [PATCH] Re: [PATCH v2 5/5] cli: lazily create the crypto gpg context only when needed --- 8b/a2158e62fe27a6d22ce1e51b386aa738dd7930 | 130 ++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 8b/a2158e62fe27a6d22ce1e51b386aa738dd7930 diff --git a/8b/a2158e62fe27a6d22ce1e51b386aa738dd7930 b/8b/a2158e62fe27a6d22ce1e51b386aa738dd7930 new file mode 100644 index 000000000..fb94a5575 --- /dev/null +++ b/8b/a2158e62fe27a6d22ce1e51b386aa738dd7930 @@ -0,0 +1,130 @@ +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 E0271431FB6 + for ; Fri, 18 May 2012 13:37:19 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0 +X-Spam-Level: +X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] + 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 GuKB1eiofPX8 for ; + Fri, 18 May 2012 13:37:19 -0700 (PDT) +Received: from che.mayfirst.org (che.mayfirst.org [209.234.253.108]) + by olra.theworths.org (Postfix) with ESMTP id 53809431FAE + for ; Fri, 18 May 2012 13:37:19 -0700 (PDT) +Received: from [192.168.23.207] (dsl254-070-154.nyc1.dsl.speakeasy.net + [216.254.70.154]) + by che.mayfirst.org (Postfix) with ESMTPSA id E0385F970 + for ; Fri, 18 May 2012 16:37:14 -0400 (EDT) +Message-ID: <4FB6B2F5.6090105@fifthhorseman.net> +Date: Fri, 18 May 2012 16:37:09 -0400 +From: Daniel Kahn Gillmor +User-Agent: Mozilla/5.0 (X11; Linux i686; + rv:10.0.3) Gecko/20120329 Icedove/10.0.3 +MIME-Version: 1.0 +To: Notmuch Mail +Subject: Re: [PATCH v2 5/5] cli: lazily create the crypto gpg context only + when needed +References: <1337362357-31281-1-git-send-email-jrollins@finestructure.net> + <1337362357-31281-2-git-send-email-jrollins@finestructure.net> + <1337362357-31281-3-git-send-email-jrollins@finestructure.net> + <1337362357-31281-4-git-send-email-jrollins@finestructure.net> + <1337362357-31281-5-git-send-email-jrollins@finestructure.net> + <1337362357-31281-6-git-send-email-jrollins@finestructure.net> + <20120518192157.GV11804@mit.edu> + <87txzd9su3.fsf@servo.finestructure.net> +In-Reply-To: <87txzd9su3.fsf@servo.finestructure.net> +X-Enigmail-Version: 1.4.1 +Content-Type: multipart/signed; micalg=pgp-sha512; + protocol="application/pgp-signature"; + boundary="------------enig95E528317834EF181F89AF5F" +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +Reply-To: notmuch +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Fri, 18 May 2012 20:37:20 -0000 + +This is an OpenPGP/MIME signed message (RFC 2440 and 3156) +--------------enig95E528317834EF181F89AF5F +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: quoted-printable + +On 05/18/2012 03:45 PM, Jameson Graef Rollins wrote: +> On Fri, May 18 2012, Austin Clements wrote: +>> It's slightly awkward that it's the caller's responsibility to free +>> this lazily constructed object. That should probably be documented. +>> We could more carefully reference count it, but I think that would +>> actually be worse because the reference count would probably bounce +>> through zero frequently. +>=20 +> I agree that this is awkward. Is there a suggestion on how to do it +> better? We only want to initialize it if it's needed, and only +> _mime_node_create knows that. And we don't want to free it with +> _mime_node_context_free, or something, only to have to reinitialize it +> again with the next node or message. Thoughts? + +You could provide a "destructor" function for notmuch_crypto_t, which +whoever is responsible for the struct would need to call when they are +ready to dispose of it. + +The destructor would just destroy any GMIME crypto contexts pointed to +by the struct, and reset those pointers to NULL. + +Since the common workflow is a singleton notmuch_crypto_t that is a +subobject of the singleton notmuch_params_t, you could just call that +destructor function before the notmuch_params_t falls out of scope. + +If you want to be fancy/symmetric, you could use the same pattern to +create a "destructor" function for notmuch_params_t (it would just +invoke the destructor on its crypto member), but this seems like +overkill to me, and not in line with the talloc approach of the rest of +the codebase. + +I agree that it's a little awkward, but i think there's something of an +impedance mismatch between gmime's object interface and notmuch's use of +talloc and friends. + + --dkg + + +--------------enig95E528317834EF181F89AF5F +Content-Type: application/pgp-signature; name="signature.asc" +Content-Description: OpenPGP digital signature +Content-Disposition: attachment; filename="signature.asc" + +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.4.12 (GNU/Linux) +Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ + +iQJ8BAEBCgBmBQJPtrL1XxSAAAAAAC4AKGlzc3Vlci1mcHJAbm90YXRpb25zLm9w +ZW5wZ3AuZmlmdGhob3JzZW1hbi5uZXQwRUU1QkU5NzkyODJEODBCOUY3NTQwRjFD +Q0QyRUQ5NEQyMTczOUU5AAoJEMzS7ZTSFznpm0gQAKXRfjkE3yzlbGVGfOj8HzP4 +nLHpm5fmPUkd6cZegq51a21lNHkO02zKGQonPHO2mUQHnZ3616sdK/BqBiBebB8b +sXWwl+d2n8OOnxNh9L/I4ihSL5mn86+fC6eTR/TVQjVE7jKSdkK0pRSbZUN8atYd +JirQ2TyyqUr4IVaD3RGHdeOU/cAPbPLjbS7YcdRep0ImfFSADZmvZE1weImy721S +0v4otH87fim5trf3tBIpJqFFfgXMMxmlw+L2xFGGewdnEwliB8v0se+pTJiABjHW +u8l3EUU5Y7GRzjv3RoLLdUooergHQi2I9Z+AZK1fcVwWicxLhVWIXuOcJ4KpknNi +MCuN5+S+EGCvK8lcfbUyy5UiDm5fF270xR/mAeTbm2/hQ3Y+MAFRuhT4ZZIlpMOP +Ldzk92B/zSh4mxRCZtoi6lLnRsd6B3GP2VRlHs5caKXG3weQhGTQIO7QmpcIcAFf +Rp+eH83OgaTQ2UEmzfQLVMlenF+NBykurRJ2//bC7kHbliMj0NKp5DqRnWChjLiB +oBBE4CMjkPYCX1PWnS/XJhwL/DZAvPNTghqIDq3hcAZRu13Hc0xXpIAUTx3lYOfc +TCPamfMs1ZhogJDjNOfhhRo+KQgjPKpR2HIDn2VU3xMlTHG7PquuLY2WkqPoYAsP +dBw+rfzJywAASGm1WxtC +=W4+Y +-----END PGP SIGNATURE----- + +--------------enig95E528317834EF181F89AF5F-- -- 2.26.2