Skip to content

Commit 2a56e45

Browse files
authored
Fix wrong alignments (#68)
* Win32: Correct alignments * Win32: alignment * Win32: fix alignments.
1 parent 399d21a commit 2a56e45

File tree

13 files changed

+31
-16
lines changed

13 files changed

+31
-16
lines changed

Graphics/Win32/GDI/AlphaBlend.hsc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import Graphics.Win32.GDI.Types ( HDC )
1717
import System.Win32.Types ( BOOL, BYTE, UINT )
1818

1919
#include <windows.h>
20+
#include "alignment.h"
2021
##include "windows_cconv.h"
2122

2223
foreign import ccall unsafe "alphablend.h"
@@ -57,7 +58,7 @@ data BLENDFUNCTION = BLENDFUNCTION
5758

5859
instance Storable BLENDFUNCTION where
5960
sizeOf = const #size BLENDFUNCTION
60-
alignment = sizeOf
61+
alignment _ = #alignment BLENDFUNCTION
6162
poke buf func = do
6263
(#poke BLENDFUNCTION, BlendOp) buf (blendOp func)
6364
(#poke BLENDFUNCTION, BlendFlags) buf (blendFlags func)

System/Win32/Automation/Input.hsc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import System.Win32.Types ( UINT, LPARAM, failIfZero )
3030
import System.Win32.Word ( DWORD, WORD )
3131

3232
#include <windows.h>
33+
#include "alignment.h"
3334
##include "windows_cconv.h"
3435
#include "winuser_compat.h"
3536

@@ -71,7 +72,7 @@ data INPUT = Mouse MOUSEINPUT | Keyboard KEYBDINPUT | OtherHardware HARDWAREINPU
7172

7273
instance Storable INPUT where
7374
sizeOf = const #{size INPUT}
74-
alignment = sizeOf
75+
alignment _ = #alignment INPUT
7576

7677
poke buf (Mouse mouse) = do
7778
(#poke INPUT, type) buf (#{const INPUT_MOUSE}:: DWORD)
@@ -103,7 +104,7 @@ data HARDWAREINPUT = HARDWAREINPUT
103104

104105
instance Storable HARDWAREINPUT where
105106
sizeOf = const #{size HARDWAREINPUT}
106-
alignment = sizeOf
107+
alignment _ = #alignment HARDWAREINPUT
107108
poke buf input = do
108109
(#poke HARDWAREINPUT, uMsg) buf (uMsg input)
109110
(#poke HARDWAREINPUT, wParamL) buf (wParamL input)

System/Win32/Automation/Input/Key.hsc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import System.Win32.Word ( DWORD, WORD )
1818

1919
#include <windows.h>
2020
#include "winuser_compat.h"
21+
#include "alignment.h"
2122

2223
type PKEYBDINPUT = Ptr KEYBDINPUT
2324

@@ -31,7 +32,7 @@ data KEYBDINPUT = KEYBDINPUT
3132

3233
instance Storable KEYBDINPUT where
3334
sizeOf = const #{size KEYBDINPUT}
34-
alignment = sizeOf
35+
alignment _ = #alignment KEYBDINPUT
3536
poke buf input = do
3637
(#poke KEYBDINPUT, wVk) buf (wVk input)
3738
(#poke KEYBDINPUT, wScan) buf (wScan input)

System/Win32/Automation/Input/Mouse.hsc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import System.Win32.Word ( DWORD )
1818

1919
#include <windows.h>
2020
#include "winuser_compat.h"
21+
#include "alignment.h"
2122

2223
type PMOUSEINPUT = Ptr MOUSEINPUT
2324

@@ -32,7 +33,7 @@ data MOUSEINPUT = MOUSEINPUT
3233

3334
instance Storable MOUSEINPUT where
3435
sizeOf = const #{size MOUSEINPUT}
35-
alignment = sizeOf
36+
alignment _ = #alignment MOUSEINPUT
3637
poke buf input = do
3738
(#poke MOUSEINPUT, dx) buf (dx input)
3839
(#poke MOUSEINPUT, dx) buf (dx input)

System/Win32/File.hsc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import Control.Concurrent
3636
##include "windows_cconv.h"
3737

3838
#include <windows.h>
39+
#include "alignment.h"
3940

4041
----------------------------------------------------------------
4142
-- Enumeration types
@@ -254,7 +255,7 @@ data BY_HANDLE_FILE_INFORMATION = BY_HANDLE_FILE_INFORMATION
254255

255256
instance Storable BY_HANDLE_FILE_INFORMATION where
256257
sizeOf = const (#size BY_HANDLE_FILE_INFORMATION)
257-
alignment = sizeOf
258+
alignment _ = #alignment BY_HANDLE_FILE_INFORMATION
258259
poke buf bhi = do
259260
(#poke BY_HANDLE_FILE_INFORMATION, dwFileAttributes) buf (bhfiFileAttributes bhi)
260261
(#poke BY_HANDLE_FILE_INFORMATION, ftCreationTime) buf (bhfiCreationTime bhi)
@@ -294,7 +295,7 @@ data WIN32_FILE_ATTRIBUTE_DATA = WIN32_FILE_ATTRIBUTE_DATA
294295

295296
instance Storable WIN32_FILE_ATTRIBUTE_DATA where
296297
sizeOf = const (#size WIN32_FILE_ATTRIBUTE_DATA)
297-
alignment = sizeOf
298+
alignment _ = #alignment WIN32_FILE_ATTRIBUTE_DATA
298299
poke buf ad = do
299300
(#poke WIN32_FILE_ATTRIBUTE_DATA, dwFileAttributes) buf (fadFileAttributes ad)
300301
(#poke WIN32_FILE_ATTRIBUTE_DATA, ftCreationTime) buf (fadCreationTime ad)

System/Win32/Info.hsc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import Prelude hiding (catch)
3636
##include "windows_cconv.h"
3737

3838
#include <windows.h>
39+
#include "alignment.h"
3940

4041
----------------------------------------------------------------
4142
-- Environment Strings
@@ -218,7 +219,7 @@ data SYSTEM_INFO = SYSTEM_INFO
218219

219220
instance Storable SYSTEM_INFO where
220221
sizeOf = const #size SYSTEM_INFO
221-
alignment = sizeOf
222+
alignment _ = #alignment SYSTEM_INFO
222223
poke buf si = do
223224
(#poke SYSTEM_INFO, wProcessorArchitecture) buf (siProcessorArchitecture si)
224225
(#poke SYSTEM_INFO, dwPageSize) buf (siPageSize si)

System/Win32/Info/Computer.hsc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import System.Win32.Word ( DWORD, LPDWORD )
6666

6767
#include <windows.h>
6868
#include <Lmcons.h>
69+
#include "alignment.h"
6970
##include "windows_cconv.h"
7071

7172
----------------------------------------------------------------
@@ -137,7 +138,7 @@ data HW_PROFILE_INFO = HW_PROFILE_INFO
137138
138139
instance Storable HW_PROFILE_INFO where
139140
sizeOf = const #{size HW_PROFILE_INFOW}
140-
alignment = sizeOf
141+
alignment _ = #alignment HW_PROFILE_INFOW
141142
poke buf info = do
142143
(#poke HW_PROFILE_INFOW, dwDockInfo) buf (dwDockInfo info)
143144
withTString (szHwProfileGuid info) $ \szHwProfileGuid' ->

System/Win32/Info/Version.hsc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import System.Win32.Types ( BOOL, BYTE, failIfFalse_ )
2727
import System.Win32.Word ( WORD, DWORD )
2828

2929
#include <windows.h>
30+
#include "alignment.h"
3031
##include "windows_cconv.h"
3132

3233
----------------------------------------------------------------
@@ -77,7 +78,7 @@ data OSVERSIONINFOEX = OSVERSIONINFOEX
7778

7879
instance Storable OSVERSIONINFOEX where
7980
sizeOf = const #{size struct _OSVERSIONINFOEXW}
80-
alignment = sizeOf
81+
alignment _ = #alignment OSVERSIONINFOEX
8182
poke buf info = do
8283
(#poke OSVERSIONINFOEXW, dwOSVersionInfoSize) buf (sizeOf info)
8384
(#poke OSVERSIONINFOEXW, dwMajorVersion) buf (dwMajorVersion info)

System/Win32/Mem.hsc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import Foreign.C.Types
2727
##include "windows_cconv.h"
2828

2929
#include <windows.h>
30+
#include "alignment.h"
3031

3132
----------------------------------------------------------------
3233
-- Data types
@@ -48,7 +49,7 @@ data MEMORY_BASIC_INFORMATION = MEMORY_BASIC_INFORMATION
4849

4950
instance Storable MEMORY_BASIC_INFORMATION where
5051
sizeOf _ = #size MEMORY_BASIC_INFORMATION
51-
alignment = sizeOf
52+
alignment _ = #alignment MEMORY_BASIC_INFORMATION
5253
poke buf mbi = do
5354
(#poke MEMORY_BASIC_INFORMATION, BaseAddress) buf (mbiBaseAddress mbi)
5455
(#poke MEMORY_BASIC_INFORMATION, AllocationBase) buf (mbiAllocationBase mbi)

System/Win32/Time.hsc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ import Foreign.C ( CInt(..), CWchar(..)
3232
, peekCWString, withCWStringLen, withCWString )
3333

3434
##include "windows_cconv.h"
35-
#include "windows.h"
35+
#include <windows.h>
36+
#include "alignment.h"
3637

3738
----------------------------------------------------------------
3839
-- data types
@@ -63,7 +64,7 @@ data TimeZoneId = TzIdUnknown | TzIdStandard | TzIdDaylight
6364

6465
instance Storable FILETIME where
6566
sizeOf = const (#size FILETIME)
66-
alignment = sizeOf
67+
alignment _ = #alignment FILETIME
6768
poke buf (FILETIME n) = do
6869
(#poke FILETIME, dwLowDateTime) buf low
6970
(#poke FILETIME, dwHighDateTime) buf hi
@@ -75,7 +76,7 @@ instance Storable FILETIME where
7576

7677
instance Storable SYSTEMTIME where
7778
sizeOf _ = #size SYSTEMTIME
78-
alignment = sizeOf
79+
alignment _ = #alignment SYSTEMTIME
7980
poke buf st = do
8081
(#poke SYSTEMTIME, wYear) buf (wYear st)
8182
(#poke SYSTEMTIME, wMonth) buf (wMonth st)
@@ -98,7 +99,7 @@ instance Storable SYSTEMTIME where
9899

99100
instance Storable TIME_ZONE_INFORMATION where
100101
sizeOf _ = (#size TIME_ZONE_INFORMATION)
101-
alignment = sizeOf
102+
alignment _ = #alignment TIME_ZONE_INFORMATION
102103
poke buf tzi = do
103104
(#poke TIME_ZONE_INFORMATION, Bias) buf (tziBias tzi)
104105
(#poke TIME_ZONE_INFORMATION, StandardDate) buf (tziStandardDate tzi)

Win32.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ Library
9797
"user32", "gdi32", "winmm", "advapi32", "shell32", "shfolder", "shlwapi", "msimg32", "imm32", "ntdll"
9898
ghc-options: -Wall
9999
include-dirs: include
100-
includes: "alphablend.h", "diatemp.h", "dumpBMP.h", "ellipse.h", "errors.h", "HsGDI.h", "HsWin32.h", "Win32Aux.h", "win32debug.h", "windows_cconv.h", "WndProc.h"
100+
includes: "alphablend.h", "diatemp.h", "dumpBMP.h", "ellipse.h", "errors.h", "HsGDI.h", "HsWin32.h", "Win32Aux.h", "win32debug.h", "windows_cconv.h", "WndProc.h", "alignment.h"
101101
install-includes: "HsWin32.h", "HsGDI.h", "WndProc.h", "windows_cconv.h", "alphablend.h", "winternl_compat.h", "winuser_compat.h"
102102
c-sources:
103103
cbits/HsGDI.c

changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
number is returned. This simulates the behavior of the `NT_SUCCESS` macro.
1414
* Merged package Win32-extras (See #16)
1515
* `Graphics.Win32.Misc.messageBox` safely imported now https://github.com/haskell/win32/pull/5
16+
* Fixed various alignment calls that were incorrect. These would result in an incorrect alignment
17+
being returned on certain platforms. (See #66)
1618

1719
## 2.4.0.0 *Nov 2016*
1820

include/alignment.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#if __GLASGOW_HASKELL__ < 711
2+
#define hsc_alignment(t ) hsc_printf ( "%lu", (unsigned long)offsetof(struct {char x__; t(y__); }, y__));
3+
#endif

0 commit comments

Comments
 (0)