Skip to content

Commit e6e1d8b

Browse files
committed
removing undefined as many as possible.
1 parent 11abcef commit e6e1d8b

File tree

13 files changed

+30
-51
lines changed

13 files changed

+30
-51
lines changed

Network/Socket/ByteString/Lazy/Posix.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ send s lbs = do
3838
| k < maxNumBytes = unsafeUseAsCStringLen c $ \(ptr, len) -> do
3939
poke q $ IOVec (castPtr ptr) (fromIntegral len)
4040
loop cs
41-
(q `plusPtr` sizeOf (undefined :: IOVec))
41+
(q `plusPtr` sizeOf (IOVec nullPtr 0))
4242
(k + fromIntegral len)
4343
(niovs + 1)
4444
| otherwise = f niovs

Network/Socket/Info.hsc

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ data AddrInfo = AddrInfo {
110110

111111
instance Storable AddrInfo where
112112
sizeOf _ = #const sizeof(struct addrinfo)
113-
alignment _ = alignment (undefined :: CInt)
113+
alignment _ = alignment (0 :: CInt)
114114

115115
peek p = do
116116
ai_flags <- (#peek struct addrinfo, ai_flags) p
@@ -181,9 +181,7 @@ niFlagMapping = [(NI_DGRAM, #const NI_DGRAM),
181181
(NI_NUMERICHOST, #const NI_NUMERICHOST),
182182
(NI_NUMERICSERV, #const NI_NUMERICSERV)]
183183

184-
-- | Default hints for address lookup with 'getAddrInfo'. The values
185-
-- of the 'addrAddress' and 'addrCanonName' fields are 'undefined',
186-
-- and are never inspected by 'getAddrInfo'.
184+
-- | Default hints for address lookup with 'getAddrInfo'.
187185
--
188186
-- >>> addrFlags defaultHints
189187
-- []
@@ -200,29 +198,10 @@ defaultHints = AddrInfo {
200198
, addrFamily = AF_UNSPEC
201199
, addrSocketType = NoSocketType
202200
, addrProtocol = defaultProtocol
203-
, addrAddress = undefined
204-
, addrCanonName = undefined
201+
, addrAddress = SockAddrInet 0 0
202+
, addrCanonName = Nothing
205203
}
206204

207-
-- | Shows the fields of 'defaultHints', without inspecting the by-default undefined fields 'addrAddress' and 'addrCanonName'.
208-
showDefaultHints :: AddrInfo -> String
209-
showDefaultHints AddrInfo{..} = concat [
210-
"AddrInfo {"
211-
, "addrFlags = "
212-
, show addrFlags
213-
, ", addrFamily = "
214-
, show addrFamily
215-
, ", addrSocketType = "
216-
, show addrSocketType
217-
, ", addrProtocol = "
218-
, show addrProtocol
219-
, ", addrAddress = "
220-
, "<assumed to be undefined>"
221-
, ", addrCanonName = "
222-
, "<assumed to be undefined>"
223-
, "}"
224-
]
225-
226205
-----------------------------------------------------------------------------
227206
-- | Resolve a host or service name to one or more addresses.
228207
-- The 'AddrInfo' values that this function returns contain 'SockAddr'
@@ -294,7 +273,7 @@ getAddrInfo hints node service = alloc getaddrinfo
294273
err
295274
message = concat [
296275
"Network.Socket.getAddrInfo (called with preferred socket type/protocol: "
297-
, maybe (show hints) showDefaultHints hints
276+
, maybe "Nothing" show hints
298277
, ", host name: "
299278
, show node
300279
, ", service name: "

Network/Socket/Options.hsc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,8 @@ pattern CustomSockOpt xy <- ((\(SockOpt x y) -> (x, y)) -> xy)
285285
data StructLinger = StructLinger CInt CInt
286286

287287
instance Storable StructLinger where
288-
sizeOf _ = (#const sizeof(struct linger))
289-
alignment _ = alignment (undefined :: CInt)
288+
sizeOf _ = (#const sizeof(struct linger))
289+
alignment _ = alignment (0 :: CInt)
290290

291291
peek p = do
292292
onoff <- (#peek struct linger, l_onoff) p

Network/Socket/Posix/Cmsg.hsc

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

170170
instance Storable IPv4PktInfo where
171171
#if defined (IP_PKTINFO)
172-
sizeOf _ = (#size struct in_pktinfo)
173-
alignment _ = alignment (undefined :: CInt)
172+
sizeOf _ = (#size struct in_pktinfo)
173+
alignment _ = alignment (0 :: CInt)
174174
poke p (IPv4PktInfo n sa ha) = do
175175
(#poke struct in_pktinfo, ipi_ifindex) p (fromIntegral n :: CInt)
176176
(#poke struct in_pktinfo, ipi_spec_dst) p sa
@@ -181,7 +181,7 @@ instance Storable IPv4PktInfo where
181181
ha <- (#peek struct in_pktinfo, ipi_addr) p
182182
return $ IPv4PktInfo n sa ha
183183
#else
184-
sizeOf _ = 0
184+
sizeOf _ = 0
185185
alignment _ = 1
186186
poke _ _ = error "Unsupported control message type"
187187
peek _ = error "Unsupported control message type"
@@ -200,8 +200,8 @@ instance ControlMessage IPv6PktInfo where
200200

201201
instance Storable IPv6PktInfo where
202202
#if defined (IPV6_PKTINFO)
203-
sizeOf _ = (#size struct in6_pktinfo)
204-
alignment _ = alignment (undefined :: CInt)
203+
sizeOf _ = (#size struct in6_pktinfo)
204+
alignment _ = alignment (0 :: CInt)
205205
poke p (IPv6PktInfo n ha6) = do
206206
(#poke struct in6_pktinfo, ipi6_ifindex) p (fromIntegral n :: CInt)
207207
(#poke struct in6_pktinfo, ipi6_addr) p (In6Addr ha6)
@@ -210,7 +210,7 @@ instance Storable IPv6PktInfo where
210210
n :: CInt <- (#peek struct in6_pktinfo, ipi6_ifindex) p
211211
return $ IPv6PktInfo (fromIntegral n) ha6
212212
#else
213-
sizeOf _ = 0
213+
sizeOf _ = 0
214214
alignment _ = 1
215215
poke _ _ = error "Unsupported control message type"
216216
peek _ = error "Unsupported control message type"

Network/Socket/Posix/CmsgHdr.hsc

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

3030
instance Storable CmsgHdr where
31-
sizeOf _ = (#size struct cmsghdr)
32-
alignment _ = alignment (undefined :: CInt)
31+
sizeOf _ = (#size struct cmsghdr)
32+
alignment _ = alignment (0 :: CInt)
3333

3434
peek p = do
3535
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 (undefined :: 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
@@ -24,8 +24,8 @@ data MsgHdr sa = MsgHdr
2424
}
2525

2626
instance Storable (MsgHdr sa) where
27-
sizeOf _ = (#const sizeof(struct msghdr))
28-
alignment _ = alignment (undefined :: CInt)
27+
sizeOf _ = (#const sizeof(struct msghdr))
28+
alignment _ = alignment (0 :: CInt)
2929

3030
peek p = do
3131
name <- (#peek struct msghdr, msg_name) p

Network/Socket/Types.hsc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -910,8 +910,8 @@ foreign import CALLCONV unsafe "ntohl" ntohl :: Word32 -> Word32
910910
{-# DEPRECATED ntohl "Use getAddrInfo instead" #-}
911911

912912
instance Storable PortNumber where
913-
sizeOf _ = sizeOf (undefined :: Word16)
914-
alignment _ = alignment (undefined :: Word16)
913+
sizeOf _ = sizeOf (0 :: Word16)
914+
alignment _ = alignment (0 :: Word16)
915915
poke p (PortNum po) = poke (castPtr p) (htons po)
916916
peek p = PortNum . ntohs <$> peek (castPtr p)
917917

@@ -1221,7 +1221,7 @@ newtype In6Addr = In6Addr HostAddress6
12211221
#endif
12221222

12231223
instance Storable In6Addr where
1224-
sizeOf _ = #const sizeof(struct in6_addr)
1224+
sizeOf _ = #const sizeof(struct in6_addr)
12251225
alignment _ = #alignment struct in6_addr
12261226

12271227
peek p = do

Network/Socket/Unix.hsc

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

8282
newtype PeerCred = PeerCred (CUInt, CUInt, CUInt)
8383
instance Storable PeerCred where
84-
sizeOf _ = (#const sizeof(struct ucred))
85-
alignment _ = alignment (undefined :: CInt)
84+
sizeOf _ = (#const sizeof(struct ucred))
85+
alignment _ = alignment (0 :: CInt)
8686
poke _ _ = return ()
8787
peek p = do
8888
pid <- (#peek struct ucred, pid) p

Network/Socket/Win32/Cmsg.hsc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ instance ControlMessage IPv4PktInfo where
147147
controlMessageId = CmsgIdIPv4PktInfo
148148

149149
instance Storable IPv4PktInfo where
150-
sizeOf = const #{size IN_PKTINFO}
150+
sizeOf _ = #{size IN_PKTINFO}
151151
alignment _ = #alignment IN_PKTINFO
152152
poke p (IPv4PktInfo n ha) = do
153153
(#poke IN_PKTINFO, ipi_ifindex) p (fromIntegral n :: CInt)
@@ -169,7 +169,7 @@ instance ControlMessage IPv6PktInfo where
169169
controlMessageId = CmsgIdIPv6PktInfo
170170

171171
instance Storable IPv6PktInfo where
172-
sizeOf = const #{size IN6_PKTINFO}
172+
sizeOf _ = #{size IN6_PKTINFO}
173173
alignment _ = #alignment IN6_PKTINFO
174174
poke p (IPv6PktInfo n ha6) = do
175175
(#poke IN6_PKTINFO, ipi6_ifindex) p (fromIntegral n :: CInt)

0 commit comments

Comments
 (0)