caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Garbage Again
@ 2001-12-28 15:22 Warp
  2002-01-03 14:35 ` Xavier Leroy
  0 siblings, 1 reply; 3+ messages in thread
From: Warp @ 2001-12-28 15:22 UTC (permalink / raw)
  To: OCaml

It crashed again....
First, I'm allocating memory ( I think it's the good way to do it ) :
------------

 value *windata = malloc(sizeof(value));

 messageid = alloc(1,MSGID_TAG);
 Store_field(messageid,1,Val_int(0));

 handletag = alloc(1,HANDLE_TAG);
 Store_field(handletag,1,Val_int(0));

 message = alloc(5,MESSAGE_TAG);
 Store_field(message,0,handletag);
 Store_field(message,1,messageid);
 Store_field(message,2,Val_int(0)); // wParam
 Store_field(message,3,Val_int(0)); // lParam
 Store_field(message,4,Val_int(0)); // MSG*

 *windata = alloc(4,WINDOW_TAG);
 register_global_root(windata);
 Store_field(*windata,0,Val_unit);
 Store_field(*windata,1,callback);
 Store_field(*windata,2,message);
 Store_field(*windata,3,Val_int(func)); // default proc

---------
Then, creating the window, and linking custom data and handle

HWND handle = CreateWindow( .... )
// store handle into data
Store_field(*windata,0,Val_int(handle));
// store data into handle
SetWindowLong(handle,GWL_USERDATA,(long)windata);

--------
And my windowProc :
having parameters  ( hwnd, uMsg, wParam, lParam )

 windata = (value*)GetWindowLong(hwnd,GWL_USERDATA);
 callback = Field(*windata,1);

// update message fields
 message = Field(*windata,2);
 Store_field(Field(message,0),0,Val_int(hwnd));
 Store_field(Field(message,1),0,Val_int(uMsg));
 Store_field(message,2,Val_int(wParam));
 Store_field(message,3,Val_int(lParam));

// caml callback
 result = Int_val(callbackN_exn(callback,1,&message));
 return result;

---------
I got a crash in callbackN_exn / interprete / minor_collection /
empty_minor_head / oldify_local_root / .... (4 oldify calls) / *p = v
 minor_gc.c:122)

I can see that message is being collected, but I don't know why because
*windata contains it so....
I've tryed both with/without CAML* garbage macros, it doesn't work

Thanks for any help / clue.

Warp

-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


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

* Re: [Caml-list] Garbage Again
  2001-12-28 15:22 [Caml-list] Garbage Again Warp
@ 2002-01-03 14:35 ` Xavier Leroy
  2002-01-03 15:42   ` warplayer
  0 siblings, 1 reply; 3+ messages in thread
From: Xavier Leroy @ 2002-01-03 14:35 UTC (permalink / raw)
  To: Warp; +Cc: OCaml

> It crashed again....

Too bad.  Are you really expecting the 500+ subscribers of this list
to debug your code?  Hint: there are at least two fencepost (off-by-one)
problems in the code snippet you posted.

- Xavier Leroy
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


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

* Re: [Caml-list] Garbage Again
  2002-01-03 14:35 ` Xavier Leroy
@ 2002-01-03 15:42   ` warplayer
  0 siblings, 0 replies; 3+ messages in thread
From: warplayer @ 2002-01-03 15:42 UTC (permalink / raw)
  To: Xavier Leroy; +Cc: OCaml

> > It crashed again....
> 
> Too bad.  Are you really expecting the 500+ subscribers of this list
> to debug your code?  Hint: there are at least two fencepost
> (off-by-one) problems in the code snippet you posted.

Okay.
But it's not like I was newbie asking for help each time it comes. In fact, I
have read many many times the full Interfacing C with OCaml documentation pages
to try to figure out what's going wrong. And spend many many ( too much ) hours
debugging. But sometimes you have to say "stop", because YES I'm having trouble
with GC and YES I'm looking for debug help on the list. Am I that stupid ?

I think that kind of GC problems can't be resolved without a solid knowledge of
the GC, especially when the existing support for interfacing with C is only few
doc pages, sometimes foggy (especially concerning globals and how to store value
from ocaml in C).

If one day I manage to understand all theses concepts, perhaps then writing a
full tutorial explaining all C/OCaml interfacing cases will be a good thing for
the OCaml community, and then this list will perhaps have more than 500
subsribers, don't you think ?

About theses fenceposts, I would be glad to have your holy flame lighning my
dark way.

Warp
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


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

end of thread, other threads:[~2002-01-03 15:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-12-28 15:22 [Caml-list] Garbage Again Warp
2002-01-03 14:35 ` Xavier Leroy
2002-01-03 15:42   ` warplayer

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