[Bug #1453] dl in ruby-1.9 must check whether block is given to TempFunction


#1

Bug #1453: dl in ruby-1.9 must check whether block is given to
TempFunction
http://redmine.ruby-lang.org/issues/show/1453

e$B5/I<<Te(B: Takashi T.
e$B%9%F!<%?%9e(B: Open, e$BM%@hEYe(B: Normal
e$B%+%F%4%je(B: ext, Target version: 1.9.2
ruby -v: ruby 1.9.2dev (2009-05-02 trunk 23326) [i686-linux]

e$B0J2<$N$h$&$K%V%m%C%/IU$-$G8F$V$Y$-$H$3$m$G8F$P$J$$$HMn$A$^$9!#e(B

$ cat d7.rb
require ‘dl/import’

require ‘dl/import’
module M
extend DL::Importer
dlload “libc.so.6”
QsortCallbackWithoutBlock = bind(“void qsort_callback(void,
void*)”, :temp)
extern ‘void qsort(void *, int, int, void *)’
end
buff = “3465721”
M.qsort(buff, buff.size, 1, M::QsortCallbackWithoutBlock) # <=
e$B$3$3$O%V%m%C%/$D$-$G8F$P$J$$$H$$$1$J$$!#e(B

$ ruby-1.9 d7.rb
/usr/local/pkg/ruby-1.9/lib/ruby/1.9.1/dl/func.rb:37: [BUG] Segmentation
fault
ruby 1.9.2dev (2009-05-02 trunk 23326) [i686-linux]

e$B%V%m%C%/$,M?$($i$l$?$+$r%A%’%C%/$9$k%Q%C%A$G$9!#e(B

Index: lib/dl/value.rb

— lib/dl/value.rb (e$B%j%S%8%g%se(B 23328)
+++ lib/dl/value.rb (e$B:n6H%3%T!<e(B)
@@ -63,6 +63,8 @@ module DL
if( block )
arg.bind_at_call(&block)
funcs.push(arg)

  •      elsif arg.is_a?(TempFunction)
    
  •        raise(RuntimeError, "block must be given.")
         end
         return arg.to_i
       when String

#2

e$B%A%1%C%He(B #1453 e$B$,99?7$5$l$^$7$?!#e(B (by Nobuyoshi N.)

e$B%9%F!<%?%9e(B Opene$B$+$ie(BClosede$B$KJQ99e(B
e$B?JD=e(B % 0e$B$+$ie(B100e$B$KJQ99e(B

Applied in changeset r23386.

http://redmine.ruby-lang.org/issues/show/1453