[PATCH 3/3] ruby: bind database close()/destroy() properly
authorFelipe Contreras <felipe.contreras@gmail.com>
Mon, 30 Sep 2013 16:28:43 +0000 (11:28 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:57:13 +0000 (09:57 -0800)
6e/1aed62f9f4f2661f572e970a41c3a72221e68a [new file with mode: 0644]

diff --git a/6e/1aed62f9f4f2661f572e970a41c3a72221e68a b/6e/1aed62f9f4f2661f572e970a41c3a72221e68a
new file mode 100644 (file)
index 0000000..ad49366
--- /dev/null
@@ -0,0 +1,161 @@
+Return-Path: <felipe.contreras@gmail.com>\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 C757F431FC4\r
+       for <notmuch@notmuchmail.org>; Mon, 30 Sep 2013 09:34:46 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.799\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] 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 YQ-wa-FHCOGp for <notmuch@notmuchmail.org>;\r
+       Mon, 30 Sep 2013 09:34:40 -0700 (PDT)\r
+Received: from mail-ob0-f174.google.com (mail-ob0-f174.google.com\r
+       [209.85.214.174]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 43F53431FC7\r
+       for <notmuch@notmuchmail.org>; Mon, 30 Sep 2013 09:34:37 -0700 (PDT)\r
+Received: by mail-ob0-f174.google.com with SMTP id uz6so5093768obc.19\r
+       for <notmuch@notmuchmail.org>; Mon, 30 Sep 2013 09:34:36 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+       h=from:to:cc:subject:date:message-id:in-reply-to:references;\r
+       bh=0wzf56n9YM5SILVxUSUA4dJqPVhbwVg0Z7Dhn6jp8fs=;\r
+       b=HFwwB1Qr1Uinti/nSxdarNjeypwtimGbRXncB6849ssZBhDdH5MNSin0awdVD8WgGG\r
+       uLViNahQS58YCOZpYCNFBUjvrZ8qeTx3XfFh/lQ+4jXhlSTRwb97XAKn25Nq3iXBXOuV\r
+       qilS5haSeQXEC5uOuTvibh8sK8KjprT75W2RYY35lWb7YPit8BizkrL3OgjW5pCzxPEj\r
+       81+s7+TJ94PjKdm7HhzwsImvbaSBXzIiVMcjvrOk0YT7qMGZRc/W1nZXXa13xSYbbyfT\r
+       pGF5fjNMvr3D8acWfN+sjs1rb+/2cSQ5VY42YWbo8pSTQE6hu3pYGQoqFYHwFBapHfCh\r
+       zi0g==\r
+X-Received: by 10.182.75.201 with SMTP id e9mr20584233obw.28.1380558876814;\r
+       Mon, 30 Sep 2013 09:34:36 -0700 (PDT)\r
+Received: from localhost (187-162-140-241.static.axtel.net. [187.162.140.241])\r
+       by mx.google.com with ESMTPSA id d3sm1982466oek.5.1969.12.31.16.00.00\r
+       (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128);\r
+       Mon, 30 Sep 2013 09:34:35 -0700 (PDT)\r
+From: Felipe Contreras <felipe.contreras@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 3/3] ruby: bind database close()/destroy() properly\r
+Date: Mon, 30 Sep 2013 11:28:43 -0500\r
+Message-Id: <1380558523-6913-4-git-send-email-felipe.contreras@gmail.com>\r
+X-Mailer: git-send-email 1.8.4-fc\r
+In-Reply-To: <1380558523-6913-1-git-send-email-felipe.contreras@gmail.com>\r
+References: <1380558523-6913-1-git-send-email-felipe.contreras@gmail.com>\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: Mon, 30 Sep 2013 16:34:47 -0000\r
+\r
+db.close() should close, and db.destroy!() should destroy, it's a simple\r
+as that.\r
+\r
+In addition, this makes is reasonable to allow the database objects to\r
+be garbage collected, and if the database object is destroyed, all the\r
+dependent objects are destroyed as well, so foo.destroy!() are not\r
+necessary.\r
+\r
+Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\r
+---\r
+ bindings/ruby/database.c | 22 +++++++++++++++++++---\r
+ bindings/ruby/defs.h     |  5 ++++-\r
+ bindings/ruby/init.c     |  1 +\r
+ 3 files changed, 24 insertions(+), 4 deletions(-)\r
+\r
+diff --git a/bindings/ruby/database.c b/bindings/ruby/database.c\r
+index e84f726..8f2e16d 100644\r
+--- a/bindings/ruby/database.c\r
++++ b/bindings/ruby/database.c\r
+@@ -23,7 +23,7 @@\r
+ VALUE\r
+ notmuch_rb_database_alloc (VALUE klass)\r
+ {\r
+-    return Data_Wrap_Struct (klass, NULL, NULL, NULL);\r
++    return Data_Wrap_Struct (klass, NULL, notmuch_database_destroy, NULL);\r
+ }\r
\r
+ /*\r
+@@ -87,6 +87,23 @@ notmuch_rb_database_initialize (int argc, VALUE *argv, VALUE self)\r
+ }\r
\r
+ /*\r
++ * call-seq: DB.destroy! => nil\r
++ *\r
++ * Destroy the notmuch database, freeing all resources allocated for it.\r
++ */\r
++VALUE\r
++notmuch_rb_database_destroy (VALUE self)\r
++{\r
++    notmuch_database_t *db;\r
++\r
++    Data_Get_Notmuch_Database (self, db);\r
++    notmuch_database_destroy (db);\r
++    DATA_PTR (self) = NULL;\r
++\r
++    return Qnil;\r
++}\r
++\r
++/*\r
+  * call-seq: Notmuch::Database.open(path [, ahash]) {|db| ...}\r
+  *\r
+  * Identical to new, except that when it is called with a block, it yields with\r
+@@ -116,8 +133,7 @@ notmuch_rb_database_close (VALUE self)\r
+     notmuch_database_t *db;\r
\r
+     Data_Get_Notmuch_Database (self, db);\r
+-    notmuch_database_destroy (db);\r
+-    DATA_PTR (self) = NULL;\r
++    notmuch_database_close (db);\r
\r
+     return Qnil;\r
+ }\r
+diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h\r
+index 5b44585..0ad198a 100644\r
+--- a/bindings/ruby/defs.h\r
++++ b/bindings/ruby/defs.h\r
+@@ -59,7 +59,7 @@ extern ID ID_db_mode;\r
+     do {                                                      \\r
+       Check_Type ((obj), T_DATA);                             \\r
+       if (DATA_PTR ((obj)) == NULL)                           \\r
+-      rb_raise (rb_eRuntimeError, "database closed");         \\r
++      rb_raise (rb_eRuntimeError, "database destroyed");      \\r
+       Data_Get_Struct ((obj), notmuch_database_t, (ptr));     \\r
+     } while (0)\r
\r
+@@ -139,6 +139,9 @@ VALUE\r
+ notmuch_rb_database_initialize (int argc, VALUE *argv, VALUE klass);\r
\r
+ VALUE\r
++notmuch_rb_database_destroy (VALUE self);\r
++\r
++VALUE\r
+ notmuch_rb_database_open (int argc, VALUE *argv, VALUE klass);\r
\r
+ VALUE\r
+diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c\r
+index 663271d..fee04c3 100644\r
+--- a/bindings/ruby/init.c\r
++++ b/bindings/ruby/init.c\r
+@@ -215,6 +215,7 @@ Init_notmuch (void)\r
+     rb_define_alloc_func (notmuch_rb_cDatabase, notmuch_rb_database_alloc);\r
+     rb_define_singleton_method (notmuch_rb_cDatabase, "open", notmuch_rb_database_open, -1); /* in database.c */\r
+     rb_define_method (notmuch_rb_cDatabase, "initialize", notmuch_rb_database_initialize, -1); /* in database.c */\r
++    rb_define_method (notmuch_rb_cDatabase, "destroy!", notmuch_rb_database_destroy, 0); /* in database.c */\r
+     rb_define_method (notmuch_rb_cDatabase, "close", notmuch_rb_database_close, 0); /* in database.c */\r
+     rb_define_method (notmuch_rb_cDatabase, "path", notmuch_rb_database_path, 0); /* in database.c */\r
+     rb_define_method (notmuch_rb_cDatabase, "version", notmuch_rb_database_version, 0); /* in database.c */\r
+-- \r
+1.8.4-fc\r
+\r