[project @ 2001-04-26 15:42:06 by sewardj]
authorsewardj <unknown>
Thu, 26 Apr 2001 15:42:06 +0000 (15:42 +0000)
committersewardj <unknown>
Thu, 26 Apr 2001 15:42:06 +0000 (15:42 +0000)
Fix bug in which *primitive* string literals were being checked for
Unicode-ness, even though they are not allowed to be; literals
containing zero bytes were then unicodified, which crashes the
bytecode generator.

ghc/compiler/parser/Lex.lhs
ghc/compiler/utils/FastString.lhs

index 130eef8..faec03f 100644 (file)
@@ -52,7 +52,7 @@ import FastString
 import StringBuffer
 import GlaExts
 import Ctype
-import Char            ( ord )
+import Char            ( chr, ord )
 import PrelRead        ( readRational__ ) -- Glasgow non-std
 \end{code}
 
@@ -668,11 +668,12 @@ lex_prag cont buf
 lex_string cont glaexts s buf
   = case currentChar# buf of
        '"'#{-"-} -> 
-          let buf' = incLexeme buf; s' = mkFastStringInt (reverse s) in
-          case currentChar# buf' of
+          let buf' = incLexeme buf
+               s' = mkFastStringNarrow (map chr (reverse s)) 
+           in case currentChar# buf' of
                '#'# | flag glaexts -> if all (<= 0xFF) s
                     then cont (ITprimstring s') (incLexeme buf')
-                    else lexError "primitive string literal must contain only characters <= '\xFF'" buf'
+                    else lexError "primitive string literal must contain only characters <= \'\\xFF\'" buf'
                _                   -> cont (ITstring s') buf'
 
        -- ignore \& in a string, deal with string gaps
index eebb53a..bb0a02f 100644 (file)
@@ -13,6 +13,7 @@ module FastString
 
          --names?
         mkFastString,       -- :: String -> FastString
+        mkFastStringNarrow, -- :: String -> FastString
         mkFastSubString,    -- :: Addr -> Int -> Int -> FastString
 
        -- These ones hold on to the Addr after they return, and aren't hashed;