From 79bb82c2179ea0dd5de384bb1ab6f0f118a035df Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Sat, 15 May 2021 16:20:58 -0500 Subject: [PATCH] ruby: fetch class name in case of error There is not much point in complicating the code for error messages that can be easily constructed. Before: database closed (RuntimeError) After: Notmuch::Database object destroyed (RuntimeError) Signed-off-by: Felipe Contreras --- bindings/ruby/defs.h | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h index 8fb47b4c..ae3ea101 100644 --- a/bindings/ruby/defs.h +++ b/bindings/ruby/defs.h @@ -55,39 +55,41 @@ extern ID ID_db_mode; # define RSTRING_PTR(v) (RSTRING((v))->ptr) #endif /* !defined (RSTRING_PTR) */ -#define Data_Get_Notmuch_Object(obj, message, ptr) \ - do { \ - (ptr) = rb_data_object_get ((obj)); \ - if (!(ptr)) \ - rb_raise (rb_eRuntimeError, (message)); \ +#define Data_Get_Notmuch_Object(obj, ptr) \ + do { \ + (ptr) = rb_data_object_get ((obj)); \ + if (!(ptr)) { \ + VALUE cname = rb_class_name (CLASS_OF ((obj))); \ + rb_raise (rb_eRuntimeError, "%"PRIsVALUE" object destroyed", cname); \ + } \ } while (0) #define Data_Get_Notmuch_Database(obj, ptr) \ - Data_Get_Notmuch_Object ((obj), "database closed", (ptr)) + Data_Get_Notmuch_Object ((obj), (ptr)) #define Data_Get_Notmuch_Directory(obj, ptr) \ - Data_Get_Notmuch_Object ((obj), "directory destroyed", (ptr)) + Data_Get_Notmuch_Object ((obj), (ptr)) #define Data_Get_Notmuch_FileNames(obj, ptr) \ - Data_Get_Notmuch_Object ((obj), "filenames destroyed", (ptr)) + Data_Get_Notmuch_Object ((obj), (ptr)) #define Data_Get_Notmuch_Query(obj, ptr) \ - Data_Get_Notmuch_Object ((obj), "query destroyed", (ptr)) + Data_Get_Notmuch_Object ((obj), (ptr)) #define Data_Get_Notmuch_Threads(obj, ptr) \ - Data_Get_Notmuch_Object ((obj), "threads destroyed", (ptr)) + Data_Get_Notmuch_Object ((obj), (ptr)) #define Data_Get_Notmuch_Messages(obj, ptr) \ - Data_Get_Notmuch_Object ((obj), "messages destroyed", (ptr)) + Data_Get_Notmuch_Object ((obj), (ptr)) #define Data_Get_Notmuch_Thread(obj, ptr) \ - Data_Get_Notmuch_Object ((obj), "thread destroyed", (ptr)) + Data_Get_Notmuch_Object ((obj), (ptr)) #define Data_Get_Notmuch_Message(obj, ptr) \ - Data_Get_Notmuch_Object ((obj), "message destroyed", (ptr)) + Data_Get_Notmuch_Object ((obj), (ptr)) #define Data_Get_Notmuch_Tags(obj, ptr) \ - Data_Get_Notmuch_Object ((obj), "tags destroyed", (ptr)) + Data_Get_Notmuch_Object ((obj), (ptr)) /* status.c */ void