[PATCH] ruby: fix "undefining the allocator of T_DATA" warnings

Subject: [PATCH] ruby: fix "undefining the allocator of T_DATA" warnings

Date: Sun, 1 Sep 2024 02:02:10 +0200

To: notmuch@notmuchmail.org

Cc: Johannes Larsen

From: Johannes Larsen


Ruby 3.2 introduced a warning when C-extensions use structs without
redefining the allocation default allocation routine meant for objects.
See https://bugs.ruby-lang.org/issues/18007 for details.

In the Ruby bindings this happens at `Data_Wrap_Notmuch_Object` call
sites, so the object types used there needed to update their allocation.

This ruby code (given a database at the hardcoded path with messages
matching `tag:tmp`) exercise all the ruby objects:

    require 'notmuch'
    Notmuch::Database.open File.expand_path("~/mail") do |db|
      db.get_directory("/tmp")
      db.query("tag:tmp").search_threads.each do |t|
        t.messages.each do |m|
          puts m.header("Subject")
        end
      end
    end

Before these changes with ruby 3.2.5 and notmuch 0.38.3 it outputs:

    notmuch.rb:5: warning: undefining the allocator of T_DATA class Notmuch::Query
    notmuch.rb:5: warning: undefining the allocator of T_DATA class Notmuch::Threads
    notmuch.rb:5: warning: undefining the allocator of T_DATA class Notmuch::Thread
    notmuch.rb:6: warning: undefining the allocator of T_DATA class Notmuch::Messages
    notmuch.rb:6: warning: undefining the allocator of T_DATA class Notmuch::Message
    notmuch release 0.38.3 now available

(the last line is the message I tagged with tmp), and after the changes:

    notmuch release 0.38.3 now available
---
 bindings/ruby/init.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c
index 2d1994af..10558a33 100644
--- a/bindings/ruby/init.c
+++ b/bindings/ruby/init.c
@@ -294,4 +294,5 @@ Init_notmuch (void)
      */
     notmuch_rb_cQuery = rb_define_class_under (mod, "Query", rb_cObject);
+    rb_undef_alloc_func(notmuch_rb_cQuery);
     rb_undef_method (notmuch_rb_cQuery, "initialize");
     rb_define_method (notmuch_rb_cQuery, "destroy!", notmuch_rb_query_destroy, 0); /* in query.c */
@@ -312,4 +313,5 @@ Init_notmuch (void)
      */
     notmuch_rb_cThreads = rb_define_class_under (mod, "Threads", rb_cObject);
+    rb_undef_alloc_func(notmuch_rb_cThreads);
     rb_undef_method (notmuch_rb_cThreads, "initialize");
     rb_define_method (notmuch_rb_cThreads, "destroy!", notmuch_rb_threads_destroy, 0); /* in threads.c */
@@ -323,4 +325,5 @@ Init_notmuch (void)
      */
     notmuch_rb_cMessages = rb_define_class_under (mod, "Messages", rb_cObject);
+    rb_undef_alloc_func(notmuch_rb_cMessages);
     rb_undef_method (notmuch_rb_cMessages, "initialize");
     rb_define_method (notmuch_rb_cMessages, "destroy!", notmuch_rb_messages_destroy, 0); /* in messages.c */
@@ -335,4 +338,5 @@ Init_notmuch (void)
      */
     notmuch_rb_cThread = rb_define_class_under (mod, "Thread", rb_cObject);
+    rb_undef_alloc_func(notmuch_rb_cThread);
     rb_undef_method (notmuch_rb_cThread, "initialize");
     rb_define_method (notmuch_rb_cThread, "destroy!", notmuch_rb_thread_destroy, 0); /* in thread.c */
@@ -354,4 +358,5 @@ Init_notmuch (void)
      */
     notmuch_rb_cMessage = rb_define_class_under (mod, "Message", rb_cObject);
+    rb_undef_alloc_func(notmuch_rb_cMessage);
     rb_undef_method (notmuch_rb_cMessage, "initialize");
     rb_define_method (notmuch_rb_cMessage, "destroy!", notmuch_rb_message_destroy, 0); /* in message.c */
-- 
2.46.0

_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org

Thread: