Re: nlffi memory problems on power ppc

Vesa A Norrman <[email protected]> Wed, 11 Apr 2007 20:37:26 +0300 (EEST)
Newsgroups gmane.comp.lang.sml.smlnj
Message-ID <[email protected]>
Perhaps the problem with malloc/free happens because they are in different 
place than other dl-loaded functions. I mean they do not have to be 
dl-loaded.

You can experiment by adding

if (strcmp(symname, "malloc") == 0) addr = &malloc;

in dlsym.c. Then it would not use dl-loading for those functions.

Really, I don't know if that will make any difference (and I don't have 
a mac too).

  - Vesa

On Wed, 11 Apr 2007, brian wrote:

> Thanks very much for looking into this !  I'm glad it's not just me.
>
> Unfortunately it's very hard to get anything done in C without
> allocating memory.
>
> I think that I've been able to create bindings to malloc/free as a
> work around, but there is some problem with doing that which I can't
> seem to remember.  Maybe this is an additional clue.
>
> I'm working on a X3D/vrml thing right now, and then I'm going to get
> back to the X/opengl interface where this is causing lots of problems
> because of all those event structures I have to allocate.
>
> Interestingly, any library, fftw is a good example, which provides
> it's own memory allocation, does not seem to cause any problems ?!
>
> "Heisenbug"  - good one - I haven't heard that before.
>
> Brian
>
> P.S. Naturally I'm happy to help out with this, just let me know what
> I can do.  I did actually look through the low-level nlffi code and
> my untrained eye could not discern anything which looked like a
> potential problem.
>
>
> On Apr 10, 2007, at 9:49 PM, Matthias Blume wrote:
>
>> Hi Brian,
>>
>> I tried to experiment a bit with this code, and it is quite
>> frustrating... :-(
>>
>> Indeed, I can reproduce your problem on my G5 using the code you
>> posted.
>> However, adding a bit of instrumentation seems to make the problem
>> go away.  In particular, I added a routine for printing the contents
>> of a C array. Putting an invocation of this routine any place where it
>> makes sense makes the problem completely vanish.
>>
>> In other words, this looks more and more like a "Heisenbug".  Right
>> now I don't have a good guess at what's causing this.  I'll keep
>> looking.
>>
>> Matthias
>>
>>
>> On Mar 8, 2007, at 12:10 AM, brian wrote:
>>
>>> 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
>>> _______________________________________________
>>> Smlnj-list mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/smlnj-list
>>>
>>
>>
>> ----------------------------------------------------------------------
>> ---
>> 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
>> _______________________________________________
>> Smlnj-list mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/smlnj-list
>
>
> -------------------------------------------------------------------------
> 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
> _______________________________________________
> Smlnj-list mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/smlnj-list
>

-- 
                                     /`---*\
                                    = ^ o ^ =
                                     `-----'

-------------------------------------------------------------------------
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