Skip to content

Commit 4af1a67

Browse files
committed
lazy evaluation for Storable instances
1 parent 948cf7b commit 4af1a67

File tree

12 files changed

+34
-34
lines changed

12 files changed

+34
-34
lines changed

Network/Socket/Info.hsc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ data AddrInfo = AddrInfo {
108108
} deriving (Eq, Show)
109109

110110
instance Storable AddrInfo where
111-
sizeOf _ = #const sizeof(struct addrinfo)
112-
alignment _ = alignment (0 :: CInt)
111+
sizeOf ~_ = #const sizeof(struct addrinfo)
112+
alignment ~_ = alignment (0 :: CInt)
113113

114114
peek p = do
115115
ai_flags <- (#peek struct addrinfo, ai_flags) p

Network/Socket/Options.hsc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,8 @@ data StructLinger = StructLinger {
466466
deriving (Eq, Ord, Show)
467467

468468
instance Storable StructLinger where
469-
sizeOf _ = (#const sizeof(struct linger))
470-
alignment _ = alignment (0 :: CInt)
469+
sizeOf ~_ = (#const sizeof(struct linger))
470+
alignment ~_ = alignment (0 :: CInt)
471471

472472
peek p = do
473473
onoff <- (#peek struct linger, l_onoff) p

Network/Socket/Posix/Cmsg.hsc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ instance ControlMessage IPv4PktInfo where
177177

178178
instance Storable IPv4PktInfo where
179179
#if defined (IP_PKTINFO)
180-
sizeOf _ = (#size struct in_pktinfo)
181-
alignment _ = alignment (0 :: CInt)
180+
sizeOf ~_ = (#size struct in_pktinfo)
181+
alignment ~_ = alignment (0 :: CInt)
182182
poke p (IPv4PktInfo n sa ha) = do
183183
(#poke struct in_pktinfo, ipi_ifindex) p (fromIntegral n :: CInt)
184184
(#poke struct in_pktinfo, ipi_spec_dst) p sa
@@ -189,8 +189,8 @@ instance Storable IPv4PktInfo where
189189
ha <- (#peek struct in_pktinfo, ipi_addr) p
190190
return $ IPv4PktInfo n sa ha
191191
#else
192-
sizeOf _ = 0
193-
alignment _ = 1
192+
sizeOf ~_ = 0
193+
alignment ~_ = 1
194194
poke _ _ = error "Unsupported control message type"
195195
peek _ = error "Unsupported control message type"
196196
#endif
@@ -208,8 +208,8 @@ instance ControlMessage IPv6PktInfo where
208208

209209
instance Storable IPv6PktInfo where
210210
#if defined (IPV6_PKTINFO)
211-
sizeOf _ = (#size struct in6_pktinfo)
212-
alignment _ = alignment (0 :: CInt)
211+
sizeOf ~_ = (#size struct in6_pktinfo)
212+
alignment ~_ = alignment (0 :: CInt)
213213
poke p (IPv6PktInfo n ha6) = do
214214
(#poke struct in6_pktinfo, ipi6_ifindex) p (fromIntegral n :: CInt)
215215
(#poke struct in6_pktinfo, ipi6_addr) p (In6Addr ha6)
@@ -218,8 +218,8 @@ instance Storable IPv6PktInfo where
218218
n :: CInt <- (#peek struct in6_pktinfo, ipi6_ifindex) p
219219
return $ IPv6PktInfo (fromIntegral n) ha6
220220
#else
221-
sizeOf _ = 0
222-
alignment _ = 1
221+
sizeOf ~_ = 0
222+
alignment ~_ = 1
223223
poke _ _ = error "Unsupported control message type"
224224
peek _ = error "Unsupported control message type"
225225
#endif

Network/Socket/Posix/CmsgHdr.hsc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ data CmsgHdr = CmsgHdr {
3232
} deriving (Eq, Show)
3333

3434
instance Storable CmsgHdr where
35-
sizeOf _ = (#size struct cmsghdr)
36-
alignment _ = alignment (0 :: CInt)
35+
sizeOf ~_ = (#size struct cmsghdr)
36+
alignment ~_ = alignment (0 :: CInt)
3737

3838
peek p = do
3939
len <- (#peek struct cmsghdr, cmsg_len) p

Network/Socket/Posix/IOVec.hsc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ data IOVec = IOVec
1919
}
2020

2121
instance Storable IOVec where
22-
sizeOf _ = (#const sizeof(struct iovec))
23-
alignment _ = alignment (0 :: CInt)
22+
sizeOf ~_ = (#const sizeof(struct iovec))
23+
alignment ~_ = alignment (0 :: CInt)
2424

2525
peek p = do
2626
base <- (#peek struct iovec, iov_base) p

Network/Socket/Posix/MsgHdr.hsc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ data MsgHdr sa = MsgHdr
3232
}
3333

3434
instance Storable (MsgHdr sa) where
35-
sizeOf _ = (#const sizeof(struct msghdr))
36-
alignment _ = alignment (0 :: CInt)
35+
sizeOf ~_ = (#const sizeof(struct msghdr))
36+
alignment ~_ = alignment (0 :: CInt)
3737

3838
peek p = do
3939
name <- (#peek struct msghdr, msg_name) p

Network/Socket/Types.hsc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -982,8 +982,8 @@ foreign import CALLCONV unsafe "ntohl" ntohl :: Word32 -> Word32
982982
{-# DEPRECATED ntohl "Use getAddrInfo instead" #-}
983983

984984
instance Storable PortNumber where
985-
sizeOf _ = sizeOf (0 :: Word16)
986-
alignment _ = alignment (0 :: Word16)
985+
sizeOf ~_ = sizeOf (0 :: Word16)
986+
alignment ~_ = alignment (0 :: Word16)
987987
poke p (PortNum po) = poke (castPtr p) (htons po)
988988
peek p = PortNum . ntohs <$> peek (castPtr p)
989989

@@ -1283,8 +1283,8 @@ newtype In6Addr = In6Addr HostAddress6
12831283
#endif
12841284

12851285
instance Storable In6Addr where
1286-
sizeOf _ = #const sizeof(struct in6_addr)
1287-
alignment _ = #alignment struct in6_addr
1286+
sizeOf ~_ = #const sizeof(struct in6_addr)
1287+
alignment ~_ = #alignment struct in6_addr
12881288

12891289
peek p = do
12901290
a <- peek32 p 0

Network/Socket/Unix.hsc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ getPeerCred s = do
8888

8989
newtype PeerCred = PeerCred (CUInt, CUInt, CUInt)
9090
instance Storable PeerCred where
91-
sizeOf _ = (#const sizeof(struct ucred))
92-
alignment _ = alignment (0 :: CInt)
91+
sizeOf ~_ = (#const sizeof(struct ucred))
92+
alignment ~_ = alignment (0 :: CInt)
9393
poke _ _ = return ()
9494
peek p = do
9595
pid <- (#peek struct ucred, pid) p

Network/Socket/Win32/Cmsg.hsc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ instance ControlMessage IPv4PktInfo where
160160
controlMessageId = CmsgIdIPv4PktInfo
161161

162162
instance Storable IPv4PktInfo where
163-
sizeOf _ = #{size IN_PKTINFO}
164-
alignment _ = #alignment IN_PKTINFO
163+
sizeOf ~_ = #{size IN_PKTINFO}
164+
alignment ~_ = #alignment IN_PKTINFO
165165
poke p (IPv4PktInfo n _ ha) = do
166166
(#poke IN_PKTINFO, ipi_ifindex) p (fromIntegral n :: CInt)
167167
(#poke IN_PKTINFO, ipi_addr) p ha
@@ -182,8 +182,8 @@ instance ControlMessage IPv6PktInfo where
182182
controlMessageId = CmsgIdIPv6PktInfo
183183

184184
instance Storable IPv6PktInfo where
185-
sizeOf _ = #{size IN6_PKTINFO}
186-
alignment _ = #alignment IN6_PKTINFO
185+
sizeOf ~_ = #{size IN6_PKTINFO}
186+
alignment ~_ = #alignment IN6_PKTINFO
187187
poke p (IPv6PktInfo n ha6) = do
188188
(#poke IN6_PKTINFO, ipi6_ifindex) p (fromIntegral n :: CInt)
189189
(#poke IN6_PKTINFO, ipi6_addr) p (In6Addr ha6)

Network/Socket/Win32/CmsgHdr.hsc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ data CmsgHdr = CmsgHdr {
2525
} deriving (Eq, Show)
2626

2727
instance Storable CmsgHdr where
28-
sizeOf _ = #{size WSACMSGHDR}
29-
alignment _ = #alignment WSACMSGHDR
28+
sizeOf ~_ = #{size WSACMSGHDR}
29+
alignment ~_ = #alignment WSACMSGHDR
3030

3131
peek p = do
3232
len <- (#peek WSACMSGHDR, cmsg_len) p

0 commit comments

Comments
 (0)