Changes between Version 19 and Version 20 of BlockObjects


Ignore:
Timestamp:
Aug 25, 2011 12:25:22 PM (4 years ago)
Author:
chak
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • BlockObjects

    v19 v20  
    1818and then executing
    1919{{{
    20 do
    21     -- convert a list of strings into a C array of stable pointers to those strings in the Haskell heap
    22   ptrs <- mapM newStablePtr myCharacters
    23   myCharactersArray <- newArray ptrs
    24  
    25    -- get the size in bytes of a stable pointer to a Haskell string
    26   let elemSize = fromIntegral $ sizeOf (undefined :: StablePtr String)
     20do {   -- convert a list of strings into a C array of stable pointers to those strings in the Haskell heap
     21   ; ptrs       <- mapM newStablePtr myCharacters
     22   ; sortedPtrs <- withArray ptrs $ \myCharactersArray -> do
     23       {
     24           -- get the size in bytes of a stable pointer to a Haskell string
     25       ; let elemSize = fromIntegral $ sizeOf (undefined :: StablePtr String)
    2726
    28     -- invoke C land 'qsort_b' with a Haskell comparison function passed as a block object; mutates 'myCharactersArray'
    29   qsort_b myCharactersArray (length myCharacters) elemSize (\l r -> fromOrdering (l `compare` r))
     27           -- invoke C land 'qsort_b' with a Haskell comparison function passed as a block object; mutates 'myCharactersArray'
     28       ; qsort_b myCharactersArray (length myCharacters) elemSize (\l r -> fromOrdering (l `compare` r))
    3029
    31     -- turn the array of Haskell strings back into a list of strings
    32   mySortedCharacters <- mapM deRefStablePtr myCharactersArray
     30           -- obtain the sorted list of stable pointers from the sorted array
     31       ; peekArray (length ptrs) myCharactersArray
     32       }
     33
     34      -- turn the array of Haskell strings back into a list of strings
     35   ; mySortedCharacters <- mapM deRefStablePtr sortedPtrs
     36   }
    3337}}}
    3438Here we compare entire strings and not just the first characters as in the C implementation.  The marshalling function `fromOrdering` is defined as follows: