Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
GHC
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Glasgow Haskell Compiler
GHC
Commits
b6407eca
Commit
b6407eca
authored
26 years ago
by
sof
Browse files
Options
Downloads
Patches
Plain Diff
[project @ 1998-06-29 14:11:09 by sof]
New functions: isCString, psToCString
parent
1dd929d5
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ghc/lib/misc/PackedString.lhs
+27
-1
27 additions, 1 deletion
ghc/lib/misc/PackedString.lhs
with
27 additions
and
1 deletion
ghc/lib/misc/PackedString.lhs
+
27
−
1
View file @
b6407eca
...
...
@@ -21,6 +21,8 @@ module PackedString (
psToByteArray, -- :: PackedString -> ByteArray Int
psToByteArrayST, -- :: PackedString -> ST s (ByteArray Int)
psToCString, -- :: PackedString -> Addr
isCString, -- :: PackedString -> Bool
unpackPS, -- :: PackedString -> [Char]
{-LATER:
...
...
@@ -73,7 +75,7 @@ module PackedString (
) where
import GlaExts
import PrelBase ( showList__ ) -- ToDo: better
import PrelBase ( showList__
) -- ToDo: better
import Addr
import PrelArr ( StateAndMutableByteArray#(..) , StateAndByteArray#(..) )
...
...
@@ -275,6 +277,30 @@ psToByteArray (CPS addr len#)
in
case byte_array_form of { PS bytes _ _ ->
ByteArray (0, len - 1) bytes }
-- isCString is useful when passing PackedStrings to the
-- outside world, and need to figure out whether you can
-- pass it as an Addr or ByteArray.
--
isCString :: PackedString -> Bool
isCString (CPS _ _ ) = True
isCString _ = False
psToCString :: PackedString -> Addr
psToCString (CPS addr _) = (A# addr)
psToCString (PS bytes n# has_null) =
unsafePerformIO $ do
stuff <- _ccall_ malloc ((I# n#) * (``sizeof(char)''))
let
fill_in n# i#
| n# ==# 0# = return ()
| otherwise = do
let ch# = indexCharArray# bytes i#
writeCharOffAddr stuff (I# i#) (C# ch#)
fill_in (n# -# 1#) (i# +# 1#)
fill_in n# 0#
return stuff
\end{code}
%************************************************************************
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment