From: "H.Yamamoto" Date: 2004-09-13T16:54:06+09:00 Subject: Re: [PATCH] dir.c --- Dir.chdir error handling nobu.nokada@softhome.net wrote: (2004/09/13 00:40) >Seems fine, but this wouldn't be needed. > >> --- 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)); Umm, you mean this? 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 13 Sep 2004 01:25:39 -0000 @@ -5165,7 +5165,7 @@ rb_ensure(b_proc, data1, e_proc, data2) VALUE data2; { int state; - volatile VALUE result = Qnil; + volatile VALUE result = Qnil, dummy = data2; VALUE retval; PUSH_TAG(PROT_NONE); or 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 13 Sep 2004 01:29:38 -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; Probably former because there is difference in type of arguments between prototype and implementation. (Maybe this is allowed in C, but I could not find document to confirm. At least C++ fails.) /////////////////////////////////////////////////////////////////////////// But I'm still uncomfortable about volatile. ruby is large, I think we cannot guarantee all VALUEs are guarded from compiler optimization. I think the safest way is to store object into volatile variable just after construction. volatile VALUE v = rb_str_new2("foo"); foo(v); /* don't have to think about GC */ but on this policy, we can't do this foo(rb_str_new2("foo")); .... totally.