This fixes the bug which I reported yesterday at: http://bugs.ruby-lang.org/issues/7135
I was having a problem with incorrect values yielded by String#codepoints, because the frozen string copy which it uses internally was being freed by the GC. I noticed that very similar code is used in String#lines and String#chars, so I added RB_GC_GUARD to those also to make sure that similar problems do not happen to anyone when using those methods.
Use RB_GC_GUARD to prevent GC from freeing String copies used by iter…
Sorry, one more thing: this bug occurs on both Ruby 1.9.2 and 1.9.3. I have confirmed that this patch can be applied cleanly to both v1_9_2_381 and v1_9_3_195. I recommend that you cherry-pick it onto both the 1.9.2 and 1.9.3 maintenance branches (so it will be included in future bugfix releases).
RB_GC_GUARD() before RSTRING_PTR/LEN can be optimized out also.
OK... let me try again.