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 57A0B431FB6 for ; Sun, 11 Sep 2011 14:47:49 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.799 X-Spam-Level: X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, 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 Qs6EwthdpVYV for ; Sun, 11 Sep 2011 14:47:48 -0700 (PDT) Received: from mail-vw0-f44.google.com (mail-vw0-f44.google.com [209.85.212.44]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id BACE8429E21 for ; Sun, 11 Sep 2011 14:47:48 -0700 (PDT) Received: by vws12 with SMTP id 12so2829483vws.3 for ; Sun, 11 Sep 2011 14:47:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:in-reply-to:references:user-agent:date :message-id:mime-version:content-type; bh=TKAtd3qeroIGcutLccDGPMqBDsvS7d6ea0SAL3Wd8Os=; b=gxJZeJtWKrPGWaZO6xckhZol+0BjDu/1/JJ35mB4krDEXR63L4oCEMz7K0Iarn54jh E28sOMEb9GuBY2aLXEQPH7lvsvWIwVAqNyO3xybpY1skWhAqkP+eLYLrP4o1vPgEg/Wy F7aqo/fKdJG12hQbReZwo+UyIEqmw1M1r6VJo= Received: by 10.52.27.239 with SMTP id w15mr278036vdg.333.1315777667893; Sun, 11 Sep 2011 14:47:47 -0700 (PDT) Received: from localhost ([72.19.95.214]) by mx.google.com with ESMTPS id by14sm9088735vdb.22.2011.09.11.14.47.44 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 11 Sep 2011 14:47:45 -0700 (PDT) From: Ben Gamari To: Austin Clements , Sebastian Spaeth , Carl Worth Subject: Re: Memory management practices In-Reply-To: <20110909175328.GV5688@mit.edu> References: <8739h1pbaq.fsf@gmail.com> <87pqjprzu2.fsf@gmail.com> <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> User-Agent: Notmuch/0.7-37-g5c3c7f6 (http://notmuchmail.org) Emacs/23.2.1 (x86_64-pc-linux-gnu) Date: Sun, 11 Sep 2011 17:47:43 -0400 Message-ID: <87d3f64ups.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Bertram Felgenhauer , notmuch , Bart Massey 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: Sun, 11 Sep 2011 21:47:49 -0000 Sorry I've been so quiet on this recently. I've been a little under the weather. On Fri, 9 Sep 2011 13:53:28 -0400, Austin Clements wrote: > Ah, the *Python* objects don't care, but the underlying C objects do. > Suppose the Query were finalized first. Python calls Query.__del__, > which calls notmuch_query_destroy, which releases the underlying > talloc references to the C notmuch_messages_t objects, causing talloc > to free the notmuch_messages_t. Messages._msgs now points to freed > memory, so when Python then finalizes the Messages object, > Messages.__del__ will pass this dangling pointer to > notmuch_messages_destroy, which will crash. Exactly. This is exactly what I suspect is happening in my case. > > 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. Does this sound completely insane, somewhat insane, or reasonable? Cheers, - Ben