From: simonmar Date: Thu, 31 Jan 2002 13:42:20 +0000 (+0000) Subject: [project @ 2002-01-31 13:42:20 by simonmar] X-Git-Tag: Approximately_9120_patches~200 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=95ac9a43042be46611c4eff33d2dbbc8518fd477;p=ghc-hetmet.git [project @ 2002-01-31 13:42:20 by simonmar] Fix a classic bug: copying a Haskell string with one of the C string functions (in this case strncpy()) is wrong when the string contains '\0' characters. The symptom in this case is that Happy parsers created with -ag don't work in GHCi, because the state tables are encoded as strings containing lots of '\0' elements. --- diff --git a/ghc/compiler/ghci/ByteCodeGen.lhs b/ghc/compiler/ghci/ByteCodeGen.lhs index bc93d39..411f1ad 100644 --- a/ghc/compiler/ghci/ByteCodeGen.lhs +++ b/ghc/compiler/ghci/ByteCodeGen.lhs @@ -1202,7 +1202,7 @@ pushAtom False d p (AnnLit lit) in ioToBc (mallocBytes (n+1)) `thenBc` \ (Ptr a#) -> recordMallocBc (A# a#) `thenBc_` ioToBc ( - do strncpy (Ptr a#) ba (fromIntegral n) + do memcpy (Ptr a#) ba (fromIntegral n) writeCharOffAddr (A# a#) n '\0' return (A# a#) ) @@ -1230,7 +1230,7 @@ pushAtom tagged d p other = pprPanic "ByteCodeGen.pushAtom" (pprCoreExpr (deAnnotate (undefined, other))) -foreign import "strncpy" strncpy :: Ptr a -> ByteArray# -> CInt -> IO () +foreign import "memcpy" memcpy :: Ptr a -> ByteArray# -> CInt -> IO () -- Given a bunch of alts code and their discrs, do the donkey work