diff --git a/ChangeLog b/ChangeLog index f9a67710f9..38d2b77ba3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +Sat Nov 10 18:10:07 2007 Tanaka Akira + + * gem_prelude.rb: new file for gem libraries. currently empty. + + * common.mk: generate ext_prelude.c by prelude.rb and gem_prelude.rb. + ruby (not miniruby) is linked with ext_prelude.o instead of prelude.o. + * inits.c (rb_call_inits): don't call Init_prelude. + + * ruby.c: support --disable-gems option. + (ruby_init_gems): new function to define Gem::Enable and + invoke Init_prelude. + (process_options): call ruby_init_gems just after + ruby_init_loadpath. + + * tool/compile_prelude.rb: support multiple files. + Sat Nov 10 17:27:55 2007 Shugo Maeda * thread.c (call_trace_proc): don't call ID2SYM() for ID_ALLOCATOR diff --git a/Makefile.in b/Makefile.in index 2c5b4b23a9..99f4a3929d 100644 --- a/Makefile.in +++ b/Makefile.in @@ -50,7 +50,7 @@ LDSHARED = @LIBRUBY_LDSHARED@ DLDFLAGS = @LIBRUBY_DLDFLAGS@ $(EXTLDFLAGS) @ARCH_FLAG@ SOLIBS = @SOLIBS@ MAINLIBS = @MAINLIBS@ -MINIOBJS = @MINIOBJS@ +MINIOBJS = @MINIOBJS@ prelude.$(OBJEXT) RUBY_INSTALL_NAME=@RUBY_INSTALL_NAME@ RUBY_SO_NAME=@RUBY_SO_NAME@ diff --git a/common.mk b/common.mk index 39669487bc..177a058253 100644 --- a/common.mk +++ b/common.mk @@ -15,7 +15,7 @@ RDOCOUT = $(EXTOUT)/rdoc DMYEXT = dmyext.$(OBJEXT) MAINOBJ = main.$(OBJEXT) -EXTOBJS = +EXTOBJS = ext_prelude.$(OBJEXT) DLDOBJS = $(DMYEXT) ENCOBJS = ascii.$(OBJEXT) \ @@ -78,7 +78,6 @@ OBJS = array.$(OBJEXT) \ thread.$(OBJEXT) \ cont.$(OBJEXT) \ id.$(OBJEXT) \ - prelude.$(OBJEXT) \ $(ENCOBJS) \ $(MISSING) @@ -586,6 +585,7 @@ blockinlining.$(OBJEXT): {$(VPATH)}blockinlining.c \ {$(VPATH)}thread_$(THREAD_MODEL).h id.$(OBJEXT): {$(VPATH)}id.c {$(VPATH)}ruby.h prelude.$(OBJEXT): {$(VPATH)}prelude.c {$(VPATH)}ruby.h {$(VPATH)}vm_core.h +ext_prelude.$(OBJEXT): {$(VPATH)}ext_prelude.c {$(VPATH)}ruby.h {$(VPATH)}vm_core.h ascii.$(OBJEXT): {$(VPATH)}ascii.c {$(VPATH)}regenc.h \ {$(VPATH)}oniguruma.h {$(VPATH)}config.h {$(VPATH)}defines.h @@ -631,6 +631,9 @@ node_name.inc: {$(VPATH)}node.h prelude.c: $(srcdir)/tool/compile_prelude.rb $(srcdir)/prelude.rb $(BASERUBY) $(srcdir)/tool/compile_prelude.rb $(srcdir)/prelude.rb $@ +ext_prelude.c: $(srcdir)/tool/compile_prelude.rb $(srcdir)/prelude.rb $(srcdir)/gem_prelude.rb $(RBCONFIG) + $(MINIRUBY) -I$(srcdir) -rrbconfig $(srcdir)/tool/compile_prelude.rb $(srcdir)/prelude.rb $(srcdir)/gem_prelude.rb $@ + prereq: incs {$(VPATH)}prelude.c docs: diff --git a/gem_prelude.rb b/gem_prelude.rb new file mode 100644 index 0000000000..7340efcaaf --- /dev/null +++ b/gem_prelude.rb @@ -0,0 +1,10 @@ +# empty gem_prelude.rb +# +# p Gem::Enable +# p RbConfig::CONFIG["arch"] +# p RbConfig::CONFIG["bindir"] +# p RbConfig::CONFIG["datadir"] +# p RbConfig::CONFIG["sitedir"] +# p RbConfig::CONFIG["sitelibdir"] +# p RbConfig::CONFIG["EXEEXT"] +# p RbConfig::CONFIG["RUBY_SO_NAME"] diff --git a/inits.c b/inits.c index f6e4502dfb..3006bf6098 100644 --- a/inits.c +++ b/inits.c @@ -51,7 +51,6 @@ void Init_VM(void); void Init_Thread(void); void Init_Cont(void); void Init_top_self(void); -void Init_prelude(void); void Init_Encoding(void); void @@ -97,5 +96,4 @@ rb_call_inits() Init_Thread(); Init_Cont(); Init_version(); - Init_prelude(); } diff --git a/ruby.c b/ruby.c index 6dc411eaa0..4285247005 100644 --- a/ruby.c +++ b/ruby.c @@ -75,6 +75,7 @@ struct cmdline_options { int usage; int version; int copyright; + int disable_gems; int verbose; int yydebug; char *script; @@ -121,6 +122,7 @@ usage(const char *name) "-w turn warnings on for your script", "-W[level] set warning level; 0=silence, 1=medium, 2=verbose (default)", "-x[directory] strip off text before #!ruby line and perhaps cd to directory", + "--disable_gems disable gem libraries", "--copyright print the copyright", "--version print the version", NULL @@ -813,6 +815,8 @@ proc_options(int argc, char **argv, struct cmdline_options *opt) ruby_debug = Qtrue; ruby_verbose = Qtrue; } + else if (strcmp("disable-gems", s) == 0) + opt->disable_gems = 1; else if (strcmp("encoding", s) == 0) { if (!--argc || !(s = *++argv)) { noencoding: @@ -873,6 +877,17 @@ proc_options(int argc, char **argv, struct cmdline_options *opt) return argc0 - argc; } +void Init_prelude(void); + +static void +ruby_init_gems(struct cmdline_options *opt) +{ + VALUE gem; + gem = rb_define_module("Gem"); + rb_const_set(gem, rb_intern("Enable"), opt->disable_gems ? Qfalse : Qtrue); + Init_prelude(); +} + static VALUE process_options(VALUE arg) { @@ -976,6 +991,7 @@ process_options(VALUE arg) process_sflag(opt); ruby_init_loadpath(); + ruby_init_gems(opt); parser = rb_parser_new(); if (opt->e_script) { if (opt->enc_index >= 0) diff --git a/tool/compile_prelude.rb b/tool/compile_prelude.rb index 1012d1fbc2..1f67d4c396 100644 --- a/tool/compile_prelude.rb +++ b/tool/compile_prelude.rb @@ -1,33 +1,79 @@ +*preludes, outfile = *ARGV -prelude, outfile = *ARGV +C_ESC = { + "\\" => "\\\\", + '"' => '\"', + "\n" => '\n', +} -lines = File.readlines(prelude).map{|line| - line.dump +0x00.upto(0x1f) {|ch| C_ESC[[ch].pack("C")] ||= "\\x%02x" % ch } +0x7f.upto(0xff) {|ch| C_ESC[[ch].pack("C")] = "\\x%02x" % ch } +C_ESC_PAT = Regexp.union(*C_ESC.keys) + +def c_esc(str) + '"' + str.gsub(C_ESC_PAT) { C_ESC[$&] } + '"' +end + +lines_list = preludes.map {|prelude| + lines = [] + File.readlines(prelude).each {|line| + line.gsub!(/RbConfig::CONFIG\["(\w+)"\]/) { + require 'rbconfig' + if RbConfig::CONFIG.has_key? $1 + c_esc(RbConfig::CONFIG[$1]) + else + $& + end + } + lines << c_esc(line) + } + lines } open(outfile, 'w'){|f| - f.puts <