From: Joey Hess Date: Fri, 30 Dec 2016 22:14:19 +0000 (-0400) Subject: work around ghc segfault X-Git-Tag: archive/raspbian/10.20250416-2+rpi1~1^2~278^2~6 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=23d71423e19d9eb9f940b3011bbdabe0bf80aca6;p=git-annex.git work around ghc segfault hSetEncoding of a closed handle segfaults. https://ghc.haskell.org/trac/ghc/ticket/7161 8484c0c1976b2daa4be674b09f6f54c15c746aa6 introduced the crash. In particular, stdin may get closed (by eg, getContents) and then trying to set its encoding will crash. We didn't need to adjust stdin's encoding anyway, but only stderr, to work around https://github.com/yesodweb/persistent/issues/474 Thanks to Mesar Hameed for assistance related to reproducing this bug. --- diff --git a/Database/Handle.hs b/Database/Handle.hs index 9071cd5380..d84ce5b620 100644 --- a/Database/Handle.hs +++ b/Database/Handle.hs @@ -69,7 +69,7 @@ openDb db tablename = do worker <- async (workerThread (T.pack db) tablename jobs) -- work around https://github.com/yesodweb/persistent/issues/474 - liftIO useFileSystemEncoding + liftIO $ fileEncoding stderr return $ DbHandle worker jobs diff --git a/Utility/FileSystemEncoding.hs b/Utility/FileSystemEncoding.hs index be43ace95e..ae3bd35d7b 100644 --- a/Utility/FileSystemEncoding.hs +++ b/Utility/FileSystemEncoding.hs @@ -10,6 +10,7 @@ module Utility.FileSystemEncoding ( useFileSystemEncoding, + fileEncoding, withFilePath, md5FilePath, decodeBS, @@ -63,6 +64,13 @@ useFileSystemEncoding = do hSetEncoding stderr e Encoding.setLocaleEncoding e +fileEncoding :: Handle -> IO () +#ifndef mingw32_HOST_OS +fileEncoding h = hSetEncoding h =<< Encoding.getFileSystemEncoding +#else +fileEncoding h = hSetEncoding h Encoding.utf8 +#endif + {- Marshal a Haskell FilePath into a NUL terminated C string using temporary - storage. The FilePath is encoded using the filesystem encoding, - reversing the decoding that should have been done when the FilePath