<div>Ah, sneaky. That code is fine because it uses unsafeCoerce# on "memcpy", changing memcpy from whatever type it is, into</div>
<div>MutableByteArray# s# -> MutableByteArray# s# -> Int# -> s# -> (# s#, () #)</div>
<div> </div>
<div>So as long as the GC understands MutableByteArray# it's safe; it's relying on the C calling convention being handled properly.<br> </div>
<div><span class="gmail_quote">On 8/21/07, <b class="gmail_sendername">Bulat Ziganshin</b> <<a href="mailto:bulat.ziganshin@gmail.com">bulat.ziganshin@gmail.com</a>> wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Hello Stefan,<br><br>Tuesday, August 21, 2007, 10:08:59 AM, you wrote:<br><br>> Your code is broken in a most evil and insidious way.
<br><br>and this code, too? :)<br><br>freezeSTUArray :: Ix i => STUArray s i e -> ST s (UArray i e)<br>freezeSTUArray (STUArray l u marr#) = ST $ \s1# -><br> case sizeofMutableByteArray# marr# of { n# -><br>
case newByteArray# n# s1# of { (# s2#, marr'# #) -><br> case unsafeCoerce# memcpy marr'# marr# n# s2# of { (# s3#, () #) -><br> case unsafeFreezeByteArray# marr'# s3# of { (# s4#, arr# #) ->
<br> (# s4#, UArray l u arr# #) }}}}<br><br>> Unreproducable bugs are rarely reported, but they do add to people's<br>> impression of how unstable a language/library is.<br><br><br><br><br>--<br>Best regards,<br>
Bulat mailto:<a href="mailto:Bulat.Ziganshin@gmail.com">Bulat.Ziganshin@gmail.com</a><br><br></blockquote></div><br>