From: "H.Yamamoto" Date: 2004-09-11T14:13:41+09:00 Subject: Re: [PATCH] dir.c --- Dir.chdir error handling nobu.nokada@softhome.net wrote: (2004/09/11 00:01) >This isn't concerned with this issue? It never fail, and uses >no VALUE's. Sorry, so many functions are in ruby.h so I just picked up the functions around rb_ensure() without checking. Is this patch enouch? Index: dir.c =================================================================== RCS file: /var/cvs/src/ruby/dir.c,v retrieving revision 1.125 diff -u -w -b -p -r1.125 dir.c --- dir.c 19 Aug 2004 07:33:15 -0000 1.125 +++ dir.c 11 Sep 2004 04:43:22 -0000 @@ -678,10 +678,10 @@ dir_close(dir) static void dir_chdir(path) - const char *path; + volatile VALUE path; { - if (chdir(path) < 0) - rb_sys_fail(path); + if (chdir(RSTRING(path)->ptr) < 0) + rb_sys_fail(RSTRING(path)->ptr); } static int chdir_blocking = 0; @@ -689,13 +689,12 @@ static VALUE chdir_thread = Qnil; static VALUE chdir_restore(path) - char *path; + VALUE path; { chdir_blocking--; if (chdir_blocking == 0) chdir_thread = Qnil; dir_chdir(path); - free(path); return Qnil; } @@ -744,20 +743,19 @@ dir_s_chdir(argc, argv, obj) VALUE *argv; VALUE obj; { - VALUE path = Qnil; - char *dist = ""; + VALUE path; rb_secure(2); if (rb_scan_args(argc, argv, "01", &path) == 1) { FilePathValue(path); - dist = RSTRING(path)->ptr; } else { - dist = getenv("HOME"); + char *dist = getenv("HOME"); if (!dist) { dist = getenv("LOGDIR"); if (!dist) rb_raise(rb_eArgError, "HOME/LOGDIR not set"); } + path = rb_str_new2(dist); } if (chdir_blocking > 0) { @@ -766,14 +764,17 @@ dir_s_chdir(argc, argv, obj) } if (rb_block_given_p()) { - char *cwd = my_getcwd(); + char *tmp = my_getcwd(); + VALUE cwd = rb_str_new2(tmp); + free(tmp); + + dir_chdir(path); chdir_blocking++; if (chdir_thread == Qnil) chdir_thread = rb_thread_current(); - dir_chdir(dist); - return rb_ensure(rb_yield, path, chdir_restore, (VALUE)cwd); + return rb_ensure(rb_yield, path, chdir_restore, cwd); } - dir_chdir(dist); + dir_chdir(path); return INT2FIX(0); } Index: eval.c =================================================================== RCS file: /var/cvs/src/ruby/eval.c,v retrieving revision 1.695 diff -u -w -b -p -r1.695 eval.c --- eval.c 6 Sep 2004 00:48:03 -0000 1.695 +++ eval.c 11 Sep 2004 04:40:31 -0000 @@ -5162,7 +5162,7 @@ rb_ensure(b_proc, data1, e_proc, data2) VALUE (*b_proc)(); VALUE data1; VALUE (*e_proc)(); - VALUE data2; + volatile VALUE data2; { int state; volatile VALUE result = Qnil; Index: ruby.h =================================================================== RCS file: /var/cvs/src/ruby/ruby.h,v retrieving revision 1.105 diff -u -w -b -p -r1.105 ruby.h --- ruby.h 7 Apr 2004 06:30:14 -0000 1.105 +++ ruby.h 11 Sep 2004 03:58:12 -0000 @@ -548,7 +548,7 @@ int rb_block_given_p _((void)); VALUE rb_iterate _((VALUE(*)(VALUE),VALUE,VALUE(*)(ANYARGS),VALUE)); VALUE rb_rescue _((VALUE(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),VALUE)); VALUE rb_rescue2 __((VALUE(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),VALUE,...)); -VALUE rb_ensure _((VALUE(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),VALUE)); +VALUE rb_ensure _((VALUE(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),volatile VALUE)); VALUE rb_catch _((const char*,VALUE(*)(ANYARGS),VALUE)); NORETURN(void rb_throw _((const char*,VALUE)));