unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Felipe Contreras <felipe.contreras@gmail.com>
To: notmuch@notmuchmail.org
Cc: Ali Polatel <alip@exherbo.org>,
	Austin Clements <austin@google.com>,
	Tomi Ollila <tomi.ollila@iki.fi>,
	Ludovic LANGE <ll-notmuchmail@lange.nom.fr>,
	Daniel Kahn Gillmor <dkg@fifthhorseman.net>
Subject: [PATCH v3 4/7] ruby: create Data_Wrap_Notmuch_Object helper
Date: Sat, 15 May 2021 16:21:00 -0500	[thread overview]
Message-ID: <20210515212103.1001295-5-felipe.contreras@gmail.com> (raw)
In-Reply-To: <20210515212103.1001295-1-felipe.contreras@gmail.com>

This makes the code more maintainable and will help in further patches.

No functional changes.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 bindings/ruby/database.c  | 14 +++++++-------
 bindings/ruby/defs.h      |  3 +++
 bindings/ruby/directory.c |  4 ++--
 bindings/ruby/message.c   |  6 +++---
 bindings/ruby/messages.c  |  4 ++--
 bindings/ruby/query.c     |  4 ++--
 bindings/ruby/thread.c    |  6 +++---
 bindings/ruby/threads.c   |  2 +-
 8 files changed, 23 insertions(+), 20 deletions(-)

diff --git a/bindings/ruby/database.c b/bindings/ruby/database.c
index 416eb709..b9ad3373 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_Notmuch_Object (klass, NULL);
 }
 
 /*
@@ -266,7 +266,7 @@ notmuch_rb_database_get_directory (VALUE self, VALUE pathv)
     ret = notmuch_database_get_directory (db, path, &dir);
     notmuch_rb_status_raise (ret);
     if (dir)
-	return Data_Wrap_Struct (notmuch_rb_cDirectory, NULL, NULL, dir);
+	return Data_Wrap_Notmuch_Object (notmuch_rb_cDirectory, dir);
     return Qnil;
 }
 
@@ -293,7 +293,7 @@ notmuch_rb_database_add_message (VALUE self, VALUE pathv)
 
     ret = notmuch_database_index_file (db, path, NULL, &message);
     notmuch_rb_status_raise (ret);
-    return rb_assoc_new (Data_Wrap_Struct (notmuch_rb_cMessage, NULL, NULL, message),
+    return rb_assoc_new (Data_Wrap_Notmuch_Object (notmuch_rb_cMessage, message),
         (ret == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) ? Qtrue : Qfalse);
 }
 
@@ -344,7 +344,7 @@ notmuch_rb_database_find_message (VALUE self, VALUE idv)
     notmuch_rb_status_raise (ret);
 
     if (message)
-        return Data_Wrap_Struct (notmuch_rb_cMessage, NULL, NULL, message);
+        return Data_Wrap_Notmuch_Object (notmuch_rb_cMessage, message);
     return Qnil;
 }
 
@@ -370,7 +370,7 @@ notmuch_rb_database_find_message_by_filename (VALUE self, VALUE pathv)
     notmuch_rb_status_raise (ret);
 
     if (message)
-        return Data_Wrap_Struct (notmuch_rb_cMessage, NULL, NULL, message);
+        return Data_Wrap_Notmuch_Object (notmuch_rb_cMessage, message);
     return Qnil;
 }
 
@@ -395,7 +395,7 @@ notmuch_rb_database_get_all_tags (VALUE self)
 
 	rb_raise (notmuch_rb_eBaseError, "%s", msg);
     }
-    return Data_Wrap_Struct (notmuch_rb_cTags, NULL, NULL, tags);
+    return Data_Wrap_Notmuch_Object (notmuch_rb_cTags, tags);
 }
 
 /*
@@ -419,5 +419,5 @@ notmuch_rb_database_query_create (VALUE self, VALUE qstrv)
     if (!query)
         rb_raise (notmuch_rb_eMemoryError, "Out of memory");
 
-    return Data_Wrap_Struct (notmuch_rb_cQuery, NULL, NULL, query);
+    return Data_Wrap_Notmuch_Object (notmuch_rb_cQuery, query);
 }
diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h
index 12538a3a..fcf1ea39 100644
--- a/bindings/ruby/defs.h
+++ b/bindings/ruby/defs.h
@@ -64,6 +64,9 @@ extern ID ID_db_mode;
 	}									    \
     } while (0)
 
+#define Data_Wrap_Notmuch_Object(klass, ptr)	\
+    Data_Wrap_Struct ((klass), NULL, NULL, (ptr))
+
 #define Data_Get_Notmuch_Database(obj, ptr) \
     Data_Get_Notmuch_Object ((obj), (ptr))
 
diff --git a/bindings/ruby/directory.c b/bindings/ruby/directory.c
index fe5fc46d..36ef3984 100644
--- a/bindings/ruby/directory.c
+++ b/bindings/ruby/directory.c
@@ -92,7 +92,7 @@ notmuch_rb_directory_get_child_files (VALUE self)
 
     fnames = notmuch_directory_get_child_files (dir);
 
-    return Data_Wrap_Struct (notmuch_rb_cFileNames, NULL, NULL, fnames);
+    return Data_Wrap_Notmuch_Object (notmuch_rb_cFileNames, fnames);
 }
 
 /*
@@ -111,5 +111,5 @@ notmuch_rb_directory_get_child_directories (VALUE self)
 
     fnames = notmuch_directory_get_child_directories (dir);
 
-    return Data_Wrap_Struct (notmuch_rb_cFileNames, NULL, NULL, fnames);
+    return Data_Wrap_Notmuch_Object (notmuch_rb_cFileNames, fnames);
 }
diff --git a/bindings/ruby/message.c b/bindings/ruby/message.c
index 6ea82afa..1990bb97 100644
--- a/bindings/ruby/message.c
+++ b/bindings/ruby/message.c
@@ -89,7 +89,7 @@ notmuch_rb_message_get_replies (VALUE self)
 
     messages = notmuch_message_get_replies (message);
 
-    return Data_Wrap_Struct (notmuch_rb_cMessages, NULL, NULL, messages);
+    return Data_Wrap_Notmuch_Object (notmuch_rb_cMessages, messages);
 }
 
 /*
@@ -125,7 +125,7 @@ notmuch_rb_message_get_filenames (VALUE self)
 
     fnames = notmuch_message_get_filenames (message);
 
-    return Data_Wrap_Struct (notmuch_rb_cFileNames, NULL, NULL, fnames);
+    return Data_Wrap_Notmuch_Object (notmuch_rb_cFileNames, fnames);
 }
 
 /*
@@ -226,7 +226,7 @@ notmuch_rb_message_get_tags (VALUE self)
     if (!tags)
 	rb_raise (notmuch_rb_eMemoryError, "Out of memory");
 
-    return Data_Wrap_Struct (notmuch_rb_cTags, NULL, NULL, tags);
+    return Data_Wrap_Notmuch_Object (notmuch_rb_cTags, tags);
 }
 
 /*
diff --git a/bindings/ruby/messages.c b/bindings/ruby/messages.c
index a337feeb..3d1669ee 100644
--- a/bindings/ruby/messages.c
+++ b/bindings/ruby/messages.c
@@ -53,7 +53,7 @@ notmuch_rb_messages_each (VALUE self)
 
     for (; notmuch_messages_valid (messages); notmuch_messages_move_to_next (messages)) {
 	message = notmuch_messages_get (messages);
-	rb_yield (Data_Wrap_Struct (notmuch_rb_cMessage, NULL, NULL, message));
+	rb_yield (Data_Wrap_Notmuch_Object (notmuch_rb_cMessage, message));
     }
 
     return self;
@@ -76,5 +76,5 @@ notmuch_rb_messages_collect_tags (VALUE self)
     if (!tags)
 	rb_raise (notmuch_rb_eMemoryError, "Out of memory");
 
-    return Data_Wrap_Struct (notmuch_rb_cTags, NULL, NULL, tags);
+    return Data_Wrap_Notmuch_Object (notmuch_rb_cTags, tags);
 }
diff --git a/bindings/ruby/query.c b/bindings/ruby/query.c
index 8b46d700..b0fb4ea7 100644
--- a/bindings/ruby/query.c
+++ b/bindings/ruby/query.c
@@ -142,7 +142,7 @@ notmuch_rb_query_search_threads (VALUE self)
     if (status)
 	notmuch_rb_status_raise (status);
 
-    return Data_Wrap_Struct (notmuch_rb_cThreads, NULL, NULL, threads);
+    return Data_Wrap_Notmuch_Object (notmuch_rb_cThreads, threads);
 }
 
 /*
@@ -163,7 +163,7 @@ notmuch_rb_query_search_messages (VALUE self)
     if (status)
 	notmuch_rb_status_raise (status);
 
-    return Data_Wrap_Struct (notmuch_rb_cMessages, NULL, NULL, messages);
+    return Data_Wrap_Notmuch_Object (notmuch_rb_cMessages, messages);
 }
 
 /*
diff --git a/bindings/ruby/thread.c b/bindings/ruby/thread.c
index 9b295981..e09be147 100644
--- a/bindings/ruby/thread.c
+++ b/bindings/ruby/thread.c
@@ -88,7 +88,7 @@ notmuch_rb_thread_get_toplevel_messages (VALUE self)
     if (!messages)
 	rb_raise (notmuch_rb_eMemoryError, "Out of memory");
 
-    return Data_Wrap_Struct (notmuch_rb_cMessages, NULL, NULL, messages);
+    return Data_Wrap_Notmuch_Object (notmuch_rb_cMessages, messages);
 }
 
 /*
@@ -108,7 +108,7 @@ notmuch_rb_thread_get_messages (VALUE self)
     if (!messages)
 	rb_raise (notmuch_rb_eMemoryError, "Out of memory");
 
-    return Data_Wrap_Struct (notmuch_rb_cMessages, NULL, NULL, messages);
+    return Data_Wrap_Notmuch_Object (notmuch_rb_cMessages, messages);
 }
 
 /*
@@ -209,5 +209,5 @@ notmuch_rb_thread_get_tags (VALUE self)
     if (!tags)
 	rb_raise (notmuch_rb_eMemoryError, "Out of memory");
 
-    return Data_Wrap_Struct (notmuch_rb_cTags, NULL, NULL, tags);
+    return Data_Wrap_Notmuch_Object (notmuch_rb_cTags, tags);
 }
diff --git a/bindings/ruby/threads.c b/bindings/ruby/threads.c
index 5885f565..19e09a7e 100644
--- a/bindings/ruby/threads.c
+++ b/bindings/ruby/threads.c
@@ -53,7 +53,7 @@ notmuch_rb_threads_each (VALUE self)
 
     for (; notmuch_threads_valid (threads); notmuch_threads_move_to_next (threads)) {
 	thread = notmuch_threads_get (threads);
-	rb_yield (Data_Wrap_Struct (notmuch_rb_cThread, NULL, NULL, thread));
+	rb_yield (Data_Wrap_Notmuch_Object (notmuch_rb_cThread, thread));
     }
 
     return self;
-- 
2.31.1

  parent reply	other threads:[~2021-05-15 21:21 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-15 21:20 [PATCH v3 0/7] ruby: object cleanups Felipe Contreras
2021-05-15 21:20 ` [PATCH v3 1/7] ruby: simplify data get helper Felipe Contreras
2021-05-17 10:55   ` David Bremner
2021-05-15 21:20 ` [PATCH v3 2/7] ruby: fetch class name in case of error Felipe Contreras
2021-05-15 21:20 ` [PATCH v3 3/7] ruby: add unlikely hint Felipe Contreras
2021-05-15 21:21 ` Felipe Contreras [this message]
2021-05-15 21:21 ` [PATCH v3 5/7] ruby: move towards more modern RTypedData Felipe Contreras
2021-05-15 21:21 ` [PATCH v3 6/7] ruby: add all data types Felipe Contreras
2021-05-15 21:21 ` [PATCH v3 7/7] ruby: new notmuch_rb_object_destroy() helper Felipe Contreras

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210515212103.1001295-5-felipe.contreras@gmail.com \
    --to=felipe.contreras@gmail.com \
    --cc=alip@exherbo.org \
    --cc=austin@google.com \
    --cc=dkg@fifthhorseman.net \
    --cc=ll-notmuchmail@lange.nom.fr \
    --cc=notmuch@notmuchmail.org \
    --cc=tomi.ollila@iki.fi \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).