From: Yukihiro Matsumoto Date: 2004-09-14T17:26:28+09:00 Subject: Re: [PATCH] dir.c --- Dir.chdir error handling Hi, In message "Re: [PATCH] dir.c --- Dir.chdir error handling" on Tue, 14 Sep 2004 16:08:23 +0900, H.Yamamoto writes: |ruby's GC uses stack and register as root, and trace reference from root and marks them. |Finally, frees unmarked object. The problem is, sometimes compiler removes VALUE |>from stack and register despite it's still in scope. |If all refrences are removed like that, corresponding object are freed wrongly. right? Right. |> In your example, you constantly work with an object `v' and not the content |> of the object, like RARRAY(v)->ptr. This mean that this object `v' will be |> in a register or in the stack (ruby need it) and it will marked by the GC | |But, there is possibility of inline expansion. If rb_fooboo and func2 and func3 |are simpile enough, they can be all expanded to somefunc() like this. Your example is exactly the case I stated in [ruby-talk:03385], and I believe the somefunc should protect VALUE using volatile. |And if s is optimized out. all references to ruby string "foo" disappers, |and GC may destroy the object. If s is volatile, there is not any chance |to erase all references because one of them is volatile. (Am I wrong?) Right. |And if we have to keep only one refernce to stack or register, is there better |place to do it than after object creation? I'm not sure what you meant. Where's "there"? |Anyway, I was told gcc -O3 or more shouldn't be used |because too much optimization will break GC. Doesn't that mean protection is not enough? I don't know. Maybe -O3 optimized out VALUEs forgotten to be protected. matz.