Numerous fixes for StringIO in 1.9 mode.

Much of the logic here for 1.9 mode is now a nearly-direct port of
the MRI logic. This should bring us closer to supporting encoding
properly for the key StringIO operations like read and gets.