diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-30 16:29:03 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-30 16:29:03 +0000 |
commit | f69c1c5eda68751caa3a9ac3f8cbf081de9a8c20 (patch) | |
tree | cd240a547dd18ff6e2d0871e94b5c9de79ed77f5 | |
parent | a2a32f9f02cf0ee90b1d7c8bb35ce6e9f9eb222e (diff) | |
download | ruby-f69c1c5eda68751caa3a9ac3f8cbf081de9a8c20.tar.gz |
* ext/dl/mkcallback.rb (foreach_proc_entry): extracted.
(gencallback): ditto.
(gen_push_proc_ary): ditto.
(gen_push_addr_ary): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18959 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | ext/dl/mkcallback.rb | 82 |
2 files changed, 52 insertions, 37 deletions
@@ -1,3 +1,10 @@ +Sun Aug 31 01:27:46 2008 Tanaka Akira <akr@fsij.org> + + * ext/dl/mkcallback.rb (foreach_proc_entry): extracted. + (gencallback): ditto. + (gen_push_proc_ary): ditto. + (gen_push_addr_ary): ditto. + Sat Aug 30 23:51:01 2008 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp> * test/rinda/test_tuplebag.rb (test_has_expires_eh): fix failures diff --git a/ext/dl/mkcallback.rb b/ext/dl/mkcallback.rb index 89d3a1c10b..84109e2078 100644 --- a/ext/dl/mkcallback.rb +++ b/ext/dl/mkcallback.rb @@ -97,19 +97,22 @@ VALUE rb_DLStdcallCallbackAddrs, rb_DLStdcallCallbackProcs; static ID cb_call; EOS -for calltype in CALLTYPES - case calltype - when CDECL - proc_entry = "rb_DLCdeclCallbackProcs" - when STDCALL - proc_entry = "rb_DLStdcallCallbackProcs" - else - raise "unknown calltype: #{calltype}" +def foreach_proc_entry + for calltype in CALLTYPES + case calltype + when CDECL + proc_entry = "rb_DLCdeclCallbackProcs" + when STDCALL + proc_entry = "rb_DLStdcallCallbackProcs" + else + raise "unknown calltype: #{calltype}" + end + yield calltype, proc_entry end - for ty in 0..(MAX_DLTYPE-1) - for argc in 0..(DLSTACK_SIZE-1) - for n in 0..(MAX_CALLBACK-1) - $out << (<<-EOS) +end + +def gencallback(ty, calltype, proc_entry, argc, n) + <<-EOS static #{DLTYPE[ty][:type]} FUNC_#{calltype.upcase}(#{func_name(ty,argc,n,calltype)})(#{(0...argc).collect{|i| "DLSTACK_TYPE stack" + i.to_s}.join(", ")}) @@ -125,7 +128,32 @@ FUNC_#{calltype.upcase}(#{func_name(ty,argc,n,calltype)})(#{(0...argc).collect{| return #{DLTYPE[ty][:conv] ? DLTYPE[ty][:conv] % "ret" : ""}; } - EOS + EOS +end + +def gen_push_proc_ary(ty, aryname) + sprintf(" rb_ary_push(#{aryname}, rb_ary_new3(%d,%s));", + MAX_CALLBACK * DLSTACK_SIZE, + (0...MAX_CALLBACK).collect{ + (0...DLSTACK_SIZE).collect{ "Qnil" }.join(",") + }.join(",")) +end + +def gen_push_addr_ary(ty, aryname, calltype) + sprintf(" rb_ary_push(#{aryname}, rb_ary_new3(%d,%s));", + MAX_CALLBACK * DLSTACK_SIZE, + (0...MAX_CALLBACK).collect{|i| + (0...DLSTACK_SIZE).collect{|argc| + "PTR2NUM(%s)" % func_name(ty,argc,i,calltype) + }.join(",") + }.join(",")) +end + +foreach_proc_entry do |calltype, proc_entry| + for ty in 0..(MAX_DLTYPE-1) + for argc in 0..(DLSTACK_SIZE-1) + for n in 0..(MAX_CALLBACK-1) + $out << gencallback(ty, calltype, proc_entry, argc, n) end end end @@ -152,42 +180,22 @@ rb_dl_init_callbacks() #{ (0...MAX_DLTYPE).collect{|ty| - sprintf(" rb_ary_push(rb_DLCdeclCallbackProcs, rb_ary_new3(%d,%s));", - MAX_CALLBACK * DLSTACK_SIZE, - (0...MAX_CALLBACK).collect{ - (0...DLSTACK_SIZE).collect{ "Qnil" }.join(",") - }.join(",")) + gen_push_proc_ary(ty, "rb_DLCdeclCallbackProcs") }.join("\n") } #{ (0...MAX_DLTYPE).collect{|ty| - sprintf(" rb_ary_push(rb_DLCdeclCallbackAddrs, rb_ary_new3(%d,%s));", - MAX_CALLBACK * DLSTACK_SIZE, - (0...MAX_CALLBACK).collect{|i| - (0...DLSTACK_SIZE).collect{|argc| - "PTR2NUM(%s)" % func_name(ty,argc,i,CDECL) - }.join(",") - }.join(",")) + gen_push_addr_ary(ty, "rb_DLCdeclCallbackAddrs", CDECL) }.join("\n") } #{ (0...MAX_DLTYPE).collect{|ty| - sprintf(" rb_ary_push(rb_DLStdcallCallbackProcs, rb_ary_new3(%d,%s));", - MAX_CALLBACK * DLSTACK_SIZE, - (0...MAX_CALLBACK).collect{ - (0...DLSTACK_SIZE).collect{ "Qnil" }.join(",") - }.join(",")) + gen_push_proc_ary(ty, "rb_DLStdcallCallbackProcs") }.join("\n") } #{ (0...MAX_DLTYPE).collect{|ty| - sprintf(" rb_ary_push(rb_DLStdcallCallbackAddrs, rb_ary_new3(%d,%s));", - MAX_CALLBACK * DLSTACK_SIZE, - (0...MAX_CALLBACK).collect{|i| - (0...DLSTACK_SIZE).collect{|argc| - "PTR2NUM(%s)" % func_name(ty,argc,i,STDCALL) - }.join(",") - }.join(",")) + gen_push_addr_ary(ty, "rb_DLStdcallCallbackAddrs", STDCALL) }.join("\n") } } |