From 6c58d6ea125183406b611c18e973ab60212ad272 Mon Sep 17 00:00:00 2001 From: sewardj Date: Wed, 7 Feb 2001 12:54:09 +0000 Subject: [PATCH] [project @ 2001-02-07 12:54:09 by sewardj] Try and fix the freeStringBuffer nightmare once and for all. --- ghc/compiler/main/HscMain.lhs | 6 +++--- ghc/compiler/utils/StringBuffer.lhs | 12 ++++++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/ghc/compiler/main/HscMain.lhs b/ghc/compiler/main/HscMain.lhs index 089e8b6..6bb6d6f 100644 --- a/ghc/compiler/main/HscMain.lhs +++ b/ghc/compiler/main/HscMain.lhs @@ -15,7 +15,6 @@ module HscMain ( HscResult(..), hscMain, #ifdef GHCI import RdrHsSyn ( RdrNameHsExpr ) import Rename ( renameExpr ) -import StringBuffer ( stringToStringBuffer, freeStringBuffer ) import Unique ( Uniquable(..) ) import Type ( Type, splitTyConApp_maybe ) import PrelNames ( ioTyConKey ) @@ -24,7 +23,8 @@ import ByteCodeGen ( byteCodeGen ) import HsSyn -import StringBuffer ( hGetStringBuffer ) +import StringBuffer ( hGetStringBuffer, + stringToStringBuffer, freeStringBuffer ) import Parser import Lex ( PState(..), ParseResult(..) ) import SrcLoc ( mkSrcLoc ) @@ -296,7 +296,7 @@ myParseModule dflags src_filename loc = mkSrcLoc (_PK_ src_filename) 1 } of { PFailed err -> do { hPutStrLn stderr (showSDoc err); --- Not yet implemented in <4.11 freeStringBuffer buf; + freeStringBuffer buf; return Nothing }; POk _ rdr_module@(HsModule mod_name _ _ _ _ _ _) -> do { diff --git a/ghc/compiler/utils/StringBuffer.lhs b/ghc/compiler/utils/StringBuffer.lhs index f95f7a1..713dc77 100644 --- a/ghc/compiler/utils/StringBuffer.lhs +++ b/ghc/compiler/utils/StringBuffer.lhs @@ -13,10 +13,8 @@ module StringBuffer -- creation/destruction hGetStringBuffer, -- :: FilePath -> IO StringBuffer -#ifdef GHCI stringToStringBuffer, -- :: String -> IO StringBuffer freeStringBuffer, -- :: StringBuffer -> IO () -#endif -- Lookup currentChar, -- :: StringBuffer -> Char @@ -77,6 +75,7 @@ import Addr ( Addr(..) ) #endif import Foreign import Char ( chr ) +import Panic ( panic ) -- urk! #include "../lib/std/cbits/stgerror.h" @@ -195,8 +194,10 @@ unsafeWriteBuffer s@(StringBuffer a _ _ _) i# ch# = -- Turn a String into a StringBuffer \begin{code} -#ifdef GHCI stringToStringBuffer :: String -> IO StringBuffer +freeStringBuffer :: StringBuffer -> IO () + +#if __GLASGOW_HASKELL__ >= 411 stringToStringBuffer str = do let sz@(I# sz#) = length str + 1 (Ptr a#) <- mallocBytes sz @@ -209,9 +210,12 @@ stringToStringBuffer str = writeCharOffAddr a 0 c fill_in cs (a `plusAddr` 1) -freeStringBuffer :: StringBuffer -> IO () freeStringBuffer (StringBuffer a# _ _ _) = Foreign.free (Ptr a#) +#else +stringToStringBuffer = panic "stringToStringBuffer: not implemented" +freeStringBuffer sb = return () #endif + \end{code} ----------------------------------------------------------------------------- -- 1.7.10.4