diff --git a/bindings/ruby/database.c b/bindings/ruby/database.c index 6824efdc..f4edd773 100644 --- a/bindings/ruby/database.c +++ b/bindings/ruby/database.c @@ -20,19 +20,26 @@ #include "defs.h" +VALUE +notmuch_rb_database_alloc(VALUE klass) +{ + return Data_Wrap_Struct(klass, NULL, NULL, NULL); +} + /* - * call-seq: Notmuch::Database.new(path, [{:create => false, :mode => notmuch::MODE_READ_ONLY}]) => DB + * call-seq: Notmuch::Database.new(path [, {:create => false, :mode => Notmuch::MODE_READ_ONLY}]) => DB * * Create or open a notmuch database using the given path. + * * If :create is +true+, create the database instead of opening. + * * The argument :mode specifies the open mode of the database. */ VALUE -notmuch_rb_database_new(int argc, VALUE *argv, VALUE klass) +notmuch_rb_database_initialize(int argc, VALUE *argv, VALUE self) { const char *path; int create, mode; - notmuch_database_t *db; VALUE pathv, hashv; VALUE modev; @@ -70,11 +77,31 @@ notmuch_rb_database_new(int argc, VALUE *argv, VALUE klass) mode = NOTMUCH_DATABASE_MODE_READ_ONLY; } - db = create ? notmuch_database_create(path) : notmuch_database_open(path, mode); - if (!db) + Check_Type(self, T_DATA); + DATA_PTR(self) = create ? notmuch_database_create(path) : notmuch_database_open(path, mode); + if (!DATA_PTR(self)) rb_raise(notmuch_rb_eDatabaseError, "Failed to open database"); - return Data_Wrap_Struct(klass, NULL, NULL, db); + return self; +} + +/* + * call-seq: Notmuch::Database.open(path [, ahash]) {|db| ...} + * + * Identical to new, except that when it is called with a block, it yields with + * the new instance and closes it, and returns the result which is returned from + * the block. + */ +VALUE +notmuch_rb_database_open(int argc, VALUE *argv, VALUE klass) +{ + VALUE obj; + + obj = rb_class_new_instance(argc, argv, klass); + if (!rb_block_given_p()) + return obj; + + return rb_ensure(rb_yield, obj, notmuch_rb_database_close, obj); } /* @@ -87,8 +114,9 @@ notmuch_rb_database_close(VALUE self) { notmuch_database_t *db; - Data_Get_Struct(self, notmuch_database_t, db); + Data_Get_Notmuch_Database(self, db); notmuch_database_close(db); + DATA_PTR(self) = NULL; return Qnil; } @@ -103,7 +131,7 @@ notmuch_rb_database_path(VALUE self) { notmuch_database_t *db; - Data_Get_Struct(self, notmuch_database_t, db); + Data_Get_Notmuch_Database(self, db); return rb_str_new2(notmuch_database_get_path(db)); } @@ -118,7 +146,7 @@ notmuch_rb_database_version(VALUE self) { notmuch_database_t *db; - Data_Get_Struct(self, notmuch_database_t, db); + Data_Get_Notmuch_Database(self, db); return INT2FIX(notmuch_database_get_version(db)); } @@ -133,7 +161,7 @@ notmuch_rb_database_needs_upgrade(VALUE self) { notmuch_database_t *db; - Data_Get_Struct(self, notmuch_database_t, db); + Data_Get_Notmuch_Database(self, db); return notmuch_database_needs_upgrade(db) ? Qtrue : Qfalse; } @@ -161,7 +189,7 @@ notmuch_rb_database_upgrade(VALUE self) notmuch_database_t *db; VALUE block; - Data_Get_Struct(self, notmuch_database_t, db); + Data_Get_Notmuch_Database(self, db); if (rb_block_given_p()) { pnotify = notmuch_rb_upgrade_notify; @@ -188,7 +216,7 @@ notmuch_rb_database_get_directory(VALUE self, VALUE pathv) notmuch_directory_t *dir; notmuch_database_t *db; - Data_Get_Struct(self, notmuch_database_t, db); + Data_Get_Notmuch_Database(self, db); #if !defined(RSTRING_PTR) #define RSTRING_PTR(v) (RSTRING((v))->ptr) @@ -220,7 +248,7 @@ notmuch_rb_database_add_message(VALUE self, VALUE pathv) notmuch_message_t *message; notmuch_database_t *db; - Data_Get_Struct(self, notmuch_database_t, db); + Data_Get_Notmuch_Database(self, db); #if !defined(RSTRING_PTR) #define RSTRING_PTR(v) (RSTRING((v))->ptr) @@ -250,7 +278,7 @@ notmuch_rb_database_remove_message(VALUE self, VALUE pathv) notmuch_status_t ret; notmuch_database_t *db; - Data_Get_Struct(self, notmuch_database_t, db); + Data_Get_Notmuch_Database(self, db); #if !defined(RSTRING_PTR) #define RSTRING_PTR(v) (RSTRING((v))->ptr) @@ -276,7 +304,7 @@ notmuch_rb_database_query_create(VALUE self, VALUE qstrv) notmuch_query_t *query; notmuch_database_t *db; - Data_Get_Struct(self, notmuch_database_t, db); + Data_Get_Notmuch_Database(self, db); #if !defined(RSTRING_PTR) #define RSTRING_PTR(v) (RSTRING((v))->ptr) @@ -287,7 +315,7 @@ notmuch_rb_database_query_create(VALUE self, VALUE qstrv) query = notmuch_query_create(db, qstr); if (!query) - rb_raise(notmuch_rb_eMemoryError, "out of memory"); + rb_raise(notmuch_rb_eMemoryError, "Out of memory"); return Data_Wrap_Struct(notmuch_rb_cQuery, NULL, NULL, query); } diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h index f36b7227..b1be5a30 100644 --- a/bindings/ruby/defs.h +++ b/bindings/ruby/defs.h @@ -49,13 +49,91 @@ ID ID_call; ID ID_db_create; ID ID_db_mode; +#define Data_Get_Notmuch_Database(obj, ptr) \ + do { \ + Check_Type(obj, T_DATA); \ + if (DATA_PTR(obj) == NULL) \ + rb_raise(rb_eRuntimeError, "database closed"); \ + Data_Get_Struct(obj, notmuch_database_t, ptr); \ + } while(0) + +#define Data_Get_Notmuch_Directory(obj, ptr) \ + do { \ + Check_Type(obj, T_DATA); \ + if (DATA_PTR(obj) == NULL) \ + rb_raise(rb_eRuntimeError, "directory destroyed"); \ + Data_Get_Struct(obj, notmuch_directory_t, ptr); \ + } while(0) + +#define Data_Get_Notmuch_FileNames(obj, ptr) \ + do { \ + Check_Type(obj, T_DATA); \ + if (DATA_PTR(obj) == NULL) \ + rb_raise(rb_eRuntimeError, "filenames destroyed"); \ + Data_Get_Struct(obj, notmuch_filenames_t, ptr); \ + } while(0) + +#define Data_Get_Notmuch_Query(obj, ptr) \ + do { \ + Check_Type(obj, T_DATA); \ + if (DATA_PTR(obj) == NULL) \ + rb_raise(rb_eRuntimeError, "query destroyed"); \ + Data_Get_Struct(obj, notmuch_query_t, ptr); \ + } while(0) + +#define Data_Get_Notmuch_Threads(obj, ptr) \ + do { \ + Check_Type(obj, T_DATA); \ + if (DATA_PTR(obj) == NULL) \ + rb_raise(rb_eRuntimeError, "threads destroyed"); \ + Data_Get_Struct(obj, notmuch_threads_t, ptr); \ + } while(0) + +#define Data_Get_Notmuch_Messages(obj, ptr) \ + do { \ + Check_Type(obj, T_DATA); \ + if (DATA_PTR(obj) == NULL) \ + rb_raise(rb_eRuntimeError, "messages destroyed"); \ + Data_Get_Struct(obj, notmuch_messages_t, ptr); \ + } while(0) + +#define Data_Get_Notmuch_Thread(obj, ptr) \ + do { \ + Check_Type(obj, T_DATA); \ + if (DATA_PTR(obj) == NULL) \ + rb_raise(rb_eRuntimeError, "thread destroyed"); \ + Data_Get_Struct(obj, notmuch_thread_t, ptr); \ + } while(0) + +#define Data_Get_Notmuch_Message(obj, ptr) \ + do { \ + Check_Type(obj, T_DATA); \ + if (DATA_PTR(obj) == NULL) \ + rb_raise(rb_eRuntimeError, "message destroyed"); \ + Data_Get_Struct(obj, notmuch_message_t, ptr); \ + } while(0) + +#define Data_Get_Notmuch_Tags(obj, ptr) \ + do { \ + Check_Type(obj, T_DATA); \ + if (DATA_PTR(obj) == NULL) \ + rb_raise(rb_eRuntimeError, "tags destroyed"); \ + Data_Get_Struct(obj, notmuch_tags_t, ptr); \ + } while(0) + /* status.c */ void notmuch_rb_status_raise(notmuch_status_t status); /* database.c */ VALUE -notmuch_rb_database_new(int argc, VALUE *argv, VALUE klass); +notmuch_rb_database_alloc(VALUE klass); + +VALUE +notmuch_rb_database_initialize(int argc, VALUE *argv, VALUE klass); + +VALUE +notmuch_rb_database_open(int argc, VALUE *argv, VALUE klass); VALUE notmuch_rb_database_close(VALUE self); diff --git a/bindings/ruby/directory.c b/bindings/ruby/directory.c index e73658c1..36dcb8be 100644 --- a/bindings/ruby/directory.c +++ b/bindings/ruby/directory.c @@ -33,6 +33,7 @@ notmuch_rb_directory_destroy(VALUE self) Data_Get_Struct(self, notmuch_directory_t, dir); notmuch_directory_destroy(dir); + DATA_PTR(self) = NULL; return Qnil; } @@ -48,7 +49,7 @@ notmuch_rb_directory_get_mtime(VALUE self) { notmuch_directory_t *dir; - Data_Get_Struct(self, notmuch_directory_t, dir); + Data_Get_Notmuch_Directory(self, dir); return UINT2NUM(notmuch_directory_get_mtime(dir)); } @@ -64,7 +65,7 @@ notmuch_rb_directory_set_mtime(VALUE self, VALUE mtimev) notmuch_status_t ret; notmuch_directory_t *dir; - Data_Get_Struct(self, notmuch_directory_t, dir); + Data_Get_Notmuch_Directory(self, dir); if (!FIXNUM_P(mtimev)) rb_raise(rb_eTypeError, "First argument not a fixnum"); @@ -87,7 +88,7 @@ notmuch_rb_directory_get_child_files(VALUE self) notmuch_directory_t *dir; notmuch_filenames_t *fnames; - Data_Get_Struct(self, notmuch_directory_t, dir); + Data_Get_Notmuch_Directory(self, dir); fnames = notmuch_directory_get_child_files(dir); @@ -106,7 +107,7 @@ notmuch_rb_directory_get_child_directories(VALUE self) notmuch_directory_t *dir; notmuch_filenames_t *fnames; - Data_Get_Struct(self, notmuch_directory_t, dir); + Data_Get_Notmuch_Directory(self, dir); fnames = notmuch_directory_get_child_directories(dir); diff --git a/bindings/ruby/filenames.c b/bindings/ruby/filenames.c index 23553ab1..faaa9a0a 100644 --- a/bindings/ruby/filenames.c +++ b/bindings/ruby/filenames.c @@ -30,9 +30,10 @@ notmuch_rb_filenames_destroy(VALUE self) { notmuch_filenames_t *fnames; - Data_Get_Struct(self, notmuch_filenames_t, fnames); + Data_Get_Notmuch_FileNames(self, fnames); notmuch_filenames_destroy(fnames); + DATA_PTR(self) = NULL; return Qnil; } @@ -48,9 +49,7 @@ notmuch_rb_filenames_each(VALUE self) { notmuch_filenames_t *fnames; - Data_Get_Struct(self, notmuch_filenames_t, fnames); - if (!fnames) - return self; + Data_Get_Notmuch_FileNames(self, fnames); for (; notmuch_filenames_valid(fnames); notmuch_filenames_move_to_next(fnames)) rb_yield(rb_str_new2(notmuch_filenames_get(fnames))); diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c index 4fdd018c..e19b0356 100644 --- a/bindings/ruby/init.c +++ b/bindings/ruby/init.c @@ -193,8 +193,10 @@ Init_notmuch(void) notmuch_rb_eUnbalancedFreezeThawError = rb_define_class_under(mod, "UnbalancedFreezeThawError", notmuch_rb_eBaseError); - notmuch_rb_cDatabase = rb_define_class_under(mod, "Database", rb_cObject); - rb_define_singleton_method(notmuch_rb_cDatabase, "new", notmuch_rb_database_new, -1); + notmuch_rb_cDatabase = rb_define_class_under(mod, "Database", rb_cData); + rb_define_alloc_func(notmuch_rb_cDatabase, notmuch_rb_database_alloc); + rb_define_singleton_method(notmuch_rb_cDatabase, "open", notmuch_rb_database_open, -1); + rb_define_method(notmuch_rb_cDatabase, "initialize", notmuch_rb_database_initialize, -1); rb_define_method(notmuch_rb_cDatabase, "close", notmuch_rb_database_close, 0); rb_define_method(notmuch_rb_cDatabase, "path", notmuch_rb_database_path, 0); rb_define_method(notmuch_rb_cDatabase, "version", notmuch_rb_database_version, 0); @@ -205,7 +207,7 @@ Init_notmuch(void) rb_define_method(notmuch_rb_cDatabase, "remove_message", notmuch_rb_database_remove_message, 1); rb_define_method(notmuch_rb_cDatabase, "query", notmuch_rb_database_query_create, 1); - notmuch_rb_cDirectory = rb_define_class_under(mod, "Directory", rb_cObject); + notmuch_rb_cDirectory = rb_define_class_under(mod, "Directory", rb_cData); rb_undef_method(notmuch_rb_cDirectory, "initialize"); rb_define_method(notmuch_rb_cDirectory, "destroy", notmuch_rb_directory_destroy, 0); rb_define_method(notmuch_rb_cDirectory, "mtime", notmuch_rb_directory_get_mtime, 0); @@ -213,33 +215,33 @@ Init_notmuch(void) rb_define_method(notmuch_rb_cDirectory, "child_files", notmuch_rb_directory_get_child_files, 0); rb_define_method(notmuch_rb_cDirectory, "child_directories", notmuch_rb_directory_get_child_directories, 0); - notmuch_rb_cFileNames = rb_define_class_under(mod, "FileNames", rb_cObject); + notmuch_rb_cFileNames = rb_define_class_under(mod, "FileNames", rb_cData); rb_undef_method(notmuch_rb_cFileNames, "initialize"); rb_define_method(notmuch_rb_cFileNames, "destroy", notmuch_rb_filenames_destroy, 0); rb_define_method(notmuch_rb_cFileNames, "each", notmuch_rb_filenames_each, 0); rb_include_module(notmuch_rb_cFileNames, rb_mEnumerable); - notmuch_rb_cQuery = rb_define_class_under(mod, "Query", rb_cObject); + notmuch_rb_cQuery = rb_define_class_under(mod, "Query", rb_cData); rb_undef_method(notmuch_rb_cQuery, "initialize"); rb_define_method(notmuch_rb_cQuery, "destroy", notmuch_rb_query_destroy, 0); rb_define_method(notmuch_rb_cQuery, "sort=", notmuch_rb_query_set_sort, 1); rb_define_method(notmuch_rb_cQuery, "search_threads", notmuch_rb_query_search_threads, 0); rb_define_method(notmuch_rb_cQuery, "search_messages", notmuch_rb_query_search_messages, 0); - notmuch_rb_cThreads = rb_define_class_under(mod, "Threads", rb_cObject); + notmuch_rb_cThreads = rb_define_class_under(mod, "Threads", rb_cData); rb_undef_method(notmuch_rb_cThreads, "initialize"); rb_define_method(notmuch_rb_cThreads, "destroy", notmuch_rb_threads_destroy, 0); rb_define_method(notmuch_rb_cThreads, "each", notmuch_rb_threads_each, 0); rb_include_module(notmuch_rb_cThreads, rb_mEnumerable); - notmuch_rb_cMessages = rb_define_class_under(mod, "Messages", rb_cObject); + notmuch_rb_cMessages = rb_define_class_under(mod, "Messages", rb_cData); rb_undef_method(notmuch_rb_cMessages, "initialize"); rb_define_method(notmuch_rb_cMessages, "destroy", notmuch_rb_messages_destroy, 0); rb_define_method(notmuch_rb_cMessages, "each", notmuch_rb_messages_each, 0); rb_define_method(notmuch_rb_cMessages, "tags", notmuch_rb_messages_collect_tags, 0); rb_include_module(notmuch_rb_cMessages, rb_mEnumerable); - notmuch_rb_cThread = rb_define_class_under(mod, "Thread", rb_cObject); + notmuch_rb_cThread = rb_define_class_under(mod, "Thread", rb_cData); rb_undef_method(notmuch_rb_cThread, "initialize"); rb_define_method(notmuch_rb_cThread, "destroy", notmuch_rb_thread_destroy, 0); rb_define_method(notmuch_rb_cThread, "thread_id", notmuch_rb_thread_get_thread_id, 0); @@ -252,7 +254,7 @@ Init_notmuch(void) rb_define_method(notmuch_rb_cThread, "newest_date", notmuch_rb_thread_get_newest_date, 0); rb_define_method(notmuch_rb_cThread, "tags", notmuch_rb_thread_get_tags, 0); - notmuch_rb_cMessage = rb_define_class_under(mod, "Message", rb_cObject); + notmuch_rb_cMessage = rb_define_class_under(mod, "Message", rb_cData); rb_undef_method(notmuch_rb_cMessage, "initialize"); rb_define_method(notmuch_rb_cMessage, "destroy", notmuch_rb_message_destroy, 0); rb_define_method(notmuch_rb_cMessage, "message_id", notmuch_rb_message_get_message_id, 0); @@ -272,7 +274,7 @@ Init_notmuch(void) rb_define_method(notmuch_rb_cMessage, "freeze", notmuch_rb_message_freeze, 0); rb_define_method(notmuch_rb_cMessage, "thaw", notmuch_rb_message_thaw, 0); - notmuch_rb_cTags = rb_define_class_under(mod, "Tags", rb_cObject); + notmuch_rb_cTags = rb_define_class_under(mod, "Tags", rb_cData); rb_undef_method(notmuch_rb_cTags, "initialize"); rb_define_method(notmuch_rb_cTags, "destroy", notmuch_rb_tags_destroy, 0); rb_define_method(notmuch_rb_cTags, "each", notmuch_rb_tags_each, 0); diff --git a/bindings/ruby/message.c b/bindings/ruby/message.c index 2babfd04..f97e1a4e 100644 --- a/bindings/ruby/message.c +++ b/bindings/ruby/message.c @@ -30,9 +30,10 @@ notmuch_rb_message_destroy(VALUE self) { notmuch_message_t *message; - Data_Get_Struct(self, notmuch_message_t, message); + Data_Get_Notmuch_Message(self, message); notmuch_message_destroy(message); + DATA_PTR(self) = NULL; return Qnil; } @@ -48,7 +49,7 @@ notmuch_rb_message_get_message_id(VALUE self) const char *msgid; notmuch_message_t *message; - Data_Get_Struct(self, notmuch_message_t, message); + Data_Get_Notmuch_Message(self, message); msgid = notmuch_message_get_message_id(message); @@ -66,7 +67,7 @@ notmuch_rb_message_get_thread_id(VALUE self) const char *tid; notmuch_message_t *message; - Data_Get_Struct(self, notmuch_message_t, message); + Data_Get_Notmuch_Message(self, message); tid = notmuch_message_get_thread_id(message); @@ -84,7 +85,7 @@ notmuch_rb_message_get_replies(VALUE self) notmuch_messages_t *messages; notmuch_message_t *message; - Data_Get_Struct(self, notmuch_message_t, message); + Data_Get_Notmuch_Message(self, message); messages = notmuch_message_get_replies(message); @@ -102,7 +103,7 @@ notmuch_rb_message_get_filename(VALUE self) const char *fname; notmuch_message_t *message; - Data_Get_Struct(self, notmuch_message_t, message); + Data_Get_Notmuch_Message(self, message); fname = notmuch_message_get_filename(message); @@ -119,7 +120,7 @@ notmuch_rb_message_get_flag(VALUE self, VALUE flagv) { notmuch_message_t *message; - Data_Get_Struct(self, notmuch_message_t, message); + Data_Get_Notmuch_Message(self, message); if (!FIXNUM_P(flagv)) rb_raise(rb_eTypeError, "Flag not a Fixnum"); @@ -137,7 +138,7 @@ notmuch_rb_message_set_flag(VALUE self, VALUE flagv, VALUE valuev) { notmuch_message_t *message; - Data_Get_Struct(self, notmuch_message_t, message); + Data_Get_Notmuch_Message(self, message); if (!FIXNUM_P(flagv)) rb_raise(rb_eTypeError, "Flag not a Fixnum"); @@ -157,7 +158,7 @@ notmuch_rb_message_get_date(VALUE self) { notmuch_message_t *message; - Data_Get_Struct(self, notmuch_message_t, message); + Data_Get_Notmuch_Message(self, message); return UINT2NUM(notmuch_message_get_date(message)); } @@ -173,7 +174,7 @@ notmuch_rb_message_get_header(VALUE self, VALUE headerv) const char *header, *value; notmuch_message_t *message; - Data_Get_Struct(self, notmuch_message_t, message); + Data_Get_Notmuch_Message(self, message); #if !defined(RSTRING_PTR) #define RSTRING_PTR(v) (RSTRING((v))->ptr) @@ -200,7 +201,7 @@ notmuch_rb_message_get_tags(VALUE self) notmuch_message_t *message; notmuch_tags_t *tags; - Data_Get_Struct(self, notmuch_message_t, message); + Data_Get_Notmuch_Message(self, message); tags = notmuch_message_get_tags(message); if (!tags) @@ -221,7 +222,7 @@ notmuch_rb_message_add_tag(VALUE self, VALUE tagv) notmuch_status_t ret; notmuch_message_t *message; - Data_Get_Struct(self, notmuch_message_t, message); + Data_Get_Notmuch_Message(self, message); #if !defined(RSTRING_PTR) #define RSTRING_PTR(v) (RSTRING((v))->ptr) @@ -248,7 +249,7 @@ notmuch_rb_message_remove_tag(VALUE self, VALUE tagv) notmuch_status_t ret; notmuch_message_t *message; - Data_Get_Struct(self, notmuch_message_t, message); + Data_Get_Notmuch_Message(self, message); #if !defined(RSTRING_PTR) #define RSTRING_PTR(v) (RSTRING((v))->ptr) @@ -274,7 +275,7 @@ notmuch_rb_message_remove_all_tags(VALUE self) notmuch_status_t ret; notmuch_message_t *message; - Data_Get_Struct(self, notmuch_message_t, message); + Data_Get_Notmuch_Message(self, message); ret = notmuch_message_remove_all_tags(message); notmuch_rb_status_raise(ret); @@ -293,7 +294,7 @@ notmuch_rb_message_freeze(VALUE self) notmuch_status_t ret; notmuch_message_t *message; - Data_Get_Struct(self, notmuch_message_t, message); + Data_Get_Notmuch_Message(self, message); ret = notmuch_message_freeze(message); notmuch_rb_status_raise(ret); @@ -312,7 +313,7 @@ notmuch_rb_message_thaw(VALUE self) notmuch_status_t ret; notmuch_message_t *message; - Data_Get_Struct(self, notmuch_message_t, message); + Data_Get_Notmuch_Message(self, message); ret = notmuch_message_thaw(message); notmuch_rb_status_raise(ret); diff --git a/bindings/ruby/messages.c b/bindings/ruby/messages.c index 94b0b0da..35b5d146 100644 --- a/bindings/ruby/messages.c +++ b/bindings/ruby/messages.c @@ -28,11 +28,12 @@ VALUE notmuch_rb_messages_destroy(VALUE self) { - notmuch_messages_t *fnames; + notmuch_messages_t *messages; - Data_Get_Struct(self, notmuch_messages_t, fnames); + Data_Get_Notmuch_Messages(self, messages); - notmuch_messages_destroy(fnames); + notmuch_messages_destroy(messages); + DATA_PTR(self) = NULL; return Qnil; } @@ -48,9 +49,7 @@ notmuch_rb_messages_each(VALUE self) notmuch_message_t *message; notmuch_messages_t *messages; - Data_Get_Struct(self, notmuch_messages_t, messages); - if (!messages) - return self; + Data_Get_Notmuch_Messages(self, messages); for (; notmuch_messages_valid(messages); notmuch_messages_move_to_next(messages)) { message = notmuch_messages_get(messages); @@ -71,7 +70,7 @@ notmuch_rb_messages_collect_tags(VALUE self) notmuch_tags_t *tags; notmuch_messages_t *messages; - Data_Get_Struct(self, notmuch_messages_t, messages); + Data_Get_Notmuch_Messages(self, messages); tags = notmuch_messages_collect_tags(messages); if (!tags) diff --git a/bindings/ruby/query.c b/bindings/ruby/query.c index 5140c008..c5b8a4cc 100644 --- a/bindings/ruby/query.c +++ b/bindings/ruby/query.c @@ -30,9 +30,10 @@ notmuch_rb_query_destroy(VALUE self) { notmuch_query_t *query; - Data_Get_Struct(self, notmuch_query_t, query); + Data_Get_Notmuch_Query(self, query); notmuch_query_destroy(query); + DATA_PTR(self) = NULL; return Qnil; } @@ -47,10 +48,10 @@ notmuch_rb_query_set_sort(VALUE self, VALUE sortv) { notmuch_query_t *query; - Data_Get_Struct(self, notmuch_query_t, query); + Data_Get_Notmuch_Query(self, query); if (!FIXNUM_P(sortv)) - rb_raise(rb_eTypeError, "Not a fixnum"); + rb_raise(rb_eTypeError, "Not a Fixnum"); notmuch_query_set_sort(query, FIX2UINT(sortv)); @@ -68,7 +69,7 @@ notmuch_rb_query_search_threads(VALUE self) notmuch_query_t *query; notmuch_threads_t *threads; - Data_Get_Struct(self, notmuch_query_t, query); + Data_Get_Notmuch_Query(self, query); threads = notmuch_query_search_threads(query); if (!threads) @@ -88,7 +89,7 @@ notmuch_rb_query_search_messages(VALUE self) notmuch_query_t *query; notmuch_messages_t *messages; - Data_Get_Struct(self, notmuch_query_t, query); + Data_Get_Notmuch_Query(self, query); messages = notmuch_query_search_messages(query); if (!messages) diff --git a/bindings/ruby/tags.c b/bindings/ruby/tags.c index 7ca03b6f..d7cd941d 100644 --- a/bindings/ruby/tags.c +++ b/bindings/ruby/tags.c @@ -21,7 +21,7 @@ #include "defs.h" /* - * call-seq: tags.destroy => nil + * call-seq: TAGS.destroy => nil * * Destroys the tags, freeing all resources allocated for it. */ @@ -30,9 +30,10 @@ notmuch_rb_tags_destroy(VALUE self) { notmuch_tags_t *tags; - Data_Get_Struct(self, notmuch_tags_t, tags); + Data_Get_Notmuch_Tags(self, tags); notmuch_tags_destroy(tags); + DATA_PTR(self) = NULL; return Qnil; } @@ -49,9 +50,7 @@ notmuch_rb_tags_each(VALUE self) const char *tag; notmuch_tags_t *tags; - Data_Get_Struct(self, notmuch_tags_t, tags); - if (!tags) - return self; + Data_Get_Notmuch_Tags(self, tags); for (; notmuch_tags_valid(tags); notmuch_tags_move_to_next(tags)) { tag = notmuch_tags_get(tags); diff --git a/bindings/ruby/thread.c b/bindings/ruby/thread.c index 5534fe3f..e5c87366 100644 --- a/bindings/ruby/thread.c +++ b/bindings/ruby/thread.c @@ -30,9 +30,10 @@ notmuch_rb_thread_destroy(VALUE self) { notmuch_thread_t *thread; - Data_Get_Struct(self, notmuch_thread_t, thread); + Data_Get_Notmuch_Thread(self, thread); notmuch_thread_destroy(thread); + DATA_PTR(self) = NULL; return Qnil; } @@ -48,7 +49,7 @@ notmuch_rb_thread_get_thread_id(VALUE self) const char *tid; notmuch_thread_t *thread; - Data_Get_Struct(self, notmuch_thread_t, thread); + Data_Get_Notmuch_Thread(self, thread); tid = notmuch_thread_get_thread_id(thread); @@ -65,7 +66,7 @@ notmuch_rb_thread_get_total_messages(VALUE self) { notmuch_thread_t *thread; - Data_Get_Struct(self, notmuch_thread_t, thread); + Data_Get_Notmuch_Thread(self, thread); return INT2FIX(notmuch_thread_get_total_messages(thread)); } @@ -81,7 +82,7 @@ notmuch_rb_thread_get_toplevel_messages(VALUE self) notmuch_messages_t *messages; notmuch_thread_t *thread; - Data_Get_Struct(self, notmuch_thread_t, thread); + Data_Get_Notmuch_Thread(self, thread); messages = notmuch_thread_get_toplevel_messages(thread); if (!messages) @@ -100,7 +101,7 @@ notmuch_rb_thread_get_matched_messages(VALUE self) { notmuch_thread_t *thread; - Data_Get_Struct(self, notmuch_thread_t, thread); + Data_Get_Notmuch_Thread(self, thread); return INT2FIX(notmuch_thread_get_matched_messages(thread)); } @@ -116,7 +117,7 @@ notmuch_rb_thread_get_authors(VALUE self) const char *authors; notmuch_thread_t *thread; - Data_Get_Struct(self, notmuch_thread_t, thread); + Data_Get_Notmuch_Thread(self, thread); authors = notmuch_thread_get_authors(thread); @@ -134,7 +135,7 @@ notmuch_rb_thread_get_subject(VALUE self) const char *subject; notmuch_thread_t *thread; - Data_Get_Struct(self, notmuch_thread_t, thread); + Data_Get_Notmuch_Thread(self, thread); subject = notmuch_thread_get_subject(thread); @@ -151,7 +152,7 @@ notmuch_rb_thread_get_oldest_date(VALUE self) { notmuch_thread_t *thread; - Data_Get_Struct(self, notmuch_thread_t, thread); + Data_Get_Notmuch_Thread(self, thread); return UINT2NUM(notmuch_thread_get_oldest_date(thread)); } @@ -166,7 +167,7 @@ notmuch_rb_thread_get_newest_date(VALUE self) { notmuch_thread_t *thread; - Data_Get_Struct(self, notmuch_thread_t, thread); + Data_Get_Notmuch_Thread(self, thread); return UINT2NUM(notmuch_thread_get_newest_date(thread)); } @@ -182,7 +183,7 @@ notmuch_rb_thread_get_tags(VALUE self) notmuch_thread_t *thread; notmuch_tags_t *tags; - Data_Get_Struct(self, notmuch_thread_t, thread); + Data_Get_Notmuch_Thread(self, thread); tags = notmuch_thread_get_tags(thread); if (!tags) diff --git a/bindings/ruby/threads.c b/bindings/ruby/threads.c index 09906975..abd51212 100644 --- a/bindings/ruby/threads.c +++ b/bindings/ruby/threads.c @@ -33,11 +33,11 @@ notmuch_rb_threads_destroy(VALUE self) Data_Get_Struct(self, notmuch_threads_t, threads); notmuch_threads_destroy(threads); + DATA_PTR(self) = NULL; return Qnil; } - /* call-seq: THREADS.each {|item| block } => THREADS * * Calls +block+ once for each thread in +self+, passing that element as a @@ -49,9 +49,7 @@ notmuch_rb_threads_each(VALUE self) notmuch_thread_t *thread; notmuch_threads_t *threads; - Data_Get_Struct(self, notmuch_threads_t, threads); - if (!threads) - return self; + Data_Get_Notmuch_Threads(self, threads); for (; notmuch_threads_valid(threads); notmuch_threads_move_to_next(threads)) { thread = notmuch_threads_get(threads);