From 700c576a3a20c0ae9b06ef5a9e9a885587b7e8a0 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Fri, 13 Apr 2012 13:02:49 +2000 Subject: [PATCH] Re: [PATCH 7/7] python: wrap and use notmuch_database_destroy as destructor --- 13/7cc1c376fcfcc0d310e7d86d514bee2af96a14 | 131 ++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 13/7cc1c376fcfcc0d310e7d86d514bee2af96a14 diff --git a/13/7cc1c376fcfcc0d310e7d86d514bee2af96a14 b/13/7cc1c376fcfcc0d310e7d86d514bee2af96a14 new file mode 100644 index 000000000..de4e7fd8d --- /dev/null +++ b/13/7cc1c376fcfcc0d310e7d86d514bee2af96a14 @@ -0,0 +1,131 @@ +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 75F6E431FB6 + for ; Thu, 12 Apr 2012 10:02:52 -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 MdwwPoKJOapV for ; + Thu, 12 Apr 2012 10:02:52 -0700 (PDT) +Received: from dmz-mailsec-scanner-1.mit.edu (DMZ-MAILSEC-SCANNER-1.MIT.EDU + [18.9.25.12]) + by olra.theworths.org (Postfix) with ESMTP id CE41B431FAE + for ; Thu, 12 Apr 2012 10:02:51 -0700 (PDT) +X-AuditID: 1209190c-b7fad6d000000920-26-4f870abbf7eb +Received: from mailhub-auth-1.mit.edu ( [18.9.21.35]) + by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP + id 47.58.02336.BBA078F4; Thu, 12 Apr 2012 13:02:51 -0400 (EDT) +Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) + by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id q3CH2pIU022054; + Thu, 12 Apr 2012 13:02: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 q3CH2neS025675 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Thu, 12 Apr 2012 13:02:50 -0400 (EDT) +Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77) + (envelope-from ) + id 1SINQ1-0004JP-M2; Thu, 12 Apr 2012 13:02:49 -0400 +Date: Thu, 12 Apr 2012 13:02:49 -0400 +From: Austin Clements +To: Justus Winter <4winter@informatik.uni-hamburg.de> +Subject: Re: [PATCH 7/7] python: wrap and use notmuch_database_destroy as + destructor +Message-ID: <20120412170249.GG13549@mit.edu> +References: + <1332291311-28954-1-git-send-email-4winter@informatik.uni-hamburg.de> + <1332291311-28954-8-git-send-email-4winter@informatik.uni-hamburg.de> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: + <1332291311-28954-8-git-send-email-4winter@informatik.uni-hamburg.de> +User-Agent: Mutt/1.5.21 (2010-09-15) +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFmphleLIzCtJLcpLzFFi42IR4hRV1t3N1e5vsPySpMXs1h9MFtdvzmR2 + YPKYeP40m8ezVbeYA5iiuGxSUnMyy1KL9O0SuDIuXLrLXtDMV7H21UzmBsYDXF2MnBwSAiYS + p5q6WSBsMYkL99azdTFycQgJ7GOUWDDjNSOEs4FR4tuyVrAqIYGTTBJXDoVDJJYwSrz7eokZ + JMEioCqxq7OPFcRmE9CQ2LZ/OSOILSJgKrHhwQN2EJtZQFri2+9mJhBbWCBM4tH+D2wgNq+A + jsTFCeuhts1klGh/eJkRIiEocXLmExaIZi2JG/9eAjVzgA1a/o8DJMwpECSxYN8RsBJRARWJ + KSe3sU1gFJqFpHsWku5ZCN0LGJlXMcqm5Fbp5iZm5hSnJusWJyfm5aUW6Rrq5WaW6KWmlG5i + BAe2JM8OxjcHlQ4xCnAwKvHwvnzW5i/EmlhWXJl7iFGSg0lJlHc1e7u/EF9SfkplRmJxRnxR + aU5q8SFGCQ5mJRHeP4+BynlTEiurUovyYVLSHCxK4rwqWu/8hATSE0tSs1NTC1KLYLIyHBxK + ErwuwAgWEixKTU+tSMvMKUFIM3FwggznARpuDVLDW1yQmFucmQ6RP8WoKCXOqwySEABJZJTm + wfXCEs8rRnGgV4R57UGqeIBJC677FdBgJqDBfAogVxeXJCKkpBoYNf29ojr317rmlS0p8z/w + eO7N4yE72FxWFkxX+ZRx+uqBpHXq8oW67BeLk/QyGAUfzMvZc3v67avr/voFngy8ErFnwqZp + XWr7n5zhvOD9O9efzaBq+hFHAVNe9mslS+p6pWY8erFl+h9jx2O7Tjay3mitnO1kK1pbsHMd + 0+6jtccOmlrdvjRFWYmlOCPRUIu5qDgRABjs77QXAwAA +Cc: notmuch@notmuchmail.org +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, 12 Apr 2012 17:02:52 -0000 + +Quoth Justus Winter on Mar 21 at 1:55 am: +> Adapt the go bindings to the notmuch_database_close split. + +Typo. + +> +> Signed-off-by: Justus Winter <4winter@informatik.uni-hamburg.de> +> --- +> bindings/python/notmuch/database.py | 17 +++++++++++++++-- +> 1 files changed, 15 insertions(+), 2 deletions(-) +> +> diff --git a/bindings/python/notmuch/database.py b/bindings/python/notmuch/database.py +> index 44d40fd..9a1896b 100644 +> --- a/bindings/python/notmuch/database.py +> +++ b/bindings/python/notmuch/database.py +> @@ -218,9 +218,22 @@ class Database(object): +> _close.restype = None +> +> def close(self): +> - """Close and free the notmuch database if needed""" +> - if self._db is not None: +> + ''' +> + Closes the notmuch database. +> + ''' +> + if self._db: +> self._close(self._db) +> + +> + _destroy = nmlib.notmuch_database_destroy +> + _destroy.argtypes = [NotmuchDatabaseP] +> + _destroy.restype = None +> + +> + def destroy(self): + +Should this be __del__? The existing __del__ is certainly wrong with +this change, since it only closes the database and doesn't free it. I +think this function is exactly what you want __del__ to be now. + +(I think it also doesn't make sense to expose notmuch_database_destroy +as a general, public method since it will free all of the other C +objects out from under the bindings, resulting in exactly the double +free-type crashes that you're trying to avoid. It appears that none +of the other Python classes have a destroy method.) + +> + ''' +> + Destroys the notmuch database. +> + ''' +> + if self._db: +> + self._destroy(self._db) +> self._db = None +> +> def __enter__(self): -- 2.26.2