nlffi memory problems on power ppc

brian <[email protected]> Wed, 7 Mar 2007 22:10:00 -0800
Newsgroups gmane.comp.lang.sml.smlnj
Message-ID <[email protected]>
OK.  I have a reasonably coherent example and a specific set of  
failure conditions, so perhaps someone can tell me what's wrong.

I should preface this with some info:

Mac Power PC G5
Standard ML of New Jersey v110.60 [built: Thu Nov  9 15:44:30 2006]

Here's the test code:

fun memtest() =
     let fun set(p, i, x) = C.Set.double (C.Ptr.|*| (C.Ptr.|+| (p,  
i)), x)
         fun fromArray(values) =
             let val n = Array.length(values)
                 val m = C.alloc C.T.double (Word.fromInt n)
                 val _ = Array.appi (fn (i, x) => set(m, i, x)) values
             in
                 (* return a read-write version of the pointer *)
                 C.Ptr.rw m
             end
         val a1 = Array.fromList([0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0])
         val a2 = Array.fromList([0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0])
         val b1 = fromArray(a1)
         (* val b2 = fromArray(a2) *)
     in
         C.free b1;
         (* C.free b2; *)
         ()
     end

The test code as is WORKS.
If the "val b2 = ..." line is uncommented, then the test code gives  
me a bus error.
If the "C.free b2" line is uncommented, then the code gives me a  
segmentation fault.

Thanks

Brian


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV