mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/dl/dl.c (rb_dl_init_callbacks): autoloads callbacks.
* ext/dl/callback: split from dl. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22722 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
2233d34b39
commit
1001173ccd
7 changed files with 68 additions and 36 deletions
|
@ -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.
|
||||
|
|
18
ext/dl/callback/depend
Normal file
18
ext/dl/callback/depend
Normal file
|
@ -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
|
15
ext/dl/callback/extconf.rb
Normal file
15
ext/dl/callback/extconf.rb
Normal file
|
@ -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
|
|
@ -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
|
|
@ -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
|
||||
|
|
19
ext/dl/dl.c
19
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));
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue