[前][次][番号順一覧][スレッド一覧]

ruby-changes:2374

From: ko1@a...
Date: 10 Nov 2007 18:23:11 +0900
Subject: [ruby-changes:2374] akr - Ruby:r13865 (trunk): * gem_prelude.rb: new file for gem libraries. currently empty.

akr	2007-11-10 18:22:59 +0900 (Sat, 10 Nov 2007)

  New Revision: 13865

  Added files:
    trunk/gem_prelude.rb
  Modified directories:
    trunk/
  Modified files:
    trunk/ChangeLog
    trunk/Makefile.in
    trunk/common.mk
    trunk/inits.c
    trunk/ruby.c
    trunk/tool/compile_prelude.rb

  Log:
    * 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.

  Modified: trunk/

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk?r1=13865&r2=13864
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/tool/compile_prelude.rb?r1=13865&r2=13864
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ruby.c?r1=13865&r2=13864
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/Makefile.in?r1=13865&r2=13864
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=13865&r2=13864
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/gem_prelude.rb?revision=13865&view=markup
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/inits.c?r1=13865&r2=13864
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/common.mk?r1=13865&r2=13864

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 13864)
+++ ChangeLog	(revision 13865)
@@ -1,3 +1,19 @@
+Sat Nov 10 18:10:07 2007  Tanaka Akira  <akr@f...>
+
+	* 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  <shugo@r...>
 
 	* thread.c (call_trace_proc): don't call ID2SYM() for ID_ALLOCATOR
Index: gem_prelude.rb
===================================================================
--- gem_prelude.rb	(revision 0)
+++ gem_prelude.rb	(revision 13865)
@@ -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"]
Index: common.mk
===================================================================
--- common.mk	(revision 13864)
+++ common.mk	(revision 13865)
@@ -15,7 +15,7 @@
 
 DMYEXT	      = dmyext.$(OBJEXT)
 MAINOBJ	      = main.$(OBJEXT)
-EXTOBJS	      = 
+EXTOBJS	      = ext_prelude.$(OBJEXT)
 DLDOBJS	      = $(DMYEXT)
 
 ENCOBJS       = ascii.$(OBJEXT) \
@@ -78,7 +78,6 @@
 		thread.$(OBJEXT) \
 		cont.$(OBJEXT) \
 		id.$(OBJEXT) \
-		prelude.$(OBJEXT) \
 		$(ENCOBJS) \
 		$(MISSING)
 
@@ -586,6 +585,7 @@
         {$(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 @@
 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:
Index: Makefile.in
===================================================================
--- Makefile.in	(revision 13864)
+++ Makefile.in	(revision 13865)
@@ -50,7 +50,7 @@
 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@
Index: inits.c
===================================================================
--- inits.c	(revision 13864)
+++ inits.c	(revision 13865)
@@ -51,7 +51,6 @@
 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 @@
     Init_Thread();
     Init_Cont();
     Init_version();
-    Init_prelude();
 }
Index: ruby.c
===================================================================
--- ruby.c	(revision 13864)
+++ ruby.c	(revision 13865)
@@ -75,6 +75,7 @@
     int usage;
     int version;
     int copyright;
+    int disable_gems;
     int verbose;
     int yydebug;
     char *script;
@@ -121,6 +122,7 @@
 	"-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 @@
 		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 @@
     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_sflag(opt);
 
     ruby_init_loadpath();
+    ruby_init_gems(opt);
     parser = rb_parser_new();
     if (opt->e_script) {
 	if (opt->enc_index >= 0)
Index: tool/compile_prelude.rb
===================================================================
--- tool/compile_prelude.rb	(revision 13864)
+++ tool/compile_prelude.rb	(revision 13865)
@@ -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 <<EOS__, <<'EOS__'
+  f.puts <<'EOS__'
 
 #include "ruby/ruby.h"
 #include "vm_core.h"
 
-static const char prelude_name[] = "#{File.basename(prelude)}";
-static const char prelude_code[] =
+EOS__
+
+  preludes.zip(lines_list).each_with_index {|(prelude, lines), i|
+    f.puts <<EOS__
+static const char prelude_name#{i}[] = "#{File.basename(prelude)}";
+static const char prelude_code#{i}[] =
 #{lines.join("\n")}
 ;
 EOS__
+  }
+  f.puts <<'EOS__'
 
 void
 Init_prelude(void)
 {
+EOS__
+  preludes.length.times {|i|
+    f.puts <<EOS__
   rb_iseq_eval(rb_iseq_compile(
-    rb_str_new(prelude_code, sizeof(prelude_code) - 1),
-    rb_str_new(prelude_name, sizeof(prelude_name) - 1),
+    rb_str_new(prelude_code#{i}, sizeof(prelude_code#{i}) - 1),
+    rb_str_new(prelude_name#{i}, sizeof(prelude_name#{i}) - 1),
     INT2FIX(1)));
 
+EOS__
+  }
+    f.puts <<EOS__
 #if 0
-    printf("%s\n", prelude_code);
+EOS__
+  preludes.length.times {|i|
+    f.puts <<EOS__
+    puts(prelude_code#{i});
+EOS__
+  }
+    f.puts <<EOS__
 #endif
+EOS__
+
+  f.puts <<'EOS__'
 }
 EOS__
 }

Property changes on: 
___________________________________________________________________
Name: svn:ignore
   + *.bak
*.inc
*.orig
*.rej
*.sav
*~
.*-*
.*.list
.*.time
.ccmalloc
.ext
.git
.pc
.ppack
.svn
COPYING.LIB
ChangeLog-1.8.0
ChangeLog.pre-alpha
ChangeLog.pre1_1
Makefile
README.atheos
README.fat-patch
README.v6
archive
autom4te*.cache
automake
beos
config.cache
config.h
config.h.in
config.log
config.status
configure
lex.c
libruby-static.a
libruby.so.*
*.dylib
miniruby
newdate.rb
newver.rb
parse.c
patches
patches-master
pitest.rb
ppack
prelude.c
ext_prelude.c
preview
rbconfig.rb
rename2.h
repack
riscos
rubicon
ruby
ruby-man.rd.gz
test.rb
tmp
web
y.output
y.tab.c
yasmdata.rb



--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml

[前][次][番号順一覧][スレッド一覧]