summaryrefslogtreecommitdiff
path: root/libraries/base/System
diff options
context:
space:
mode:
authorAndreas Klebinger <klebinger.andreas@gmx.at>2017-02-23 13:46:15 -0500
committerBen Gamari <ben@smart-cactus.org>2017-02-23 17:26:44 -0500
commit6ca6a360c2b71d7e0c77a819dc463b37efe7a39d (patch)
treeb8c5856ce8332b5ddca75f1817dcad7395f0784a /libraries/base/System
parent7d116e553f0b44723e279ae5affa744e6aefc3c0 (diff)
downloadhaskell-6ca6a360c2b71d7e0c77a819dc463b37efe7a39d.tar.gz
base: Add handling of -- to getArgs for Windows
getArgs didn't match the treatmeant of -- in the RTS leading to inconsistencies between behavior on Windows and other platforms. See #13287. Reviewers: austin, hvr, bgamari, erikd, simonmar, rwbarton Reviewed By: bgamari, rwbarton Subscribers: rwbarton, thomie Differential Revision: https://phabricator.haskell.org/D3147
Diffstat (limited to 'libraries/base/System')
-rw-r--r--libraries/base/System/Environment.hs16
1 files changed, 15 insertions, 1 deletions
diff --git a/libraries/base/System/Environment.hs b/libraries/base/System/Environment.hs
index d8b3e03be5..61b728cb9c 100644
--- a/libraries/base/System/Environment.hs
+++ b/libraries/base/System/Environment.hs
@@ -67,12 +67,24 @@ import System.Environment.ExecutablePath
#ifdef mingw32_HOST_OS
--- Ignore the arguments to hs_init on Windows for the sake of Unicode compat
+{-
+Note [Ignore hs_init argv]
+~~~~~~~~~~~~~~~~~~~~~~~~~~
+Ignore the arguments to hs_init on Windows for the sake of Unicode compat
+
+Instead on Windows we get the list of arguments from getCommandLineW and
+filter out arguments which the RTS would not have passed along.
+
+This is done to ensure we get the arguments in proper Unicode Encoding which
+the RTS at this moment does not seem provide. The filtering has to match the
+one done by the RTS to avoid inconsistencies like #13287.
+-}
getWin32ProgArgv_certainly :: IO [String]
getWin32ProgArgv_certainly = do
mb_argv <- getWin32ProgArgv
case mb_argv of
+ -- see Note [Ignore hs_init argv]
Nothing -> fmap dropRTSArgs getFullArgs
Just argv -> return argv
@@ -106,8 +118,10 @@ foreign import ccall unsafe "getWin32ProgArgv"
foreign import ccall unsafe "setWin32ProgArgv"
c_setWin32ProgArgv :: CInt -> Ptr CWString -> IO ()
+-- See Note [Ignore hs_init argv]
dropRTSArgs :: [String] -> [String]
dropRTSArgs [] = []
+dropRTSArgs rest@("--":_) = rest
dropRTSArgs ("+RTS":rest) = dropRTSArgs (dropWhile (/= "-RTS") rest)
dropRTSArgs ("--RTS":rest) = rest
dropRTSArgs ("-RTS":rest) = dropRTSArgs rest