unprotected use of global variables in base:GHC.IO.Encoding

Nicolas Frisby nicolas.frisby at gmail.com
Sun Feb 17 17:41:08 CET 2013


I've noticed some suspicious code in base:GHC.IO.Encoding.


setLocaleEncoding, setFileSystemEncoding, setForeignEncoding ::
TextEncoding -> IO ()

(getLocaleEncoding, setLocaleEncoding)         = mkGlobal initLocaleEncoding

(getFileSystemEncoding, setFileSystemEncoding) = mkGlobal
initFileSystemEncoding

(getForeignEncoding, setForeignEncoding)       = mkGlobal
initForeignEncoding



mkGlobal :: a -> (IO a, a -> IO ())
mkGlobal x = unsafePerformIO $ do
    x_ref <- newIORef x
    return (readIORef x_ref, writeIORef x_ref)



I've not elided any pragmas and there's no relevant LANGUAGE or OPTIONS
pragmas.

With HEAD from a couple weeks ago, mkGlobal is not getting inlined. But
with some of my experimental alterations of sizeExpr, it is getting inlined.

So this code should probably have some of the guards for faking global
variables, right?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/ghc-devs/attachments/20130217/1eef0986/attachment.htm>


More information about the ghc-devs mailing list