OTWO-1213 Works around lost encoding in Ruby/C binding layer origin/ruby192
authorRobin Luckey <rluckey@blackducksoftware.com>
Mon, 9 Jan 2012 16:44:25 +0000 (08:44 -0800)
committerRobin Luckey <rluckey@blackducksoftware.com>
Mon, 9 Jan 2012 16:44:25 +0000 (08:44 -0800)
commit9d77d7bd9cce62f6749bb8b2bb7696fcb68f8135
treeedd31baf6b5e7da0138ed62dc92ba085ea11d9b3
parent9bf832775e35ac4e25a21a5f56c3acf9efb3e5c8
OTWO-1213 Works around lost encoding in Ruby/C binding layer

When a Ruby 1.9.2 string is passed to the C code, the associated
encoding metadata is lost. When this same string is then returned from C
back to Ruby, an arbitrary, mismatched encoding is applied to replace
the lost one.

This means that a string becomes garbled in the round trip. The bits
don't change, but the encoding is lost.

The correct fix would be to preserve the encoding metadata in the C
layer.

The easier fix is to replace the lost encoding with a more likely match,
which is what I've done in this patch. When the C code returns a string,
we apply the Ruby runtime's current default encoding, which is highly likely to
be the encoding originally discarded.
ruby/ohcount.rb