Skip to content

internal error: mallocBytesRWX:

while loading my code (RBtrees implementation) sometimes interpreter says: OK but sometimes (quite often) it crashes with description like:

Prelude Main> :load E.hs
Compiling Main             ( E.hs, interpreted )
ghc-6.4.2: internal error: mallocBytesRWX: failed to protect 0x0xa8e5c70

    Please report this as a compiler bug.  See:
    http://www.haskell.org/ghc/reportabug

my RBtrees implementation is not finished yet, I found out that interpreter crashes only after I add "veryLeftChild" function (code below). Compiler works fine with or without this function, no problems. my code:

module Main
    where

import IO

{- --- implementacja drzew czerwono-czarnych wg. Okasakiego ---------------- -}

data Color = Red | Black
data Tree x = E | T Color (Tree x) x (Tree x)

type Set a = Tree a

-- empty : T -> bool
empty = E

-- member : x,T -> bool
member _ E = False
member n@(k,x,y) (T _ l (k',_,_) r) | k < k'  = member n l
									| k > k'  = member n r
									| k == k' = True

-- insert : x,T -> T
insert n@(k,x,y) s = makeBlack(insert_ s)
	where
		insert_ (T col l n'@(k',x',y') r ) | k < k'  = balance col (insert_ l) n' r
										   | k > k'  = balance col l n' (insert_ r)
										   | k == k' = T col l n r ;
		insert_ E = T Red E n E ;
		makeBlack (T _ l n' r) = T Black l n' r

-- balance T -> T
balance Black (T Red (T Red a x b) y c) z d = T Red (T Black a x b) y (T Black c z d)
balance Black (T Red a x (T Red b y c)) z d = T Red (T Black a x b) y (T Black c z d)
balance Black a x (T Red (T Red b y c) z d) = T Red (T Black a x b) y (T Black c z d)
balance Black a x (T Red b y (T Red c z d)) = T Red (T Black a x b) y (T Black c z d)
balance color a x b = T color a x b


-- locate x,T -> T
locate k tree@(T _ left@(T _ _ k1 _) k' right@(T _ _ k2 _)) | k == k' 			= tree
															| k1 < k && k < k2  = tree
															| k1 >= k			= locate k left
															| k <= k2			= locate k right

veryLeftChild tree@(T _ left k _) | left == E	= k
								  | True 		= veryLeftChild left

-- next k tree = 


-- delete : x,T -> T
{- remove n@(k,x,y) s = remove_ s
	where
		remove_ -}

{- --- main i miedzymordzie ------------------------------------------------ -}

main = do
	hSetBuffering stdin LineBuffering
	n <- getLine
	while (rInt n) empty -- wywolanie operacji na drzewie (poczatkowo pustym)

rInt :: String -> Int
rInt = read

-- scan : String -> (cmd, x, y)
scan (l:' ':xs) = ( l, rInt x, rInt y )
	where
		(x,y) = scan xs;
		scan (x:xs) | x == ' ' = ([], xs)
					| True     = (x:xs', ys') where (xs',ys') = scan(xs)
		scan [] = ([],[])

-- while iteruje operacje i razy na tree
while i tree = do
	if i == 0
		then return []
		else do
			cmd <- getLine
			let (output, tree') = command (scan cmd) tree
			putStr output
			r <- while (i-1) tree'
			return r

-- wywoluje odpowiednia operacje na drzewie
command (cmd,x,y) tree | cmd == 'W' = ("", insert (x*x+y*y,x,y) tree )
					   | cmd == 'U' = ("usun\n", tree )
					   | cmd == 'D' = ("dalszy\n", tree )
					   | cmd == 'B' = ("blizszy\n", tree )
					   | True		= error "wrong command"

I use ghc 6.4.2, Linux, Fedora Core 5, x86. For any further info contact me through dreamer.tan@gmail.com

Trac metadata
Trac field Value
Version 6.4.2
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component GHCi
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information