mat813 / rb-kqueue

An FFI wrapper for kqueue
MIT License
22 stars 12 forks source link

ruby 3 warning: finalizer references object to be finalized #14

Closed marvinthepa closed 3 years ago

marvinthepa commented 3 years ago

When running it via spring-watcher-listen, I get a lot of these warnings:

vendor/bundle/ruby/3.0/gems/rb-kqueue-0.2.6/lib/rb-kqueue/watcher/file.rb:40: warning: finalizer references object to be finalized

It seems to me that this PR: https://github.com/ruby/ruby/pull/3444 created this warning. Following the links, it seems that this https://www.mikeperham.com/2010/02/24/the-trouble-with-ruby-finalizers/ describes the fix: use a class method that creates the lambda:

-        ObjectSpace.define_finalizer(self, lambda do
+        ObjectSpace.define_finalizer(self, self.class.finalize(@fd, path))

...

+      def self.finalize(fd, path)
+        lambda do
+          next unless Native.close(fd) < 0
+          ...

Please note that I have not tested this.

Do you want a pull request?