summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-30 16:55:34 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-30 16:55:34 +0000
commit3deee712f5645d269b573b127ee1dd108e5d0e90 (patch)
tree749671e116b62b229a04205414d8ef8b86f0d918
parentc4eb738b7458c5f38153de5552a281de04586d4e (diff)
* ext/dl/mkcallback.rb: split callback.h to callback-[0-9].c to reduce
memory consumption on compilation. [ruby-dev:31898] * ext/dl/depend: add dependency for callback-[0-9].[co]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18961 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog7
-rw-r--r--ext/dl/depend15
-rw-r--r--ext/dl/extconf.rb7
-rw-r--r--ext/dl/mkcallback.rb68
4 files changed, 69 insertions, 28 deletions
diff --git a/ChangeLog b/ChangeLog
index ff4f1193b53..189d3ccb118 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Sun Aug 31 01:53:31 2008 Tanaka Akira <akr@fsij.org>
+
+ * ext/dl/mkcallback.rb: split callback.h to callback-[0-9].c to reduce
+ memory consumption on compilation. [ruby-dev:31898]
+
+ * ext/dl/depend: add dependency for callback-[0-9].[co].
+
Sun Aug 31 01:27:46 2008 Tanaka Akira <akr@fsij.org>
* ext/dl/mkcallback.rb (foreach_proc_entry): extracted.
diff --git a/ext/dl/depend b/ext/dl/depend
index fe89a9fae3b..1093960e10d 100644
--- a/ext/dl/depend
+++ b/ext/dl/depend
@@ -6,6 +6,19 @@ handle.o: handle.c dl.h $(hdrdir)/ruby.h
dl.o: dl.c dl.h callback.h $(hdrdir)/ruby.h $(hdrdir)/io.h
+callback-0.o: callback-0.c $(hdrdir)/ruby.h
+callback-1.o: callback-1.c $(hdrdir)/ruby.h
+callback-2.o: callback-2.c $(hdrdir)/ruby.h
+callback-3.o: callback-3.c $(hdrdir)/ruby.h
+callback-4.o: callback-4.c $(hdrdir)/ruby.h
+callback-5.o: callback-5.c $(hdrdir)/ruby.h
+callback-6.o: callback-6.c $(hdrdir)/ruby.h
+callback-7.o: callback-7.c $(hdrdir)/ruby.h
+callback-8.o: callback-8.c $(hdrdir)/ruby.h
+
+callback-0.c callback-1.c callback-2.c \
+callback-3.c callback-4.c callback-5.c \
+callback-6.c callback-7.c callback-8.c \
callback.h: $(srcdir)/mkcallback.rb dl.h
@echo "generating callback.h"
- @$(RUBY) $(srcdir)/mkcallback.rb $(srcdir)/dl.h > $@
+ @$(RUBY) $(srcdir)/mkcallback.rb $(srcdir)/dl.h
diff --git a/ext/dl/extconf.rb b/ext/dl/extconf.rb
index abd8d8f781a..8ba6c53d0db 100644
--- a/ext/dl/extconf.rb
+++ b/ext/dl/extconf.rb
@@ -25,6 +25,13 @@ else
check = false
end
+$objs = %w[
+ cfunc.o dl.o cptr.o handle.o
+ callback-0.o callback-1.o callback-2.o callback-3.o
+ callback-4.o callback-5.o callback-6.o callback-7.o
+ callback-8.o
+]
+
if check
$defs << %[-DRUBY_VERSION=\\"#{RUBY_VERSION}\\"]
create_makefile("dl")
diff --git a/ext/dl/mkcallback.rb b/ext/dl/mkcallback.rb
index 84109e2078d..edf9aa7c97c 100644
--- a/ext/dl/mkcallback.rb
+++ b/ext/dl/mkcallback.rb
@@ -1,4 +1,5 @@
-$out ||= $stdout
+$out = open("callback.h", "w")
+
$dl_h = ARGV[0] || "dl.h"
# import DLSTACK_SIZE, DLSTACK_ARGS and so on
@@ -94,7 +95,7 @@ VALUE rb_DLCdeclCallbackAddrs, rb_DLCdeclCallbackProcs;
VALUE rb_DLStdcallCallbackAddrs, rb_DLStdcallCallbackProcs;
/*static void *cdecl_callbacks[MAX_DLTYPE][MAX_CALLBACK];*/
/*static void *stdcall_callbacks[MAX_DLTYPE][MAX_CALLBACK];*/
-static ID cb_call;
+ID rb_dl_cb_call;
EOS
def foreach_proc_entry
@@ -124,7 +125,7 @@ FUNC_#{calltype.upcase}(#{func_name(ty,argc,n,calltype)})(#{(0...argc).collect{|
}.join("\n")
}
cb = rb_ary_entry(rb_ary_entry(#{proc_entry}, #{ty}), #{(n * DLSTACK_SIZE) + argc});
- ret = rb_funcall2(cb, cb_call, #{argc}, #{argc > 0 ? 'args' : 'NULL'});
+ ret = rb_funcall2(cb, rb_dl_cb_call, #{argc}, #{argc > 0 ? 'args' : 'NULL'});
return #{DLTYPE[ty][:conv] ? DLTYPE[ty][:conv] % "ret" : ""};
}
@@ -149,14 +150,42 @@ def gen_push_addr_ary(ty, aryname, calltype)
}.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)
+def gen_callback_file(ty)
+ filename = "callback-#{ty}.c"
+ initname = "rb_dl_init_callbacks_#{ty}"
+ open(filename, "w") {|f|
+ f.puts <<-EOS
+#include "dl.h"
+extern VALUE rb_DLCdeclCallbackAddrs, rb_DLCdeclCallbackProcs;
+extern VALUE rb_DLStdcallCallbackAddrs, rb_DLStdcallCallbackProcs;
+extern ID rb_dl_cb_call;
+ EOS
+ yield f
+ f.puts <<-EOS
+void
+#{initname}()
+{
+#{gen_push_proc_ary(ty, "rb_DLCdeclCallbackProcs")}
+#{gen_push_addr_ary(ty, "rb_DLCdeclCallbackAddrs", CDECL)}
+#{gen_push_proc_ary(ty, "rb_DLStdcallCallbackProcs")}
+#{gen_push_addr_ary(ty, "rb_DLStdcallCallbackAddrs", STDCALL)}
+}
+ EOS
+ }
+ initname
+end
+
+for ty in 0...MAX_DLTYPE
+ initname = gen_callback_file(ty) {|f|
+ foreach_proc_entry do |calltype, proc_entry|
+ for argc in 0...DLSTACK_SIZE
+ for n in 0...MAX_CALLBACK
+ f << gencallback(ty, calltype, proc_entry, argc, n)
+ end
end
end
- end
+ }
+ $out << "void #{initname}();\n"
end
$out << (<<EOS)
@@ -164,7 +193,7 @@ static void
rb_dl_init_callbacks()
{
VALUE tmp;
- cb_call = rb_intern("call");
+ rb_dl_cb_call = rb_intern("call");
tmp = rb_DLCdeclCallbackProcs = rb_ary_new();
rb_define_const(rb_mDL, "CdeclCallbackProcs", tmp);
@@ -180,23 +209,8 @@ rb_dl_init_callbacks()
#{
(0...MAX_DLTYPE).collect{|ty|
- gen_push_proc_ary(ty, "rb_DLCdeclCallbackProcs")
- }.join("\n")
-}
-#{
- (0...MAX_DLTYPE).collect{|ty|
- gen_push_addr_ary(ty, "rb_DLCdeclCallbackAddrs", CDECL)
- }.join("\n")
-}
-#{
- (0...MAX_DLTYPE).collect{|ty|
- gen_push_proc_ary(ty, "rb_DLStdcallCallbackProcs")
- }.join("\n")
-}
-#{
- (0...MAX_DLTYPE).collect{|ty|
- gen_push_addr_ary(ty, "rb_DLStdcallCallbackAddrs", STDCALL)
- }.join("\n")
+ "rb_dl_init_callbacks_#{ty}();\n"
+ }.join("")
}
}
EOS