Skip to content

Instantly share code, notes, and snippets.

@Sixeight
Last active December 12, 2015 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sixeight/4771462 to your computer and use it in GitHub Desktop.
Save Sixeight/4771462 to your computer and use it in GitHub Desktop.
Preference-ENGINE:/Users/tomohiro:(---) 2.0.0-rc2
2:16:> irb
irb(main):001:0> require 'fiddle'
=> true
irb(main):002:0> DL
NameError: uninitialized constant DL
from (irb):2
from /Users/tomohiro/.rbenv/versions/2.0.0-rc2/bin/irb:12:in `<main>'
irb(main):003:0>
Preference-ENGINE:/Users/tomohiro:(---) 2.0.0-rc2
2:18:> irb
irb(main):001:0> require 'dl'
DL is deprecated, please use Fiddle
=> true
irb(main):002:0> DL
=> DL
irb(main):003:0> DL.fiddle?
=> true
irb(main):004:0>
Preference-ENGINE:/Users/tomohiro:(---) 1.9.3-p374
2:18:> irb
irb(main):001:0> require 'fiddle'
=> true
irb(main):002:0> DL
=> DL
irb(main):003:0> DL.fiddle?
=> true
irb(main):004:0>
@Sixeight
Copy link
Author

related commit: ruby/ruby@c1fb6a8

old code requires 'dl' library when DL module was not defined.
ruby/ruby@c1fb6a8#L7L4

@Sixeight
Copy link
Author

We should use Fiddle module instead of DL (maybe)

For example:

$ rbenv shell 1.9.3-p385
$ irb
> require 'fiddle'
> DL::Handle::DEFAULT['getsid']
=> xxx
> Fiddle::Handle::DEFAULT['getsid']
NameError: uninitialized constant Fiddle::Handle
    from (irb):3
    from /Users/tomohiro/.rbenv/versions/1.9.3-p385/bin/irb:12:in `<main>'
> exit

$ rbenv shell 2.0.0-rc2
$ irb
> require 'fiddle'
> Fiddle::Handle::DEFAULT['getsid']
=> xxx
> DL::Handle::DEFAULT['getsid']
NameError: uninitialized constant DL
    from (irb):2
    from /Users/tomohiro/.rbenv/versions/2.0.0-rc2/bin/irb:12:in `<main>'

@Sixeight
Copy link
Author

the problem appears in spring.
following code doesn't run with ruby 2.0.
https://github.com/jonleighton/spring/blob/master/lib/spring/sid.rb

@Sixeight
Copy link
Author

DL is deprecated, please use Fiddle oh...

@tenderlove
Copy link

Sorry, it's not convenient, but you need to conditionalize:

diff --git a/lib/spring/sid.rb b/lib/spring/sid.rb
index 632c694..c70e212 100644
--- a/lib/spring/sid.rb
+++ b/lib/spring/sid.rb
@@ -2,8 +2,14 @@ require 'fiddle'

 module Spring
   module SID
+    if RUBY_VERSION >= '2.0.0'
+      handle = Fiddle::Handle
+    else
+      handle = DL::Handle
+    end
+
     FUNC = Fiddle::Function.new(
-      DL::Handle::DEFAULT['getsid'],
+      handle::DEFAULT['getsid'],
       [Fiddle::TYPE_INT],
       Fiddle::TYPE_INT
     )

I'll send a patch.

@Sixeight
Copy link
Author

@tenderlove Thank you for your information!
and thank you for your patch for spring!

@Sixeight
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment