Re: [PATCH v2 5/5] cli: lazily create the crypto gpg context only when needed
authorJameson Graef Rollins <jrollins@finestructure.net>
Fri, 18 May 2012 19:45:08 +0000 (12:45 +1700)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:47:14 +0000 (09:47 -0800)
ed/090a9e7ff87fb3da420431774c1b9cbec5cabd [new file with mode: 0644]

diff --git a/ed/090a9e7ff87fb3da420431774c1b9cbec5cabd b/ed/090a9e7ff87fb3da420431774c1b9cbec5cabd
new file mode 100644 (file)
index 0000000..d51c9a4
--- /dev/null
@@ -0,0 +1,136 @@
+Return-Path: <jrollins@finestructure.net>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 86CB4431FB6\r
+       for <notmuch@notmuchmail.org>; Fri, 18 May 2012 12:45:16 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -2.29\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-2.29 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_MED=-2.3, T_MIME_NO_TEXT=0.01] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id rROkj6zrb-U4 for <notmuch@notmuchmail.org>;\r
+       Fri, 18 May 2012 12:45:15 -0700 (PDT)\r
+Received: from outgoing-mail.its.caltech.edu (outgoing-mail.its.caltech.edu\r
+       [131.215.239.19])\r
+       by olra.theworths.org (Postfix) with ESMTP id 04677431FAE\r
+       for <notmuch@notmuchmail.org>; Fri, 18 May 2012 12:45:15 -0700 (PDT)\r
+Received: from fire-doxen.imss.caltech.edu (localhost [127.0.0.1])\r
+       by fire-doxen-postvirus (Postfix) with ESMTP id B78962E507A4;\r
+       Fri, 18 May 2012 12:45:14 -0700 (PDT)\r
+X-Spam-Scanned: at Caltech-IMSS on fire-doxen by amavisd-new\r
+Received: from finestructure.net (rrcs-24-103-26-131.nyc.biz.rr.com\r
+       [24.103.26.131]) (Authenticated sender: jrollins)\r
+       by fire-doxen-submit (Postfix) with ESMTP id A9C11328075;\r
+       Fri, 18 May 2012 12:45:11 -0700 (PDT)\r
+Received: by finestructure.net (Postfix, from userid 1000)\r
+       id 893574AD; Fri, 18 May 2012 12:45:10 -0700 (PDT)\r
+From: Jameson Graef Rollins <jrollins@finestructure.net>\r
+To: Austin Clements <amdragon@MIT.EDU>\r
+Subject: Re: [PATCH v2 5/5] cli: lazily create the crypto gpg context only\r
+       when needed\r
+In-Reply-To: <20120518192157.GV11804@mit.edu>\r
+References: <1337362357-31281-1-git-send-email-jrollins@finestructure.net>\r
+       <1337362357-31281-2-git-send-email-jrollins@finestructure.net>\r
+       <1337362357-31281-3-git-send-email-jrollins@finestructure.net>\r
+       <1337362357-31281-4-git-send-email-jrollins@finestructure.net>\r
+       <1337362357-31281-5-git-send-email-jrollins@finestructure.net>\r
+       <1337362357-31281-6-git-send-email-jrollins@finestructure.net>\r
+       <20120518192157.GV11804@mit.edu>\r
+User-Agent: Notmuch/0.12+183~g9d5ff3c (http://notmuchmail.org) Emacs/23.4.1\r
+       (x86_64-pc-linux-gnu)\r
+Date: Fri, 18 May 2012 12:45:08 -0700\r
+Message-ID: <87txzd9su3.fsf@servo.finestructure.net>\r
+MIME-Version: 1.0\r
+Content-Type: multipart/signed; boundary="=-=-=";\r
+       micalg=pgp-sha256; protocol="application/pgp-signature"\r
+Cc: Notmuch Mail <notmuch@notmuchmail.org>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Fri, 18 May 2012 19:45:16 -0000\r
+\r
+--=-=-=\r
+\r
+On Fri, May 18 2012, Austin Clements <amdragon@MIT.EDU> wrote:\r
+>> +    /* Lazily create the gpgctx if it's needed and hasn't been initialized yet */\r
+>> +    if ((GMIME_IS_MULTIPART_ENCRYPTED (part) || GMIME_IS_MULTIPART_SIGNED (part))\r
+>> +   && (node->ctx->crypto->verify || node->ctx->crypto->decrypt)) {\r
+>> +   if (!node->ctx->crypto->gpgctx) {\r
+>\r
+> These if conditions could be combined, like\r
+>\r
+>     if ((GMIME_IS_MULTIPART_ENCRYPTED (part) || GMIME_IS_MULTIPART_SIGNED (part))\r
+>      && (node->ctx->crypto->verify || node->ctx->crypto->decrypt)\r
+>      && !node->ctx->crypto->gpgctx) {\r
+>\r
+> When I see two nested 'if's like this, I expect there to be an else\r
+> part to the inner if or something after the inner if (why else would\r
+> it be separate?) and then I wind up matching braces when I don't see\r
+> anything.  Also, one 'if' would save a level of indentation.\r
+\r
+To explain what I was explaining on IRC, and what I should have noted in\r
+the original patch, I did this on purpose because I'm looking forward to\r
+the S/MIME support I was trying to get working.\r
+\r
+gmime 2.6 provides a separate context for pkcs7 (S/MIME).  In this\r
+context initialization section we will therefore have to test for\r
+initialization of the relevant context.  Since I knew that going into\r
+this I decided to anticipate it by constructing things this way now\r
+future diffs wouldn't have to include the indentation of this section\r
+and could therefore be cleaner and smaller.  If folks have issue with\r
+that explanation let me know.\r
+\r
+> Perhaps "If crypto->gpgctx is NULL, it will be lazily initialized."?\r
+> The variable does have to be "initialized", in the sense that it can't\r
+> be uninitialized data.\r
+\r
+That sounds like a better wording.  I'll fix.\r
+\r
+> It's slightly awkward that it's the caller's responsibility to free\r
+> this lazily constructed object.  That should probably be documented.\r
+> We could more carefully reference count it, but I think that would\r
+> actually be worse because the reference count would probably bounce\r
+> through zero frequently.\r
+\r
+I agree that this is awkward.  Is there a suggestion on how to do it\r
+better?  We only want to initialize it if it's needed, and only\r
+_mime_node_create knows that.  And we don't want to free it with\r
+_mime_node_context_free, or something, only to have to reinitialize it\r
+again with the next node or message.  Thoughts?\r
+\r
+jamie.\r
+\r
+--=-=-=\r
+Content-Type: application/pgp-signature\r
+\r
+-----BEGIN PGP SIGNATURE-----\r
+Version: GnuPG v1.4.12 (GNU/Linux)\r
+\r
+iQIcBAEBCAAGBQJPtqbEAAoJEO00zqvie6q8GOYP+wZO99ubAxHOriE9RK5KqZQM\r
+ATLxdRhZ9r1AElwTo7sZpyh1uAiprArjN9U7UM5BwZKICfXaaw7kJ9uNdQibdb2B\r
+m7DnPUtf4dFkUTHY0G4866evzUX2FehJwVHAmJ61mjlUtSNTqfkvgQ9aCBC0JuUS\r
+yNFxLrSFtn4tEI38PCMrG+rkjcJwcGA/6KA5yvipjjLrYSG+YWvvdFA0q26MUC9g\r
+oqycy0T4KminjofXckKoiGL/gs32i1u5AV8eORKBXDivbt6twU/aRnUucCIhqrMx\r
+RXUZad7OLTG2G/OLTrXs/pNjIl39DJYivzzh8+xLEYeL7EX0Tw85wwxxojLI/hvA\r
+xXRayU7R1pA3C8666OyA65uy22/Os/TSWYB2VmHqeIlgAt5I5bUGLaV6sKhN81Ho\r
+4QbBAh0Fs976EUdLwKhZsUQ5VqhJk8whB1mmoa9PtQw6/thiNV28BgCkM8DIxWOK\r
+DXDVkVmlbmUj93eYNYxqYaTncpQqX1cBEIlO/Mz+xON959kjwYRCS/D8yKXm6rZ9\r
+95HpztmcxBawjYhaErPtGwCGFGXBY4fs87Dx+8zLemgXRrNUPoWG/3lPfvBze+t2\r
+Ws4P7/9hO8aiqV9MMb7gQLqnE1xTNV9m5cT17aHe8klKVR8a1igyF2e8+3V3lpfH\r
+PZuNaT4xDaV9x0/SGvio\r
+=IZeH\r
+-----END PGP SIGNATURE-----\r
+--=-=-=--\r