[project @ 2003-03-14 13:08:04 by simonmar]
authorsimonmar <unknown>
Fri, 14 Mar 2003 13:08:04 +0000 (13:08 +0000)
committersimonmar <unknown>
Fri, 14 Mar 2003 13:08:04 +0000 (13:08 +0000)
Attach the finalizer to the write side of a duplex handle, where it
should have been.  Otherwise finalization of duplex handles doesn't
work properly.

MERGE TO STABLE

GHC/Handle.hs

index 260074d..4381de0 100644 (file)
@@ -320,23 +320,8 @@ stdHandleFinalizer m = do
 handleFinalizer :: MVar Handle__ -> IO ()
 handleFinalizer m = do
   h_ <- takeMVar m
-  let
-    -- hClose puts both the fd and the handle's type
-    -- into a closed state, so it's a bit excessive
-    -- to test for both here, but caution sometimes
-    -- pays off..
-   alreadyClosed = 
-     case haType h_ of { ClosedHandle{} -> True; _ -> False }
-   fd = fromIntegral (haFD h_)
-
-  when (not alreadyClosed && fd /= -1) $ do
-       flushWriteBufferOnly h_
-       unlockFile fd
-#ifdef mingw32_TARGET_OS
-       (closeFd (haIsStream h_) fd >> return ())
-#else
-       (c_close fd >> return ())
-#endif
+  hClose_help h_
+  return ()
 
 -- ---------------------------------------------------------------------------
 -- Grimy buffer operations
@@ -839,7 +824,7 @@ mkDuplexHandle fd is_stream filepath binary = do
                      }
   read_side <- newMVar r_handle_
 
-  addMVarFinalizer read_side (handleFinalizer read_side)
+  addMVarFinalizer write_side (handleFinalizer write_side)
   return (DuplexHandle read_side write_side)