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

ruby-changes:26478

From: ko1 <ko1@a...>
Date: Fri, 21 Dec 2012 19:40:08 +0900 (JST)
Subject: [ruby-changes:26478] ko1:r38529 (trunk): * ruby.c (process_options): need to acquire env from TOPLEVEL_BINDING

ko1	2012-12-21 19:39:59 +0900 (Fri, 21 Dec 2012)

  New Revision: 38529

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

  Log:
    * ruby.c (process_options): need to acquire env from TOPLEVEL_BINDING
      each time.
      `bind->env' may update after `eval()'.
      [Bug #7536]

  Modified files:
    trunk/ChangeLog
    trunk/ruby.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38528)
+++ ChangeLog	(revision 38529)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Dec 21 19:37:15 2012  Koichi Sasada  <ko1@a...>
+
+	* ruby.c (process_options): need to acquire env from TOPLEVEL_BINDING
+	  each time.
+	  `bind->env' may update after `eval()'.
+	   [Bug #7536]
+
 Fri Dec 21 18:46:50 2012  Koichi Sasada  <ko1@a...>
 
 	* include/ruby/debug.h, vm_core.h: define rb_trace_arg_t at
Index: ruby.c
===================================================================
--- ruby.c	(revision 38528)
+++ ruby.c	(revision 38529)
@@ -559,10 +559,9 @@ require_libraries(VALUE *req_list) https://github.com/ruby/ruby/blob/trunk/ruby.c#L559
 }
 
 static rb_env_t*
-toplevel_context(void)
+toplevel_context(VALUE toplevel_binding)
 {
     rb_env_t *env;
-    VALUE toplevel_binding = rb_const_get(rb_cObject, rb_intern("TOPLEVEL_BINDING"));
     rb_binding_t *bind;
 
     GetBindingPtr(toplevel_binding, bind);
@@ -1308,7 +1307,7 @@ process_options(int argc, char **argv, s https://github.com/ruby/ruby/blob/trunk/ruby.c#L1307
     char fbuf[MAXPATHLEN];
     int i = (int)proc_options(argc, argv, opt, 0);
     rb_thread_t *th = GET_THREAD();
-    rb_env_t *env = 0;
+    VALUE toplevel_binding = Qundef;
 
     argc -= i;
     argv += i;
@@ -1438,9 +1437,10 @@ process_options(int argc, char **argv, s https://github.com/ruby/ruby/blob/trunk/ruby.c#L1437
     ruby_set_argv(argc, argv);
     process_sflag(&opt->sflag);
 
-    env = toplevel_context();
+    toplevel_binding = rb_const_get(rb_cObject, rb_intern("TOPLEVEL_BINDING"));
 
 #define PREPARE_PARSE_MAIN(expr) do { \
+    rb_env_t *env = toplevel_context(toplevel_binding); \
     th->parse_in_eval--; \
     th->base_block = &env->block; \
     expr; \
@@ -1533,8 +1533,9 @@ process_options(int argc, char **argv, s https://github.com/ruby/ruby/blob/trunk/ruby.c#L1533
 
     PREPARE_PARSE_MAIN({
 	VALUE path = Qnil;
-	if (!opt->e_script && strcmp(opt->script, "-"))
+	if (!opt->e_script && strcmp(opt->script, "-")) {
 	    path = rb_realpath_internal(Qnil, opt->script_name, 1);
+	}
 	iseq = rb_iseq_new_main(tree, opt->script_name, path);
     });
 

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

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