[commit: packages/Win32] Mistuke-fix-build, depend-os-windows, fix-appveyor-curl-ussue, master, win32-2.5.4.1-ghc-8.2: Call SetLastError before maperrno (#60) (bf54fa7)

git at git.haskell.org git at git.haskell.org
Mon Apr 17 21:27:59 UTC 2017


Repository : ssh://git@git.haskell.org/Win32

On branches: Mistuke-fix-build,depend-os-windows,fix-appveyor-curl-ussue,master,win32-2.5.4.1-ghc-8.2
Link       : http://git.haskell.org/packages/Win32.git/commitdiff/bf54fa7134eb9b1366f827426f050d833b2cda54

>---------------------------------------------------------------

commit bf54fa7134eb9b1366f827426f050d833b2cda54
Author: Egor Tensin <Egor.Tensin at gmail.com>
Date:   Wed Nov 16 05:26:43 2016 +0300

    Call SetLastError before maperrno (#60)
    
    * Call SetLastError before maperrno
    
    * Use maperrno_func instead of the stateful maperrno
    
    * Added a changelog entry on `failWith`


>---------------------------------------------------------------

bf54fa7134eb9b1366f827426f050d833b2cda54
 System/Win32/Types.hs | 18 ++++++++++--------
 changelog.md          |  3 +++
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/System/Win32/Types.hs b/System/Win32/Types.hs
index 8340564..0ff7f34 100755
--- a/System/Win32/Types.hs
+++ b/System/Win32/Types.hs
@@ -26,10 +26,10 @@ import Data.Char (isSpace)
 import Data.Int (Int32, Int64)
 import Data.Maybe (fromMaybe)
 import Data.Word (Word8, Word16, Word32, Word64)
-import Foreign.C.Error (getErrno, errnoToIOError)
+import Foreign.C.Error (Errno(..), errnoToIOError)
 import Foreign.C.String (newCWString, withCWStringLen)
 import Foreign.C.String (peekCWString, peekCWStringLen, withCWString)
-import Foreign.C.Types (CChar, CUChar, CWchar, CIntPtr, CUIntPtr)
+import Foreign.C.Types (CChar, CUChar, CWchar, CInt(..), CIntPtr, CUIntPtr)
 import Foreign.ForeignPtr (ForeignPtr, newForeignPtr, newForeignPtr_)
 import Foreign.Ptr (FunPtr, Ptr, nullPtr)
 import Foreign (allocaArray)
@@ -242,18 +242,17 @@ failWith fn_name err_code = do
                    -- We ignore failure of freeing c_msg, given we're already failing
                    _ <- localFree c_msg
                    return msg
-  c_maperrno -- turn GetLastError() into errno, which errnoToIOError knows
-             -- how to convert to an IOException we can throw.
-             -- XXX we should really do this directly.
-  errno <- getErrno
+  -- turn GetLastError() into errno, which errnoToIOError knows how to convert
+  -- to an IOException we can throw.
+  errno <- c_maperrno_func err_code
   let msg' = reverse $ dropWhile isSpace $ reverse msg -- drop trailing \n
       ioerror = errnoToIOError fn_name errno Nothing Nothing
                   `ioeSetErrorString` msg'
   throwIO ioerror
 
 
-foreign import ccall unsafe "maperrno" -- in base/cbits/Win32Utils.c
-   c_maperrno :: IO ()
+foreign import ccall unsafe "maperrno_func" -- in base/cbits/Win32Utils.c
+   c_maperrno_func :: ErrCode -> IO Errno
 
 ----------------------------------------------------------------
 -- Misc helpers
@@ -295,6 +294,9 @@ foreign import WINDOWS_CCONV unsafe "windows.h LocalFree"
 foreign import WINDOWS_CCONV unsafe "windows.h GetLastError"
   getLastError :: IO ErrCode
 
+foreign import WINDOWS_CCONV unsafe "windows.h SetLastError"
+  setLastError :: ErrCode -> IO ()
+
 {-# CFILES cbits/errors.c #-}
 
 foreign import ccall unsafe "errors.h"
diff --git a/changelog.md b/changelog.md
index 6966ac6..d538387 100644
--- a/changelog.md
+++ b/changelog.md
@@ -2,6 +2,9 @@
 
 ## Unreleased GIT version
 
+* `failWith` (and the API calls that use it) now throw `IOError`s with proper
+  `IOErrorType`s.
+
 ## 2.4.0.0 *Nov 2016*
 
 * Add `windows_cconv.h` to the `install-includes` field of `Win32.cabal`,



More information about the ghc-commits mailing list