caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Raj <rajb@rice.edu>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Disabling the OCaml garbage collector
Date: Wed, 28 Nov 2007 12:05:43 -0600	[thread overview]
Message-ID: <474DADF7.5020204@rice.edu> (raw)
In-Reply-To: <474C48C5.708@starynkevitch.net>

The issue for me is that I need to be able to modify mutable objects in 
OCaml (eg. array-modification in-place) from both OCaml and C/Python. 
However, the OCaml GC moves things around while the execution is in 
C/Python and this crashes my program.

The Python GC is very simple, based on reference counts, hence (I think) 
it suffices just to make sure that any object has a refcount > 0 to keep 
the Python GC off.

Well, I decided to go ahead and hack some C code to build a custom OCaml 
compiler. These are the steps I followed:

1) Add the following declarations to stdlib/gc.ml and stdlib/gc.mli

external disable: unit -> unit = "caml_gc_disable"
external enable: unit -> unit = "caml_gc_enable"

2) Modify byterun/gc_ctrl.c and implement the C functions. For example,

int gc_enabled = 1; //global variable

CAMLprim value caml_gc_enable(){
        CAMLparam0();
        gc_enabled = 1;
        CAMLreturn(Val_unit);
}

3) Modify the "main loop" in gc_ctrl.c as

CAMLprim value caml_gc_compaction(value v)
{
if(gc_enabled) {
  Assert (v == Val_unit);
  caml_empty_minor_heap ();
  caml_finish_major_cycle ();
  caml_finish_major_cycle ();
  caml_compact_heap ();
  caml_final_do_calls ();
}
  return Val_unit;
}


However, when I compile this code with 'make world' I get the following 
error while linking:

boot/ocamlrun boot/ocamlc -nostdlib -I boot  -linkall -o ocaml.tmp 
toplevel/toplevellib.cma toplevel/topstart.cmo
Error while linking boot/stdlib.cma(Gc):
The external function `caml_gc_enable' is not available
make: *** [ocaml] Error 2


Any ideas what I am missing?

Thanks!
Raj




>
> You definitely may need to hack the C code inside byterun/minor_gc.c 
> (for example), but I don't understand what you want exactly.
>
> However, I do know that mixing GCs, like Ocaml & Python, is a nightmare.
> Did you consider having two separate Unix processes, one for the Ocaml 
> code and one for the Python code, and having them communicate thru 
> standard stuff like pipes, memory mapped files, ...
>
>


  reply	other threads:[~2007-11-28 18:05 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-27 16:28 Raj Bandyopadhyay
2007-11-27 16:41 ` [Caml-list] " Basile STARYNKEVITCH
2007-11-28 18:05   ` Raj [this message]
2007-11-28 18:15     ` Alain Frisch
2007-11-28 18:31       ` Thomas Fischbacher
2007-11-28 19:30         ` Raj
2007-11-28 18:25     ` Thomas Fischbacher
2007-11-28 18:32     ` Xavier Leroy
2007-11-28 19:33       ` Raj
2007-11-28 20:00         ` Thomas Fischbacher
2007-12-04 20:14           ` Raj Bandyopadhyay
2007-12-05  4:07             ` Jon Harrop
2007-11-29  8:54     ` Frédéric van der Plancke
2007-11-27 17:05 ` [Caml-list] Python and Caml (was: Disabling the OCaml garbage collector) Thomas Fischbacher
2011-08-04 13:10   ` [Caml-list] Python and Caml Stéphane Glondu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=474DADF7.5020204@rice.edu \
    --to=rajb@rice.edu \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).