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.
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#)
)
= 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