X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=bindings%2Fruby%2Fdefs.h;h=6dbaa85dcfbcd0fd5ec03146d11d176483245cfa;hb=fba9774a81e90a179ccfa810c47a501eaf266e2b;hp=e95ea239b0cea8c222c71e72d6b225f75f371641;hpb=2e57ffb860f2ca986fcb60548e4907d6e8fa912a;p=notmuch diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h index e95ea239..6dbaa85d 100644 --- a/bindings/ruby/defs.h +++ b/bindings/ruby/defs.h @@ -55,40 +55,46 @@ extern ID ID_db_mode; # define RSTRING_PTR(v) (RSTRING((v))->ptr) #endif /* !defined (RSTRING_PTR) */ -#define Data_Get_Notmuch_Object(obj, type, message, ptr) \ - do { \ - Check_Type ((obj), T_DATA); \ - if (DATA_PTR ((obj)) == NULL) \ - rb_raise (rb_eRuntimeError, (message)); \ - Data_Get_Struct ((obj), type, (ptr)); \ +extern const rb_data_type_t notmuch_rb_object_type; + +#define Data_Get_Notmuch_Object(obj, ptr) \ + do { \ + (ptr) = rb_check_typeddata ((obj), ¬much_rb_object_type); \ + if (RB_UNLIKELY (!(ptr))) { \ + VALUE cname = rb_class_name (CLASS_OF ((obj))); \ + rb_raise (rb_eRuntimeError, "%"PRIsVALUE" object destroyed", cname); \ + } \ } while (0) +#define Data_Wrap_Notmuch_Object(klass, ptr) \ + TypedData_Wrap_Struct ((klass), ¬much_rb_object_type, (ptr)) + #define Data_Get_Notmuch_Database(obj, ptr) \ - Data_Get_Notmuch_Object ((obj), notmuch_database_t, "database closed", (ptr)) + Data_Get_Notmuch_Object ((obj), (ptr)) #define Data_Get_Notmuch_Directory(obj, ptr) \ - Data_Get_Notmuch_Object ((obj), notmuch_directory_t, "directory destroyed", (ptr)) + Data_Get_Notmuch_Object ((obj), (ptr)) #define Data_Get_Notmuch_FileNames(obj, ptr) \ - Data_Get_Notmuch_Object ((obj), notmuch_filenames_t, "filenames destroyed", (ptr)) + Data_Get_Notmuch_Object ((obj), (ptr)) #define Data_Get_Notmuch_Query(obj, ptr) \ - Data_Get_Notmuch_Object ((obj), notmuch_query_t, "query destroyed", (ptr)) + Data_Get_Notmuch_Object ((obj), (ptr)) #define Data_Get_Notmuch_Threads(obj, ptr) \ - Data_Get_Notmuch_Object ((obj), notmuch_threads_t, "threads destroyed", (ptr)) + Data_Get_Notmuch_Object ((obj), (ptr)) #define Data_Get_Notmuch_Messages(obj, ptr) \ - Data_Get_Notmuch_Object ((obj), notmuch_messages_t, "messages destroyed", (ptr)) + Data_Get_Notmuch_Object ((obj), (ptr)) #define Data_Get_Notmuch_Thread(obj, ptr) \ - Data_Get_Notmuch_Object ((obj), notmuch_thread_t, "thread destroyed", (ptr)) + Data_Get_Notmuch_Object ((obj), (ptr)) #define Data_Get_Notmuch_Message(obj, ptr) \ - Data_Get_Notmuch_Object ((obj), notmuch_message_t, "message destroyed", (ptr)) + Data_Get_Notmuch_Object ((obj), (ptr)) #define Data_Get_Notmuch_Tags(obj, ptr) \ - Data_Get_Notmuch_Object ((obj), notmuch_tags_t, "tags destroyed", (ptr)) + Data_Get_Notmuch_Object ((obj), (ptr)) /* status.c */ void