When iconv is unavailable, use an ASCII encoding to encode ASCII
authorReid Barton <rwbarton@gmail.com>
Tue, 21 Jul 2015 17:13:20 +0000 (19:13 +0200)
committerBen Gamari <ben@smart-cactus.org>
Tue, 21 Jul 2015 19:42:54 +0000 (21:42 +0200)
commitdbe6dac96543f426297a59d8d16c3f5afacf42d4
treeece8ced882e19add696a4dfc99e298a93ad1a247
parent97a50d5096e134a1b713a085a7ba859bdd7143d1
When iconv is unavailable, use an ASCII encoding to encode ASCII

D898 and D1059 implemented a fallback behavior to handle the case
that the end user's iconv installation is broken (typically due to
running inside a chroot in which the necessary locale files and/or
gconv modules have not been installed). In this case, if the
program requests an ASCII locale, GHC's char8 encoding is used
rather than the program failing.

However, silently mangling data like char8 does when the programmer
did not ask for it is poor behavior, for reasons described in D1059.

This commit implements an ASCII encoding and uses it in the fallback
case when iconv is unavailable and the user has requested ASCII.

Test Plan:
Added tests for the encodings defined in Latin1.
Also, manually ran a statically-linked executable of that test
in a chroot and the tests passed (up to the ones that call
mkTextEncoding "LATIN1", since there is no fallback from iconv
for that case yet).

Reviewers: austin, hvr, hsyl20, bgamari

Reviewed By: hsyl20, bgamari

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D1085

GHC Trac Issues: #7695, #10623
libraries/base/GHC/IO/Encoding.hs
libraries/base/GHC/IO/Encoding/Latin1.hs
libraries/base/tests/.gitignore
libraries/base/tests/IO/all.T
libraries/base/tests/IO/encoding005.hs [new file with mode: 0644]
libraries/base/tests/IO/encoding005.stdout [new file with mode: 0644]