[commit: packages/Win32] master: Fix i386/windows build. (3da00d8)

git at git.haskell.org git at git.haskell.org
Tue Aug 20 06:50:28 CEST 2013


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

On branch  : master
Link       : http://git.haskell.org/?p=packages/Win32.git;a=commit;h=3da00d80f2fd7d1032e3530e1af1b39fba79aac3

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

commit 3da00d80f2fd7d1032e3530e1af1b39fba79aac3
Author: Austin Seipp <aseipp at pobox.com>
Date:   Mon Aug 19 23:16:18 2013 -0500

    Fix i386/windows build.
    
    With the new -XNegativeLiterals, the compiler was (rightly) complaining
    that values like (0x80000000 :: Int32) suffer from signed overflow. This
    caused the Windows GHC build to fail, since it uses -Werror.
    
    The fix is very simple. For details, see Note [Overflow checking and
    fromIntegral] in Graphics/Win32/GDI/HDC.hs
    
    Signed-off-by: Austin Seipp <aseipp at pobox.com>


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

3da00d80f2fd7d1032e3530e1af1b39fba79aac3
 Graphics/Win32/GDI/HDC.hs |   21 ++++++++++++++++++---
 Graphics/Win32/Window.hsc |    4 +++-
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/Graphics/Win32/GDI/HDC.hs b/Graphics/Win32/GDI/HDC.hs
index 51da1db..e99b505 100644
--- a/Graphics/Win32/GDI/HDC.hs
+++ b/Graphics/Win32/GDI/HDC.hs
@@ -26,7 +26,20 @@ import Foreign
 
 #include "windows_cconv.h"
 
-----------------------------------------------------------------
+{- Note [Overflow checking and fromIntegral]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Some windows APIs use the value 0x80000000 to represent failure return
+codes. However, when GHC builds libraries with -XNegativeLiterals
+enabled, it will fail in contexts where the type would suffer from
+signed overflow - such as Int32. (minBound :: Int32 == 0x80000000)
+
+Technically, the frontend is correct that the literal overflows in the
+context it is used in. So instead, we use fromIntegral to convert the
+literal from a Word32 to the necessary type. This isn't any less
+efficient (fromIntegral is optimized away,) and conveys the idea we
+simply want the same representational value.
+-}
 
 setArcDirection :: HDC -> ArcDirection -> IO ArcDirection
 setArcDirection dc dir =
@@ -142,14 +155,16 @@ foreign import WINDOWS_CCONV unsafe "windows.h GetTextAlign"
 
 setTextCharacterExtra :: HDC -> Int -> IO Int
 setTextCharacterExtra dc extra =
-  failIf (== 0x80000000) "SetTextCharacterExtra" $
+  -- See Note [Overflow checking and fromIntegral]
+  failIf (== fromIntegral (0x80000000 :: Word32)) "SetTextCharacterExtra" $
     c_SetTextCharacterExtra dc extra
 foreign import WINDOWS_CCONV unsafe "windows.h SetTextCharacterExtra"
   c_SetTextCharacterExtra :: HDC ->  Int  -> IO  Int
 
 getTextCharacterExtra :: HDC -> IO Int
 getTextCharacterExtra dc =
-  failIf (== 0x80000000) "GetTextCharacterExtra" $ c_GetTextCharacterExtra dc
+  -- See Note [Overflow checking and fromIntegral]
+  failIf (== fromIntegral (0x80000000 :: Word32)) "GetTextCharacterExtra" $ c_GetTextCharacterExtra dc
 foreign import WINDOWS_CCONV unsafe "windows.h GetTextCharacterExtra"
   c_GetTextCharacterExtra :: HDC -> IO  Int
 
diff --git a/Graphics/Win32/Window.hsc b/Graphics/Win32/Window.hsc
index 6e8f765..791549a 100644
--- a/Graphics/Win32/Window.hsc
+++ b/Graphics/Win32/Window.hsc
@@ -171,8 +171,10 @@ type WindowStyleEx   = DWORD
  , wS_EX_PALETTEWINDOW  = WS_EX_PALETTEWINDOW
  }
 
+
 cW_USEDEFAULT :: Pos
-cW_USEDEFAULT = #{const CW_USEDEFAULT}
+-- See Note [Overflow checking and fromIntegral] in Graphics/Win32/GDI/HDC.hs
+cW_USEDEFAULT = fromIntegral (#{const CW_USEDEFAULT} :: Word32)
 
 type Pos = Int
 





More information about the ghc-commits mailing list