Commit 95ac9a43 authored by simonmar's avatar simonmar
Browse files

[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.
parent 2980a982
......@@ -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
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment