OTWO-1213 Works around lost encoding in Ruby/C binding layer
authorRobin Luckey <rluckey@blackducksoftware.com>
Mon, 9 Jan 2012 16:44:25 +0000 (08:44 -0800)
committerSathishkumar Natesan <sathish.n@imaginea.com>
Mon, 30 Sep 2013 06:15:05 +0000 (11:45 +0530)
commit9bd0540ccc7a1d920e9f7e75a38233e6b413a120
treed8f0af8cb60c6e102b435c82ce22b8d1a0c0c5a3
parentcd81878ffe11003f3f88a82c1c8e135fcbe651a4
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