summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--ext/dl/callback/depend18
-rw-r--r--ext/dl/callback/extconf.rb15
-rw-r--r--ext/dl/callback/mkcallback.rb (renamed from ext/dl/mkcallback.rb)19
-rw-r--r--ext/dl/depend19
-rw-r--r--ext/dl/dl.c19
-rw-r--r--ext/dl/extconf.rb8
7 files changed, 68 insertions, 36 deletions
diff --git a/ChangeLog b/ChangeLog
index 53b8d0384c4..e529cae52f7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,8 @@
-Tue Mar 3 15:09:12 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Tue Mar 3 15:40:38 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * ext/dl/dl.c (rb_dl_init_callbacks): autoloads callbacks.
+
+ * ext/dl/callback: split from dl.
* ext/dl/lib/dl/cparser.rb (DL::CParser::parse_signature): fixed
variable name.
diff --git a/ext/dl/callback/depend b/ext/dl/callback/depend
new file mode 100644
index 00000000000..aeca53f0ccc
--- /dev/null
+++ b/ext/dl/callback/depend
@@ -0,0 +1,18 @@
+callback.o: $(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.c: $(srcdir)/mkcallback.rb $(srcdir)/../dl.h
+ @echo "generating callback.h"
+ @$(RUBY) $(srcdir)/mkcallback.rb $(srcdir)/../dl.h
diff --git a/ext/dl/callback/extconf.rb b/ext/dl/callback/extconf.rb
new file mode 100644
index 00000000000..46aba28397d
--- /dev/null
+++ b/ext/dl/callback/extconf.rb
@@ -0,0 +1,15 @@
+require 'mkmf'
+
+if compiled?("dl")
+ CALLBACKS = (0..8).map{|i| "callback-#{i}"}
+ CALLBACK_SRCS = CALLBACKS.map{|basename| "#{basename}.c"}
+ CALLBACK_OBJS = CALLBACKS.map{|basename| "#{basename}.o"}
+
+ $distcleanfiles += [ "callback.h", *CALLBACK_SRCS ]
+
+ $objs = %w[ callback.o ] + CALLBACK_OBJS
+
+ $INCFLAGS << " -I$(srcdir)/.."
+
+ create_makefile("dl/callback")
+end
diff --git a/ext/dl/mkcallback.rb b/ext/dl/callback/mkcallback.rb
index 1cac0857bbc..a210a686e1b 100644
--- a/ext/dl/mkcallback.rb
+++ b/ext/dl/callback/mkcallback.rb
@@ -1,4 +1,4 @@
-$out = open("callback.h", "w")
+$out = open("callback.c", "w")
$dl_h = ARGV[0] || "dl.h"
@@ -91,10 +91,16 @@ def func_name(ty, argc, n, calltype)
end
$out << (<<EOS)
+#include "ruby.h"
+
VALUE rb_DLCdeclCallbackAddrs, rb_DLCdeclCallbackProcs;
+#ifdef FUNC_STDCALL
VALUE rb_DLStdcallCallbackAddrs, rb_DLStdcallCallbackProcs;
+#endif
/*static void *cdecl_callbacks[MAX_DLTYPE][MAX_CALLBACK];*/
+#ifdef FUNC_STDCALL
/*static void *stdcall_callbacks[MAX_DLTYPE][MAX_CALLBACK];*/
+#endif
ID rb_dl_cb_call;
EOS
@@ -156,6 +162,7 @@ def gen_callback_file(ty)
open(filename, "w") {|f|
f.puts <<-EOS
#include "dl.h"
+
extern VALUE rb_DLCdeclCallbackAddrs, rb_DLCdeclCallbackProcs;
#ifdef FUNC_STDCALL
extern VALUE rb_DLStdcallCallbackAddrs, rb_DLStdcallCallbackProcs;
@@ -193,10 +200,12 @@ for ty in 0...MAX_DLTYPE
end
$out << (<<EOS)
-static void
-rb_dl_init_callbacks()
+void
+Init_callback(void)
{
VALUE tmp;
+ VALUE rb_mDL = rb_path2class("DL");
+
rb_dl_cb_call = rb_intern("call");
tmp = rb_DLCdeclCallbackProcs = rb_ary_new();
@@ -215,8 +224,8 @@ rb_dl_init_callbacks()
#{
(0...MAX_DLTYPE).collect{|ty|
- " rb_dl_init_callbacks_#{ty}();\n"
- }.join("")
+ " rb_dl_init_callbacks_#{ty}();"
+ }.join("\n")
}
}
EOS
diff --git a/ext/dl/depend b/ext/dl/depend
index 1093960e10d..992c17c1b81 100644
--- a/ext/dl/depend
+++ b/ext/dl/depend
@@ -4,21 +4,4 @@ cptr.o: cptr.c dl.h $(hdrdir)/ruby.h $(hdrdir)/io.h
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
+dl.o: dl.c dl.h $(hdrdir)/ruby.h $(hdrdir)/io.h
diff --git a/ext/dl/dl.c b/ext/dl/dl.c
index 0427dfb3f3f..984a62a7efb 100644
--- a/ext/dl/dl.c
+++ b/ext/dl/dl.c
@@ -60,7 +60,18 @@ rb_dl_value2ptr(VALUE self, VALUE val)
return PTR2NUM((void*)val);
}
-#include "callback.h"
+static void
+rb_dl_init_callbacks(VALUE dl)
+{
+ static const char cb[] = "dl/callback.so";
+
+ rb_autoload(dl, rb_intern_const("CdeclCallbackAddrs"), cb);
+ rb_autoload(dl, rb_intern_const("CdeclCallbackProcs"), cb);
+#ifdef FUNC_STDCALL
+ rb_autoload(dl, rb_intern_const("StdcallCallbackAddrs"), cb);
+ rb_autoload(dl, rb_intern_const("StdcallCallbackProcs"), cb);
+#endif
+}
void
Init_dl()
@@ -69,8 +80,8 @@ Init_dl()
void Init_dlcfunc();
void Init_dlptr();
- rbdl_id_cdecl = rb_intern("cdecl");
- rbdl_id_stdcall = rb_intern("stdcall");
+ rbdl_id_cdecl = rb_intern_const("cdecl");
+ rbdl_id_stdcall = rb_intern_const("stdcall");
rb_mDL = rb_define_module("DL");
rb_eDLError = rb_define_class_under(rb_mDL, "DLError", rb_eStandardError);
@@ -79,7 +90,7 @@ Init_dl()
rb_define_const(rb_mDL, "MAX_CALLBACK", INT2NUM(MAX_CALLBACK));
rb_define_const(rb_mDL, "DLSTACK_SIZE", INT2NUM(DLSTACK_SIZE));
- rb_dl_init_callbacks();
+ rb_dl_init_callbacks(rb_mDL);
rb_define_const(rb_mDL, "RTLD_GLOBAL", INT2NUM(RTLD_GLOBAL));
rb_define_const(rb_mDL, "RTLD_LAZY", INT2NUM(RTLD_LAZY));
diff --git a/ext/dl/extconf.rb b/ext/dl/extconf.rb
index c0b8ffd0a11..36babf4143e 100644
--- a/ext/dl/extconf.rb
+++ b/ext/dl/extconf.rb
@@ -4,15 +4,9 @@ if( RbConfig::CONFIG['CC'] =~ /gcc/ )
$CFLAGS << " -fno-defer-pop -fno-omit-frame-pointer"
end
-CALLBACKS = (0..8).map{|i| "callback-#{i}"}
-CALLBACK_SRCS = CALLBACKS.map{|basename| "#{basename}.c"}
-CALLBACK_OBJS = CALLBACKS.map{|basename| "#{basename}.o"}
-
$INSTALLFILES = [
["dl.h", "$(HDRDIR)"],
]
-$distcleanfiles += [ "callback.h", *CALLBACK_SRCS ]
-
check = true
if( have_header("dlfcn.h") )
@@ -29,8 +23,6 @@ else
check = false
end
-$objs = %w[ cfunc.o dl.o cptr.o handle.o ] + CALLBACK_OBJS
-
if check
$defs << %[-DRUBY_VERSION=\\"#{RUBY_VERSION}\\"]
create_makefile("dl")