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