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 54E73429E21 for ; Sun, 11 Sep 2011 19:15:54 -0700 (PDT) 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 TQgoo-7b5PFo for ; Sun, 11 Sep 2011 19:15:53 -0700 (PDT) Received: from dmz-mailsec-scanner-2.mit.edu (DMZ-MAILSEC-SCANNER-2.MIT.EDU [18.9.25.13]) by olra.theworths.org (Postfix) with ESMTP id C6D35431FB6 for ; Sun, 11 Sep 2011 19:15:53 -0700 (PDT) X-AuditID: 1209190d-b7be0ae000000a16-60-4e6d6a80d298 Received: from mailhub-auth-2.mit.edu ( [18.7.62.36]) by dmz-mailsec-scanner-2.mit.edu (Symantec Messaging Gateway) with SMTP id B8.33.02582.08A6D6E4; Sun, 11 Sep 2011 22:12:16 -0400 (EDT) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id p8C2Fp5c025263; Sun, 11 Sep 2011 22:15:51 -0400 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 p8C2Fnhw020305 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Sun, 11 Sep 2011 22:15:50 -0400 (EDT) Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.72) (envelope-from ) id 1R2w6E-0000Vj-Vc; Sun, 11 Sep 2011 22:18:18 -0400 Date: Sun, 11 Sep 2011 22:18:18 -0400 From: Austin Clements To: Ben Gamari Subject: Re: Memory management practices Message-ID: <20110912021818.GD23603@mit.edu> References: <20110829183010.GA2605@24f89f8c-e6a1-4e75-85ee-bb8a3743bb9f> <87liucyn7i.fsf@gmail.com> <87aaag3xaf.fsf@gmail.com> <87zkiff8in.fsf@SSpaeth.de> <20110908151557.GM5688@mit.edu> <8762l22hgk.fsf@SSpaeth.de> <20110909175328.GV5688@mit.edu> <87d3f64ups.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87d3f64ups.fsf@gmail.com> User-Agent: Mutt/1.5.20 (2009-06-14) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrOKsWRmVeSWpSXmKPExsUixG6notuQletn0LBT2aLx7z0mi5lP9jJb LF8lZXHz5xw2i+s3ZzJbzJozj9GBzeP16mmsHrs3P2Dx2DnrLrvH0wmT2T2erbrF7LH4y1KW ALYoLpuU1JzMstQifbsErowlnxrYCw4IVhxbPYWpgXETXxcjJ4eEgInEtB9v2CFsMYkL99az gdhCAvsYJe6ctuti5AKyNzBKzFn5hRXCOckksXPNL0YIZwmjxNxve5lBWlgEVCUutx8Gs9kE NCS27V/OCGKLCKhL7H07jw2kgVngJqPE5hP9YEXCQEUzH3SD7eMV0JF4N3cT1O61zBJzJpVB xAUlTs58wgJiMwtoSdz495Kpi5EDyJaWWP6PAyTMCTT/17J2sBJRARWJa/vb2SYwCs1C0j0L SfcshO4FjMyrGGVTcqt0cxMzc4pTk3WLkxPz8lKLdI30cjNL9FJTSjcxguKEU5J3B+O7g0qH GAU4GJV4eFfeyPETYk0sK67MPcQoycGkJMpbCowyIb6k/JTKjMTijPii0pzU4kOMEhzMSiK8 DXpA5bwpiZVVqUX5MClpDhYlcd7CHQ5+QgLpiSWp2ampBalFMFkZDg4lCd6tIEMFi1LTUyvS MnNKENJMHJwgw3mAhm8CqeEtLkjMLc5Mh8ifYtTlOL/2+nFGIZa8/LxUKXHeFpAiAZCijNI8 uDmw9PaKURzoLWHejSBVPMDUCDfpFdASJqAlAdszQZaUJCKkpBoYy6b9fDFP9PV0/f++kb4P a2Yuao+1eXdF7FXH90WGT0M5Nt36NaU/5mJ7gLBwASvbs0Ces7f3zXAOMborWvSgQr/t2IX0 k0eS8zcynLNU4Up7aOL8orLBrGKKf+Hl5Gmiiqsv1eYXndiY57bfkMFlamS5+pfUOSLvdDmf HZyY6cX3cMMpqVvySizFGYmGWsxFxYkA8KxBBUoDAAA= Cc: Bertram Felgenhauer , Bart Massey , notmuch 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: Mon, 12 Sep 2011 02:15:54 -0000 Quoth Ben Gamari on Sep 11 at 5:47 pm: > Sorry I've been so quiet on this recently. I've been a little under the > weather. No worries. > On Fri, 9 Sep 2011 13:53:28 -0400, Austin Clements wrote: > > Hence my suggestion that, rather than trying to emulate C-style memory > > management in bindings, bindings should create an additional talloc > > reference to the underlying objects and rather than calling > > notmuch_*_destroy during finalization, they should simply unlink this > > additional reference. > > Currently talloc's reference counting interface is hidden behind > _destroy. While this might be a fairly intrusive change, perhaps notmuch > wants to juse expose a pair of reference counting *_ref/unref functions > instead of the *_destroy. Most users would simply need to change > existing *_destroy()s to _unref()s. Furthermore, this would allow > bindings authors to easily ensure non-broken GC behavior. I think the _destroy functions are silly. They all just call talloc_free and, indeed, it would arguably be incorrect for them to do anything more (any additional cleanup should be in a talloc destructor). talloc is never explicitly mentioned in lib/notmuch.h (intentionally, I would assume) but talloc-style notions of "ownership" pervade the library documentation. IMO, the library should just admit to using talloc, rather than try to wrap all of the not-insubstantial talloc functionality a caller may need. In the language of talloc, it's very natural to express the needs of bindings in terms talloc_reference and talloc_unlink. The bindings could maintain a per-Database context and track their own ownership by adding a talloc reference from this context to each object returned from the bindings; the finalizer would simply unlink the finalized object from this context. Bindings could also use a global context (though that would obviously be awkward in Haskell without biting the unsafePerformIO bullet). Alternatively, bindings could use the NULL context, which has the advantage of not actually tracking ownership in talloc, but the disadvantage of making it harder to track down bugs (since any code can reference or unlink from NULL).