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

ruby-changes:12694

From: nobu <ko1@a...>
Date: Wed, 5 Aug 2009 19:19:39 +0900 (JST)
Subject: [ruby-changes:12694] Ruby:r24410 (trunk): * ruby.c (load_file_internal): assumes -x flag if no "ruby" is in

nobu	2009-08-05 19:19:18 +0900 (Wed, 05 Aug 2009)

  New Revision: 24410

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=24410

  Log:
    * ruby.c (load_file_internal): assumes -x flag if no "ruby" is in
      the shebang line.  [ruby-dev:39015]

  Modified files:
    trunk/ChangeLog
    trunk/ruby.c
    trunk/test/ruby/test_system.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 24409)
+++ ChangeLog	(revision 24410)
@@ -1,3 +1,8 @@
+Wed Aug  5 19:19:13 2009  Nobuyoshi Nakada  <nobu@r...>
+
+	* ruby.c (load_file_internal): assumes -x flag if no "ruby" is in
+	  the shebang line.  [ruby-dev:39015]
+
 Wed Aug  5 19:11:01 2009  NARUSE, Yui  <naruse@r...>
 
 	* ruby.c (rb_stdio_set_default_encoding): declared.
Index: ruby.c
===================================================================
--- ruby.c	(revision 24409)
+++ ruby.c	(revision 24410)
@@ -1508,6 +1508,7 @@
 	rb_funcall(f, set_encoding, 1, rb_enc_from_encoding(enc));
 
 	if (opt->xflag) {
+	  search_shebang:
 	    forbid_setid("-x");
 	    opt->xflag = Qfalse;
 	    while (!NIL_P(line = rb_io_gets(f))) {
@@ -1532,37 +1533,8 @@
 		    return 0;
 
 		if ((p = strstr(RSTRING_PTR(line), "ruby")) == 0) {
-		    void rb_thread_stop_timer_thread(void);
-		    /* not ruby script, kick the program */
-		    char **argv;
-		    char *path;
-		    char *pend = RSTRING_PTR(line) + RSTRING_LEN(line);
-
-		    p = RSTRING_PTR(line);	/* skip `#!' */
-		    if (pend[-1] == '\n')
-			pend--;	/* chomp line */
-		    if (pend[-1] == '\r')
-			pend--;
-		    *pend = '\0';
-		    while (p < pend && ISSPACE(*p))
-			p++;
-		    path = p;	/* interpreter path */
-		    while (p < pend && !ISSPACE(*p))
-			p++;
-		    *p++ = '\0';
-		    if (p < pend) {
-			argv = ALLOCA_N(char *, origarg.argc + 3);
-			argv[1] = p;
-			MEMCPY(argv + 2, origarg.argv + 1, char *, origarg.argc);
-		    }
-		    else {
-			argv = origarg.argv;
-		    }
-		    argv[0] = path;
-		    rb_thread_stop_timer_thread();
-		    execv(path, argv);
-
-		    rb_fatal("Can't exec %s", path);
+		    /* not ruby script, assume -x flag */
+		    goto search_shebang;
 		}
 
 	      start_read:
Index: test/ruby/test_system.rb
===================================================================
--- test/ruby/test_system.rb	(revision 24409)
+++ test/ruby/test_system.rb	(revision 24410)
@@ -46,6 +46,18 @@
       assert_equal('555', `#{ruby} -x #{tmpfilename} -zzz=555`)
 
       tmp = open(tmpfilename, "w")
+      tmp.print "#! /non/exist\\interpreter?/./to|be:ignored\n";
+      tmp.print "this is a leading junk\n";
+      tmp.print "#! /usr/local/bin/ruby -s\n";
+      tmp.print "print $zzz\n";
+      tmp.print "__END__\n";
+      tmp.print "this is a trailing junk\n";
+      tmp.close
+
+      assert_equal('', `#{ruby} #{tmpfilename}`)
+      assert_equal('555', `#{ruby} #{tmpfilename} -zzz=555`)
+
+      tmp = open(tmpfilename, "w")
       for i in 1..5
         tmp.print i, "\n"
       end

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

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