#2473: Data.Array.IO.Internals hidden in GHC6.8 for no good reason
------------------------+---------------------------------------------------
    Reporter:  ryani    |       Owner:                   
        Type:  bug      |      Status:  new              
    Priority:  normal   |   Component:  libraries (other)
     Version:  6.8.3    |    Severity:  normal           
    Keywords:           |    Testcase:                   
Architecture:  Unknown  |          Os:  Unknown          
------------------------+---------------------------------------------------
 I had some fast array modification code in C to modify the contents of an
 IOUArray, because I couldn't get my Haskell performance up to snuff.  Now
 that module is hidden in the array package and it doesn't seem possible to
 unhide it.

 The code compiled & worked quite well in GHC6.6.  I understand that by
 going into the internals I may have to update the code as the internals
 change, but it doesn't seem to be possible to do so at all at this point.
 The only workaround I can think of is to figure out the internal type from
 the source, re-declare it locally, and use unsafeCoerce# shenanigans to
 extract the data.  That seems terrible, since future changes to the
 internals could cause the code to start crashing without any compile-time
 warning at all.

 Bitmap.hs:
 {{{
 {-# OPTIONS_GHC -fffi -fglasgow-exts #-}
 {-# INCLUDE "bitmap_operations.h" #-}
 module Bitmap(clearBitmap) where

 import Data.Array.Base
 import Data.Array.IO.Internals
 import GHC.Exts
 import Data.Word

 foreign import ccall unsafe clear_bitmap
   :: MutableByteArray# RealWorld -> Word32 -> Word32 -> IO ()

 {-# INLINE unsafeGetMutableArray# #-}
 unsafeGetMutableArray# :: IOUArray Int Word32 -> MutableByteArray#
 RealWorld
 unsafeGetMutableArray# (IOUArray (STUArray _ _ array#)) = array#

 clearBitmap :: IOUArray Int Word32 -> Word32 -> Word32 -> IO ()
 clearBitmap a c sz = clear_bitmap (unsafeGetMutableArray# a) c sz
 }}}

 bitmap_operations.h:
 {{{
 #include "HsFFI.h"

 void clear_bitmap(void* p, HsWord32 color, HsWord32 size);
 }}}

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2473>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to