[Ruby-debug-commits] [881] trunk: Trying to fix "if $0 == __FILE__" ruby's idiom.

nobody at rubyforge.org nobody at rubyforge.org
Sun Nov 9 21:56:13 EST 2008


Revision: 881
Author:   kent
Date:     2008-11-09 21:56:13 -0500 (Sun, 09 Nov 2008)

Log Message:
-----------
Trying to fix "if $0 == __FILE__" ruby's idiom. Apparently setting $0 to
a new value doesn't work correctly. (Ruby's bug?)

$ cat t3.rb 
p $0
p File.expand_path $0
$0 = File.expand_path $0
p $0
$ ruby t3.rb 
"t3.rb"
"/Users/kent/Work/ruby-debug/trunk/t3.rb"
"/Users/ke"

Modified Paths:
--------------
    trunk/bin/rdebug
    trunk/ext/ruby_debug.c

Modified: trunk/bin/rdebug
===================================================================
--- trunk/bin/rdebug	2008-11-10 01:50:00 UTC (rev 880)
+++ trunk/bin/rdebug	2008-11-10 02:56:13 UTC (rev 881)
@@ -16,35 +16,7 @@
     exit $?.exitstatus 
   end
   print "\032\032starting\n" if Debugger.annotate and Debugger.annotate > 2
-  unless options.no_rewrite_program
-    # Set $0 so things like __FILE == $0 work.
-    # A more reliable way to do this is to put $0 = __FILE__ *after*
-    # loading the script to be debugged.  For this, adding a debug hook
-    # for the first time and then switching to the debug hook that's
-    # normally used would be helpful. Doing this would also help other
-    # first-time initializations such as reloading debugger state
-    # after a restart. 
 
-    # However This is just a little more than I want to take on right
-    # now, so I think I'll stick with the slightly hacky approach.
-    $RDEBUG_0 = $0
-
-    # cygwin does some sort of funky truncation on $0 ./abcdef => ./ab
-    # probably something to do with 3-letter extension truncation.
-    # The hacky workaround is to do slice assignment. Ugh.
-    d0 = if '.' == File.dirname(Debugger::PROG_SCRIPT) and
-             Debugger::PROG_SCRIPT[0..0] != '.'
-           File.join('.', Debugger::PROG_SCRIPT)
-         else
-           Debugger::PROG_SCRIPT
-         end
-    if $0.frozen?
-      $0 = d0
-    else
-      $0[0..-1] = d0
-    end
-  end
-
   # Record where we are we can know if the call stack has been
   # truncated or not.
   Debugger.start_sentinal=caller(0)[1]
@@ -272,7 +244,7 @@
   # save script name
   prog_script = ARGV.shift
   prog_script = whence_file(prog_script) unless File.exist?(prog_script)
-  Debugger::PROG_SCRIPT = prog_script
+  Debugger::PROG_SCRIPT = File.expand_path prog_script
   
   # install interruption handler
   trap('INT') { Debugger.interrupt_last }

Modified: trunk/ext/ruby_debug.c
===================================================================
--- trunk/ext/ruby_debug.c	2008-11-10 01:50:00 UTC (rev 880)
+++ trunk/ext/ruby_debug.c	2008-11-10 02:56:13 UTC (rev 881)
@@ -1388,6 +1388,8 @@
     debug_context->stack_size = 0;
     if(RTEST(stop))
       debug_context->stop_next = 1;
+    /* Initializing $0 to the script's path */
+    ruby_script(RSTRING(file)->ptr);
     rb_load_protect(file, 0, &state);
     if (0 != state) {
       VALUE errinfo = ruby_errinfo;




More information about the Ruby-debug-commits mailing list