caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re: [Caml-list] caml_oldify_local_roots crashes
@ 2005-01-02 19:00 Zakath
  0 siblings, 0 replies; 3+ messages in thread
From: Zakath @ 2005-01-02 19:00 UTC (permalink / raw)
  To: rich; +Cc: caml-list

> On Sun, Dec 26, 2004 at 04:35:53AM +0000, Jon Harrop wrote:
> > On Sat, 25 Dec 2004, haiku.issa wrote:
> > > Everything worked fine until I added a subfunction that simply
> > > merges two int lists.
> > I am no expert on this but I believe this implies that your interfacing 
> > between C and OCaml was already broken. Almost certainly something to do 
> > with the GC.

> It often helps to add lots of calls to Gc.full_major () to your code.
> One of these will crash, telling you that between that call and the
> previous one, you did something bad to the heap.
> 
> Rich.

I eventually found out : I was following the book "Devloppement d'applications avec Objective Caml" instead of the OCaml manual. They were advicing to register local variables and parameters (with CAMLparam* and CAMLlocal*) when using a callback.
Removing them made everything work fine.

To be more accurate, it was creating a corrupted entry of local_roots. from /asmrun/roots.c (or byterun), there was (lr->next == lr) in some point, which was causing the looping.
May be this should be said in the Manual ?

Thnaks for your help

Alexandre


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] caml_oldify_local_roots crashes
  2004-12-26  4:35 ` [Caml-list] " Jon Harrop
@ 2004-12-30 22:41   ` Richard Jones
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Jones @ 2004-12-30 22:41 UTC (permalink / raw)
  To: Jon Harrop; +Cc: caml-list

On Sun, Dec 26, 2004 at 04:35:53AM +0000, Jon Harrop wrote:
> On Sat, 25 Dec 2004, haiku.issa wrote:
> >Everything worked fine until I added a subfunction that simply
> >merges two int lists.
> I am no expert on this but I believe this implies that your interfacing 
> between C and OCaml was already broken. Almost certainly something to do 
> with the GC.

It often helps to add lots of calls to Gc.full_major () to your code.
One of these will crash, telling you that between that call and the
previous one, you did something bad to the heap.

Rich.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] caml_oldify_local_roots crashes
  2004-12-25 13:11 haiku.issa
@ 2004-12-26  4:35 ` Jon Harrop
  2004-12-30 22:41   ` Richard Jones
  0 siblings, 1 reply; 3+ messages in thread
From: Jon Harrop @ 2004-12-26  4:35 UTC (permalink / raw)
  Cc: caml-list


On Sat, 25 Dec 2004, haiku.issa wrote:
> I am currently developping a small piece of software that uses
> both OCaml and C (for openGL). The main loop is in C and I use
> callback to call a Caml function that processes the key that
> was pressed and returns the new state of a matrix.

Do you have to use C at all? Have you looked at lablGL?

I strongly recommend that you avoid interfacing to C whenever possible...

> Everything worked fine until I added a subfunction that simply
> merges two int lists.

I am no expert on this but I believe this implies that your interfacing 
between C and OCaml was already broken. Almost certainly something to do 
with the GC. There are rules that you must adhere to when writing the 
interface code, of course, and human errors are a great cause of bugs 
here. I'd also strongly recommend that you try to write the simplest 
possible first working version and optimise it later only if necessary. 
Unfortunately I'm too drunk and full of turkey to help with any code right 
now...

Cheers,
Jon.

PS: If you program starts at "main" in C code then I assume you've 
initialised the OCaml GC before calling any OCaml code?


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-01-02 20:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-02 19:00 [Caml-list] caml_oldify_local_roots crashes Zakath
  -- strict thread matches above, loose matches on Subject: below --
2004-12-25 13:11 haiku.issa
2004-12-26  4:35 ` [Caml-list] " Jon Harrop
2004-12-30 22:41   ` Richard Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).