ueno / ruby-gpgme

a ruby interface to GnuPG Made Easy (GPGME).
GNU Lesser General Public License v2.1
232 stars 99 forks source link

Ruby 3.2 warning: undefining the allocator of T_DATA class GPGME::Ctx #157

Closed lildude closed 2 years ago

lildude commented 2 years ago

When running ruby-gpgme (and the tests in this repo) on Ruby 3.2.0-preview1 you get several warnings:

/workspaces/ruby-gpgme/lib/gpgme/ctx.rb:47: warning: undefining the allocator of T_DATA class GPGME::Ctx
/workspaces/ruby-gpgme/lib/gpgme/data.rb:71: warning: undefining the allocator of T_DATA class GPGME::Data
/workspaces/ruby-gpgme/lib/gpgme/ctx.rb:283: warning: undefining the allocator of T_DATA class GPGME::Key

See https://bugs.ruby-lang.org/issues/18007 for details on why this warning has been implemented and https://ruby-doc.org/core-3.1.1/doc/extension_rdoc.html#label-C+struct+to+Ruby+object

From a quick test, this diff resolves the issue (the gemspec change is needed to cater for Ruby 3):

diff --git ext/gpgme/gpgme_n.c ext/gpgme/gpgme_n.c
index ad3ca47..3ba15f0 100644
--- ext/gpgme/gpgme_n.c
+++ ext/gpgme/gpgme_n.c
@@ -2298,10 +2298,13 @@ Init_gpgme_n (void)
     rb_define_class_under (mGPGME, "EngineInfo", rb_cObject);
   cCtx =
     rb_define_class_under (mGPGME, "Ctx", rb_cObject);
+  rb_undef_alloc_func(cCtx);
   cData =
     rb_define_class_under (mGPGME, "Data", rb_cObject);
+  rb_undef_alloc_func(cData);
   cKey =
     rb_define_class_under (mGPGME, "Key", rb_cObject);
+  rb_undef_alloc_func(cKey);
   cSubKey =
     rb_define_class_under (mGPGME, "SubKey", rb_cObject);
   cUserID =
diff --git gpgme.gemspec gpgme.gemspec
index 8bb55fc..46dcf85 100644
--- gpgme.gemspec
+++ gpgme.gemspec
@@ -29,8 +29,8 @@ encryption, decryption, signing, signature verification and key management.}
     s.add_development_dependency "debugger" , "~> 1.6.6"
   when /\A1\.9\./
     s.add_development_dependency "ruby-debug19" , "~> 0.11.6"
-  when /\A2\./
-    s.add_development_dependency "byebug" , "~> 3.5.1"
+  when /\A2\./, /\A3\./
+    s.add_development_dependency "byebug" , "~> 11.1.3"
   else
     s.add_development_dependency "ruby-debug" , "~> 0.10.4"
   end

A similar change is probably needed elsewhere, but those locations aren't being tickled by the tests or our usage 😁.